b2Draw.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2011 Erin Catto http://box2d.org
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include <Box2D/Common/b2Math.h>
  19. /// Color for debug drawing. Each value has the range [0,1].
  20. struct b2Color
  21. {
  22. b2Color() {}
  23. b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {}
  24. void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; }
  25. float32 r, g, b;
  26. };
  27. /// Implement and register this class with a b2World to provide debug drawing of physics
  28. /// entities in your game.
  29. class b2Draw
  30. {
  31. public:
  32. b2Draw();
  33. virtual ~b2Draw() {}
  34. enum
  35. {
  36. e_shapeBit = 0x0001, ///< draw shapes
  37. e_jointBit = 0x0002, ///< draw joint connections
  38. e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
  39. e_pairBit = 0x0008, ///< draw broad-phase pairs
  40. e_centerOfMassBit = 0x0010 ///< draw center of mass frame
  41. };
  42. /// Set the drawing flags.
  43. void SetFlags(uint32 flags);
  44. /// Get the drawing flags.
  45. uint32 GetFlags() const;
  46. /// Append flags to the current flags.
  47. void AppendFlags(uint32 flags);
  48. /// Clear flags from the current flags.
  49. void ClearFlags(uint32 flags);
  50. /// Draw a closed polygon provided in CCW order.
  51. virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
  52. /// Draw a solid closed polygon provided in CCW order.
  53. virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
  54. /// Draw a circle.
  55. virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0;
  56. /// Draw a solid circle.
  57. virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0;
  58. /// Draw a line segment.
  59. virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;
  60. /// Draw a transform. Choose your own length scale.
  61. /// @param xf a transform.
  62. virtual void DrawTransform(const b2Transform& xf) = 0;
  63. protected:
  64. uint32 m_drawFlags;
  65. };