PageRenderTime 183ms CodeModel.GetById 100ms app.highlight 6ms RepoModel.GetById 75ms app.codeStats 0ms

/PhysicsEngines/JigLib/JigLibDatatypesMapping.cs

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