PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/PhysicsEngines/Farseer/FarseerDatatypesMapping.cs

#
C# | 101 lines | 49 code | 8 blank | 44 comment | 1 complexity | 796501dff5ec319be25d4835b72841ec MD5 | raw file
  1using System.Collections.Generic;
  2using Delta.Utilities.Datatypes;
  3using FarseerPhysics.Common;
  4using Microsoft.Xna.Framework;
  5	// Please read the note in summary, these are not really XNA Framework types.
  6
  7namespace Delta.PhysicsEngines.Farseer
  8{
  9	/// <summary>
 10	/// Class that managed mapping from-to Delta engine data types to farseer and
 11	/// vice versa.
 12	/// </summary>
 13	/// <remarks>
 14	/// Note: Farseer uses internally Microsoft.Xna.Vector2 inside but this does
 15	/// not mean that it self references XNA. They ported the XNA version inside
 16	/// Farseer.
 17	/// </remarks>
 18	internal static class FarseerDatatypesMapping
 19	{
 20		#region Convert (Static)
 21		/// <summary>
 22		/// Convert Delta Engine Vector to Farseer Vector2.
 23		/// </summary>
 24		/// <param name="vector">The vector.</param>
 25		/// <returns>Farseer Vector2 created from Delta Engine Point.</returns>
 26		public static Vector2 Convert(ref Vector vector)
 27		{
 28			return new Vector2(vector.X, vector.Y);
 29		}
 30
 31		/// <summary>
 32		/// Convert Delta Engine Point to Farseer Vector2.
 33		/// </summary>
 34		/// <param name="point">The point.</param>
 35		/// <returns>Farseer Vector2 created from Delta Engine Point.</returns>
 36		public static Vector2 Convert(ref Point point)
 37		{
 38			return new Vector2(point.X, point.Y);
 39		}
 40
 41		/// <summary>
 42		/// Convert Farseer Vector2 to Delta engine vector.
 43		/// </summary>
 44		/// <param name="vector">The vector.</param>
 45		/// <param name="result">The converted Farseer vector.</param>
 46		public static void Convert(Vector2 vector, out Vector result)
 47		{
 48			result.X = vector.X;
 49			result.Y = vector.Y;
 50			result.Z = 0f;
 51		}
 52
 53		/// <summary>
 54		/// Convert Farseer Vector2 to Delta engine Point.
 55		/// </summary>
 56		/// <param name="vector">The vector.</param>
 57		/// <param name="result">The converted Farseer vector.</param>
 58		public static void Convert(ref Vector2 vector, out Point result)
 59		{
 60			result.X = vector.X;
 61			result.Y = vector.Y;
 62		}
 63
 64		/// <summary>
 65		/// Converts a list of DeltaEngine Point's to Farseer list of Point's.
 66		/// </summary>
 67		/// <param name="list">The list.</param>
 68		/// <returns>
 69		/// Farseer List of Vector2 created from Delta Engine list of points.
 70		/// </returns>
 71		public static IList<Vector2> Convert(IList<Point> list)
 72		{
 73			List<Vector2> result = new List<Vector2>();
 74			for (int index = 0; index < list.Count; index++)
 75			{
 76				result.Add(new Vector2(list[index].X, list[index].Y));
 77			}
 78
 79			return result;
 80		}
 81
 82		/// <summary>
 83		/// Convers a list of list Point to Farseer Vertices.
 84		/// </summary>
 85		/// <param name="arrayVert">The array vert.</param>
 86		/// <returns>
 87		/// Farseer Vertices created from Delta Engine list of points.
 88		/// </returns>
 89		public static List<Vertices> Convert(List<IList<Point>> arrayVert)
 90		{
 91			List<Vertices> vertices = new List<Vertices>();
 92			foreach (IList<Point> points in arrayVert)
 93			{
 94				vertices.Add(new Vertices(Convert(points)));
 95			}
 96
 97			return vertices;
 98		}
 99		#endregion
100	}
101}