PhysicsDrawer.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2009-2021, 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. {
  9. /// @addtogroup physics
  10. /// @{
  11. /// Physics debug drawer interface.
  12. class PhysicsDrawer
  13. {
  14. public:
  15. PhysicsDrawer()
  16. : m_debugDraw(this)
  17. {
  18. }
  19. /// Draw a line.
  20. virtual void drawLines(const Vec3* lines, const U32 vertCount, const Vec4& color) = 0;
  21. void drawWorld(const PhysicsWorld& world);
  22. private:
  23. class DebugDraw : public btIDebugDraw
  24. {
  25. public:
  26. PhysicsDrawer* m_drawer = nullptr;
  27. DebugDraw(PhysicsDrawer* drawer)
  28. : m_drawer(drawer)
  29. {
  30. }
  31. void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override
  32. {
  33. Array<Vec3, 2> lines = {toAnki(from), toAnki(to)};
  34. m_drawer->drawLines(&lines[0], 2, Vec4(toAnki(color), 1.0f));
  35. }
  36. void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime,
  37. const btVector3& color) override
  38. {
  39. // TODO
  40. }
  41. void reportErrorWarning(const char* warningString) override
  42. {
  43. ANKI_PHYS_LOGW("%s", warningString);
  44. }
  45. void draw3dText(const btVector3& location, const char* textString) override
  46. {
  47. // TODO
  48. }
  49. void setDebugMode(int debugMode) override
  50. {
  51. // TODO
  52. }
  53. int getDebugMode() const override
  54. {
  55. return btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb;
  56. }
  57. };
  58. DebugDraw m_debugDraw;
  59. };
  60. /// @}
  61. } // end namespace anki