PhysicsDrawer.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Physics/Common.h>
  7. namespace anki {
  8. /// @addtogroup physics
  9. /// @{
  10. /// Physics debug drawer interface.
  11. class PhysicsDrawer
  12. {
  13. public:
  14. PhysicsDrawer()
  15. : m_debugDraw(this)
  16. {
  17. }
  18. /// Draw a line.
  19. virtual void drawLines(const Vec3* lines, const U32 vertCount, const Vec4& color) = 0;
  20. void drawWorld(const PhysicsWorld& world);
  21. private:
  22. class DebugDraw : public btIDebugDraw
  23. {
  24. public:
  25. PhysicsDrawer* m_drawer = nullptr;
  26. DebugDraw(PhysicsDrawer* drawer)
  27. : m_drawer(drawer)
  28. {
  29. }
  30. void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override
  31. {
  32. Array<Vec3, 2> lines = {toAnki(from), toAnki(to)};
  33. m_drawer->drawLines(&lines[0], 2, Vec4(toAnki(color), 1.0f));
  34. }
  35. void drawContactPoint([[maybe_unused]] const btVector3& PointOnB, [[maybe_unused]] const btVector3& normalOnB,
  36. [[maybe_unused]] btScalar distance, [[maybe_unused]] int lifeTime, [[maybe_unused]] const btVector3& color) override
  37. {
  38. // TODO
  39. }
  40. void reportErrorWarning(const char* warningString) override
  41. {
  42. ANKI_PHYS_LOGW("%s", warningString);
  43. }
  44. void draw3dText([[maybe_unused]] const btVector3& location, [[maybe_unused]] const char* textString) override
  45. {
  46. // TODO
  47. }
  48. void setDebugMode([[maybe_unused]] int debugMode) override
  49. {
  50. // TODO
  51. }
  52. int getDebugMode() const override
  53. {
  54. return btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb;
  55. }
  56. };
  57. DebugDraw m_debugDraw;
  58. };
  59. /// @}
  60. } // end namespace anki