PageRenderTime 77ms CodeModel.GetById 20ms app.highlight 32ms RepoModel.GetById 18ms app.codeStats 1ms

/PhysicsEngines/Bullet/BulletDatatypesMapping.cs

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