/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
- using Delta.Utilities.Datatypes;
- using BulletVector3 = Microsoft.Xna.Framework.Vector3;
- using BulletMatrix = Microsoft.Xna.Framework.Matrix;
-
- namespace Delta.PhysicsEngines.Bullet
- {
- /// <summary>
- /// Implements mapping between Bullet data types and Delta engine data types.
- /// </summary>
- internal class BulletDatatypesMapping
- {
- #region Convert (Static)
- /// <summary>
- /// Perform conversion between BulletXNA Matrix and DeltaEngine Matrix.
- /// </summary>
- /// <param name="matrix">The BulletXNA matrix.</param>
- /// <param name="result">The result DeltaEngine matrix.</param>
- public static void Convert(ref BulletMatrix matrix, out Matrix result)
- {
- result = new Matrix(
- matrix.M11,
- matrix.M12,
- matrix.M13,
- 0.0f,
- matrix.M21,
- matrix.M22,
- matrix.M23,
- 0.0f,
- matrix.M31,
- matrix.M32,
- matrix.M33,
- 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
- }
-
- /// <summary>
- /// Perform conversion between DeltaEngine Matrix and BulletXNA Matrix.
- /// </summary>
- /// <param name="matrix">The DeltaEngine matrix.</param>
- /// <param name="result">The result BulletXNA matrix.</param>
- public static void Convert(ref Matrix matrix, out BulletMatrix result)
- {
- result.M11 = matrix.M11;
- result.M12 = matrix.M12;
- result.M13 = matrix.M13;
- result.M14 = 0.0f;
- result.M21 = matrix.M21;
- result.M22 = matrix.M22;
- result.M23 = matrix.M23;
- result.M24 = 0.0f;
- result.M31 = matrix.M31;
- result.M32 = matrix.M32;
- result.M33 = matrix.M33;
- result.M34 = 0.0f;
- result.M41 = 0.0f;
- result.M42 = 0.0f;
- result.M43 = 0.0f;
- result.M44 = 0.0f;
- }
-
- /// <summary>
- /// Convert DeltaEngine vector to Jitter vector.
- /// </summary>
- /// <param name="vector">DeltaEngine vector.</param>
- /// <returns>
- /// The converted BulletXNA vector.
- /// </returns>
- public static BulletVector3 Convert(Vector vector)
- {
- return new BulletVector3(vector.X, vector.Y, vector.Z);
- }
-
- /// <summary>
- /// Convert BulletXNA vector to DeltaEngine vector.
- /// </summary>
- /// <param name="vector">BulletXNA vector.</param>
- /// <returns>
- /// The converted DeltaEngine vector.
- /// </returns>
- public static Vector Convert(BulletVector3 vector)
- {
- return new Vector(vector.X, vector.Y, vector.Z);
- }
- #endregion
-
- #region ConvertSlow (Static)
- /// <summary>
- /// Slow version of the BulletMatrix to Delta Matrix conversion. Used
- /// when properties are involved (we cannot pass them as ref and would
- /// need local copies anyway) and performance is not super critical.
- /// </summary>
- /// <param name="inputValue">The input value.</param>
- /// <returns></returns>
- public static Matrix ConvertSlow(BulletMatrix inputValue)
- {
- return new Matrix(
- inputValue.M11,
- inputValue.M12,
- inputValue.M13,
- 0.0f,
- inputValue.M21,
- inputValue.M22,
- inputValue.M23,
- 0.0f,
- inputValue.M31,
- inputValue.M32,
- inputValue.M33,
- 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
- }
- #endregion
- }
- }