DebugView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Farseer Physics Engine based on Box2D.XNA port:
  3. * Copyright (c) 2010 Ian Qvist
  4. *
  5. * Box2D.XNA port of Box2D:
  6. * Copyright (c) 2009 Brandon Furtwangler, Nathan Furtwangler
  7. *
  8. * Original source Box2D:
  9. * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
  10. *
  11. * This software is provided 'as-is', without any express or implied
  12. * warranty. In no event will the authors be held liable for any damages
  13. * arising from the use of this software.
  14. * Permission is granted to anyone to use this software for any purpose,
  15. * including commercial applications, and to alter it and redistribute it
  16. * freely, subject to the following restrictions:
  17. * 1. The origin of this software must not be misrepresented; you must not
  18. * claim that you wrote the original software. If you use this software
  19. * in a product, an acknowledgment in the product documentation would be
  20. * appreciated but is not required.
  21. * 2. Altered source versions must be plainly marked as such, and must not be
  22. * misrepresented as being the original software.
  23. * 3. This notice may not be removed or altered from any source distribution.
  24. */
  25. using System;
  26. using FarseerPhysics.Common;
  27. using FarseerPhysics.Dynamics;
  28. using Microsoft.Xna.Framework;
  29. namespace FarseerPhysics
  30. {
  31. [Flags]
  32. public enum DebugViewFlags
  33. {
  34. /// <summary>
  35. /// Draw shapes.
  36. /// </summary>
  37. Shape = (1 << 0),
  38. /// <summary>
  39. /// Draw joint connections.
  40. /// </summary>
  41. Joint = (1 << 1),
  42. /// <summary>
  43. /// Draw axis aligned bounding boxes.
  44. /// </summary>
  45. AABB = (1 << 2),
  46. /// <summary>
  47. /// Draw broad-phase pairs.
  48. /// </summary>
  49. Pair = (1 << 3),
  50. /// <summary>
  51. /// Draw center of mass frame.
  52. /// </summary>
  53. CenterOfMass = (1 << 4),
  54. /// <summary>
  55. /// Draw useful debug data such as timings and number of bodies, joints, contacts and more.
  56. /// </summary>
  57. DebugPanel = (1 << 5),
  58. /// <summary>
  59. /// Draw contact points between colliding bodies.
  60. /// </summary>
  61. ContactPoints = (1 << 6),
  62. /// <summary>
  63. /// Draw contact normals. Need ContactPoints to be enabled first.
  64. /// </summary>
  65. ContactNormals = (1 << 7),
  66. /// <summary>
  67. /// Draws the vertices of polygons.
  68. /// </summary>
  69. PolygonPoints = (1 << 8),
  70. /// <summary>
  71. /// Draws the performance graph.
  72. /// </summary>
  73. PerformanceGraph = (1 << 9),
  74. /// <summary>
  75. /// Draws controllers.
  76. /// </summary>
  77. Controllers = (1 << 10)
  78. }
  79. /// Implement and register this class with a World to provide debug drawing of physics
  80. /// entities in your game.
  81. public abstract class DebugView
  82. {
  83. protected DebugView(World world)
  84. {
  85. World = world;
  86. }
  87. protected World World { get; private set; }
  88. /// <summary>
  89. /// Gets or sets the debug view flags.
  90. /// </summary>
  91. /// <value>The flags.</value>
  92. public DebugViewFlags Flags { get; set; }
  93. /// <summary>
  94. /// Append flags to the current flags.
  95. /// </summary>
  96. /// <param name="flags">The flags.</param>
  97. public void AppendFlags(DebugViewFlags flags)
  98. {
  99. Flags |= flags;
  100. }
  101. /// <summary>
  102. /// Remove flags from the current flags.
  103. /// </summary>
  104. /// <param name="flags">The flags.</param>
  105. public void RemoveFlags(DebugViewFlags flags)
  106. {
  107. Flags &= ~flags;
  108. }
  109. /// <summary>
  110. /// Draw a closed polygon provided in CCW order.
  111. /// </summary>
  112. /// <param name="vertices">The vertices.</param>
  113. /// <param name="count">The vertex count.</param>
  114. /// <param name="red">The red value.</param>
  115. /// <param name="blue">The blue value.</param>
  116. /// <param name="green">The green value.</param>
  117. public abstract void DrawPolygon(Vector2[] vertices, int count, float red, float blue, float green);
  118. /// <summary>
  119. /// Draw a solid closed polygon provided in CCW order.
  120. /// </summary>
  121. /// <param name="vertices">The vertices.</param>
  122. /// <param name="count">The vertex count.</param>
  123. /// <param name="red">The red value.</param>
  124. /// <param name="blue">The blue value.</param>
  125. /// <param name="green">The green value.</param>
  126. public abstract void DrawSolidPolygon(Vector2[] vertices, int count, float red, float blue, float green);
  127. /// <summary>
  128. /// Draw a circle.
  129. /// </summary>
  130. /// <param name="center">The center.</param>
  131. /// <param name="radius">The radius.</param>
  132. /// <param name="red">The red value.</param>
  133. /// <param name="blue">The blue value.</param>
  134. /// <param name="green">The green value.</param>
  135. public abstract void DrawCircle(Vector2 center, float radius, float red, float blue, float green);
  136. /// <summary>
  137. /// Draw a solid circle.
  138. /// </summary>
  139. /// <param name="center">The center.</param>
  140. /// <param name="radius">The radius.</param>
  141. /// <param name="axis">The axis.</param>
  142. /// <param name="red">The red value.</param>
  143. /// <param name="blue">The blue value.</param>
  144. /// <param name="green">The green value.</param>
  145. public abstract void DrawSolidCircle(Vector2 center, float radius, Vector2 axis, float red, float blue,
  146. float green);
  147. /// <summary>
  148. /// Draw a line segment.
  149. /// </summary>
  150. /// <param name="start">The start.</param>
  151. /// <param name="end">The end.</param>
  152. /// <param name="red">The red value.</param>
  153. /// <param name="blue">The blue value.</param>
  154. /// <param name="green">The green value.</param>
  155. public abstract void DrawSegment(Vector2 start, Vector2 end, float red, float blue, float green);
  156. /// <summary>
  157. /// Draw a transform. Choose your own length scale.
  158. /// </summary>
  159. /// <param name="transform">The transform.</param>
  160. public abstract void DrawTransform(ref Transform transform);
  161. }
  162. }