PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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