PhysicsDebugNode.cpp 1.4 KB

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