b2_draw.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // MIT License
  2. // Copyright (c) 2019 Erin Catto
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. #ifndef B2_DRAW_H
  19. #define B2_DRAW_H
  20. #include "b2_api.h"
  21. #include "b2_math.h"
  22. /// Color for debug drawing. Each value has the range [0,1].
  23. struct B2_API b2Color
  24. {
  25. b2Color() {}
  26. b2Color(float rIn, float gIn, float bIn, float aIn = 1.0f)
  27. {
  28. r = rIn; g = gIn; b = bIn; a = aIn;
  29. }
  30. void Set(float rIn, float gIn, float bIn, float aIn = 1.0f)
  31. {
  32. r = rIn; g = gIn; b = bIn; a = aIn;
  33. }
  34. float r, g, b, a;
  35. };
  36. /// Implement and register this class with a b2World to provide debug drawing of physics
  37. /// entities in your game.
  38. class B2_API b2Draw
  39. {
  40. public:
  41. b2Draw();
  42. virtual ~b2Draw() {}
  43. enum
  44. {
  45. e_shapeBit = 0x0001, ///< draw shapes
  46. e_jointBit = 0x0002, ///< draw joint connections
  47. e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
  48. e_pairBit = 0x0008, ///< draw broad-phase pairs
  49. e_centerOfMassBit = 0x0010 ///< draw center of mass frame
  50. };
  51. /// Set the drawing flags.
  52. void SetFlags(uint32 flags);
  53. /// Get the drawing flags.
  54. uint32 GetFlags() const;
  55. /// Append flags to the current flags.
  56. void AppendFlags(uint32 flags);
  57. /// Clear flags from the current flags.
  58. void ClearFlags(uint32 flags);
  59. /// Draw a closed polygon provided in CCW order.
  60. virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
  61. /// Draw a solid closed polygon provided in CCW order.
  62. virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;
  63. /// Draw a circle.
  64. virtual void DrawCircle(const b2Vec2& center, float radius, const b2Color& color) = 0;
  65. /// Draw a solid circle.
  66. virtual void DrawSolidCircle(const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color) = 0;
  67. /// Draw a line segment.
  68. virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;
  69. /// Draw a transform. Choose your own length scale.
  70. /// @param xf a transform.
  71. virtual void DrawTransform(const b2Transform& xf) = 0;
  72. /// Draw a point.
  73. virtual void DrawPoint(const b2Vec2& p, float size, const b2Color& color) = 0;
  74. protected:
  75. uint32 m_drawFlags;
  76. };
  77. #endif