PhysicsDebugNode.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include <AnKi/Scene/PhysicsDebugNode.h>
  6. #include <AnKi/Scene/Components/RenderComponent.h>
  7. #include <AnKi/Scene/Components/SpatialComponent.h>
  8. #include <AnKi/Scene/SceneGraph.h>
  9. #include <AnKi/Resource/ResourceManager.h>
  10. namespace anki {
  11. PhysicsDebugNode::PhysicsDebugNode(SceneGraph* scene, CString name)
  12. : SceneNode(scene, name)
  13. , m_physDbgDrawer(&scene->getDebugDrawer())
  14. {
  15. RenderComponent* rcomp = newComponent<RenderComponent>();
  16. rcomp->setFlags(RenderComponentFlag::NONE);
  17. rcomp->initRaster(
  18. [](RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData) {
  19. static_cast<PhysicsDebugNode*>(userData[0])->draw(ctx);
  20. },
  21. this, 0);
  22. SpatialComponent* scomp = newComponent<SpatialComponent>();
  23. scomp->setUpdateOctreeBounds(false); // Don't mess with the bounds
  24. scomp->setAabbWorldSpace(Aabb(getSceneGraph().getSceneMin(), getSceneGraph().getSceneMax()));
  25. scomp->setSpatialOrigin(Vec3(0.0f));
  26. }
  27. PhysicsDebugNode::~PhysicsDebugNode()
  28. {
  29. }
  30. void PhysicsDebugNode::draw(RenderQueueDrawContext& ctx)
  31. {
  32. if(ctx.m_debugDraw)
  33. {
  34. m_physDbgDrawer.start(ctx.m_viewProjectionMatrix, ctx.m_commandBuffer, ctx.m_stagingGpuAllocator);
  35. m_physDbgDrawer.drawWorld(getSceneGraph().getPhysicsWorld());
  36. m_physDbgDrawer.end();
  37. }
  38. }
  39. } // end namespace anki