/PhysicsEngines/Farseer/FarseerDatatypesMapping.cs
C# | 101 lines | 49 code | 8 blank | 44 comment | 1 complexity | 796501dff5ec319be25d4835b72841ec MD5 | raw file
Possible License(s): Apache-2.0
- using System.Collections.Generic;
- using Delta.Utilities.Datatypes;
- using FarseerPhysics.Common;
- using Microsoft.Xna.Framework;
- // Please read the note in summary, these are not really XNA Framework types.
-
- namespace Delta.PhysicsEngines.Farseer
- {
- /// <summary>
- /// Class that managed mapping from-to Delta engine data types to farseer and
- /// vice versa.
- /// </summary>
- /// <remarks>
- /// Note: Farseer uses internally Microsoft.Xna.Vector2 inside but this does
- /// not mean that it self references XNA. They ported the XNA version inside
- /// Farseer.
- /// </remarks>
- internal static class FarseerDatatypesMapping
- {
- #region Convert (Static)
- /// <summary>
- /// Convert Delta Engine Vector to Farseer Vector2.
- /// </summary>
- /// <param name="vector">The vector.</param>
- /// <returns>Farseer Vector2 created from Delta Engine Point.</returns>
- public static Vector2 Convert(ref Vector vector)
- {
- return new Vector2(vector.X, vector.Y);
- }
-
- /// <summary>
- /// Convert Delta Engine Point to Farseer Vector2.
- /// </summary>
- /// <param name="point">The point.</param>
- /// <returns>Farseer Vector2 created from Delta Engine Point.</returns>
- public static Vector2 Convert(ref Point point)
- {
- return new Vector2(point.X, point.Y);
- }
-
- /// <summary>
- /// Convert Farseer Vector2 to Delta engine vector.
- /// </summary>
- /// <param name="vector">The vector.</param>
- /// <param name="result">The converted Farseer vector.</param>
- public static void Convert(Vector2 vector, out Vector result)
- {
- result.X = vector.X;
- result.Y = vector.Y;
- result.Z = 0f;
- }
-
- /// <summary>
- /// Convert Farseer Vector2 to Delta engine Point.
- /// </summary>
- /// <param name="vector">The vector.</param>
- /// <param name="result">The converted Farseer vector.</param>
- public static void Convert(ref Vector2 vector, out Point result)
- {
- result.X = vector.X;
- result.Y = vector.Y;
- }
-
- /// <summary>
- /// Converts a list of DeltaEngine Point's to Farseer list of Point's.
- /// </summary>
- /// <param name="list">The list.</param>
- /// <returns>
- /// Farseer List of Vector2 created from Delta Engine list of points.
- /// </returns>
- public static IList<Vector2> Convert(IList<Point> list)
- {
- List<Vector2> result = new List<Vector2>();
- for (int index = 0; index < list.Count; index++)
- {
- result.Add(new Vector2(list[index].X, list[index].Y));
- }
-
- return result;
- }
-
- /// <summary>
- /// Convers a list of list Point to Farseer Vertices.
- /// </summary>
- /// <param name="arrayVert">The array vert.</param>
- /// <returns>
- /// Farseer Vertices created from Delta Engine list of points.
- /// </returns>
- public static List<Vertices> Convert(List<IList<Point>> arrayVert)
- {
- List<Vertices> vertices = new List<Vertices>();
- foreach (IList<Point> points in arrayVert)
- {
- vertices.Add(new Vertices(Convert(points)));
- }
-
- return vertices;
- }
- #endregion
- }
- }