PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/PhysicsEngines/Bullet/BulletDatatypesMapping.cs

#
C# | 111 lines | 72 code | 5 blank | 34 comment | 0 complexity | 03c1c647fba58d76f90f35c01509f1b6 MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Utilities.Datatypes;
  2. using BulletVector3 = Microsoft.Xna.Framework.Vector3;
  3. using BulletMatrix = Microsoft.Xna.Framework.Matrix;
  4. namespace Delta.PhysicsEngines.Bullet
  5. {
  6. /// <summary>
  7. /// Implements mapping between Bullet data types and Delta engine data types.
  8. /// </summary>
  9. internal class BulletDatatypesMapping
  10. {
  11. #region Convert (Static)
  12. /// <summary>
  13. /// Perform conversion between BulletXNA Matrix and DeltaEngine Matrix.
  14. /// </summary>
  15. /// <param name="matrix">The BulletXNA matrix.</param>
  16. /// <param name="result">The result DeltaEngine matrix.</param>
  17. public static void Convert(ref BulletMatrix matrix, out Matrix result)
  18. {
  19. result = new Matrix(
  20. matrix.M11,
  21. matrix.M12,
  22. matrix.M13,
  23. 0.0f,
  24. matrix.M21,
  25. matrix.M22,
  26. matrix.M23,
  27. 0.0f,
  28. matrix.M31,
  29. matrix.M32,
  30. matrix.M33,
  31. 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
  32. }
  33. /// <summary>
  34. /// Perform conversion between DeltaEngine Matrix and BulletXNA Matrix.
  35. /// </summary>
  36. /// <param name="matrix">The DeltaEngine matrix.</param>
  37. /// <param name="result">The result BulletXNA matrix.</param>
  38. public static void Convert(ref Matrix matrix, out BulletMatrix result)
  39. {
  40. result.M11 = matrix.M11;
  41. result.M12 = matrix.M12;
  42. result.M13 = matrix.M13;
  43. result.M14 = 0.0f;
  44. result.M21 = matrix.M21;
  45. result.M22 = matrix.M22;
  46. result.M23 = matrix.M23;
  47. result.M24 = 0.0f;
  48. result.M31 = matrix.M31;
  49. result.M32 = matrix.M32;
  50. result.M33 = matrix.M33;
  51. result.M34 = 0.0f;
  52. result.M41 = 0.0f;
  53. result.M42 = 0.0f;
  54. result.M43 = 0.0f;
  55. result.M44 = 0.0f;
  56. }
  57. /// <summary>
  58. /// Convert DeltaEngine vector to Jitter vector.
  59. /// </summary>
  60. /// <param name="vector">DeltaEngine vector.</param>
  61. /// <returns>
  62. /// The converted BulletXNA vector.
  63. /// </returns>
  64. public static BulletVector3 Convert(Vector vector)
  65. {
  66. return new BulletVector3(vector.X, vector.Y, vector.Z);
  67. }
  68. /// <summary>
  69. /// Convert BulletXNA vector to DeltaEngine vector.
  70. /// </summary>
  71. /// <param name="vector">BulletXNA vector.</param>
  72. /// <returns>
  73. /// The converted DeltaEngine vector.
  74. /// </returns>
  75. public static Vector Convert(BulletVector3 vector)
  76. {
  77. return new Vector(vector.X, vector.Y, vector.Z);
  78. }
  79. #endregion
  80. #region ConvertSlow (Static)
  81. /// <summary>
  82. /// Slow version of the BulletMatrix to Delta Matrix conversion. Used
  83. /// when properties are involved (we cannot pass them as ref and would
  84. /// need local copies anyway) and performance is not super critical.
  85. /// </summary>
  86. /// <param name="inputValue">The input value.</param>
  87. /// <returns></returns>
  88. public static Matrix ConvertSlow(BulletMatrix inputValue)
  89. {
  90. return new Matrix(
  91. inputValue.M11,
  92. inputValue.M12,
  93. inputValue.M13,
  94. 0.0f,
  95. inputValue.M21,
  96. inputValue.M22,
  97. inputValue.M23,
  98. 0.0f,
  99. inputValue.M31,
  100. inputValue.M32,
  101. inputValue.M33,
  102. 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
  103. }
  104. #endregion
  105. }
  106. }