Box2DDebugDraw.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include "Actor.h"
  3. #include "Box2D/Box2D.h"
  4. using namespace oxygine;
  5. namespace oxygine
  6. {
  7. class ShaderProgramGL;
  8. }
  9. DECLARE_SMART(Box2DDraw, spBox2DDraw);
  10. class Box2DDraw: public Actor, public b2Draw
  11. {
  12. public:
  13. Box2DDraw();
  14. ~Box2DDraw();
  15. void setWorld(float worldScale, b2World* world) {_worldScale = worldScale; _world = world;}
  16. /// Draw a closed polygon provided in CCW order.
  17. void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
  18. /// Draw a solid closed polygon provided in CCW order.
  19. void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
  20. /// Draw a circle.
  21. void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color);
  22. /// Draw a solid circle.
  23. void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
  24. /// Draw a line segment.
  25. void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
  26. /// Draw a transform. Choose your own length scale.
  27. /// @param xf a transform.
  28. void DrawTransform(const b2Transform& xf);
  29. protected:
  30. b2World* _world;
  31. float _worldScale;
  32. void doRender(const RenderState& rs);
  33. static const int MAX_VERTICES = 64;
  34. static const int CIRCLE_SEGMENTS = 16;
  35. Vector2 mVertices[MAX_VERTICES];
  36. void createCircleVertices(const b2Vec2& aCenter, float32 aRadius);
  37. void createPolygonVertices(const b2Vec2* aVertices, int32 aVertexCount);
  38. void drawPrimitives(bool drawTriangles, bool drawLines, int aCount, const b2Color& aColor);
  39. ShaderProgramGL* _program;
  40. };