b2Draw.h 3.0 KB

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