2
0

PhysicsDrawer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2009-2022, 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,
  37. [[maybe_unused]] 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([[maybe_unused]] const btVector3& location, [[maybe_unused]] const char* textString) override
  46. {
  47. // TODO
  48. }
  49. void setDebugMode([[maybe_unused]] 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