Batch physics debug rendering

This commit is contained in:
Marianne Gagnon 2014-05-10 19:26:14 -04:00
parent 46a832a67f
commit 486d5c291f
6 changed files with 58 additions and 1 deletions

@ -1952,6 +1952,16 @@ void IrrDriver::update(float dt)
else
renderFixed(dt);
if (world != NULL && world->getPhysics() != NULL)
{
IrrDebugDrawer* debug_drawer = world->getPhysics()->getDebugDrawer();
if (debug_drawer != NULL && debug_drawer->debugEnabled())
{
debug_drawer->beginNextFrame();
}
}
if (m_request_screenshot) doScreenShot();
// Enable this next print statement to get render information printed

@ -197,6 +197,24 @@ void IrrDriver::renderGLSL(float dt)
drawDebugMeshes();
#endif
if (world != NULL && world->getPhysics() != NULL)
{
IrrDebugDrawer* debug_drawer = world->getPhysics()->getDebugDrawer();
if (debug_drawer != NULL && debug_drawer->debugEnabled())
{
const std::map<video::SColor, std::vector<btVector3>>& lines = debug_drawer->getLines();
std::map<video::SColor, std::vector<btVector3>>::const_iterator it;
for (it = lines.begin(); it != lines.end(); it++)
{
for (int i = 0; i < it->second.size(); i += 2)
{
draw3DLine((const core::vector3df&)it->second[0], (const core::vector3df&)it->second[1], it->first);
}
}
}
}
PROFILER_PUSH_CPU_MARKER("EndSccene", 0x45, 0x75, 0x45);
m_video_driver->endScene();
PROFILER_POP_CPU_MARKER();

@ -621,8 +621,14 @@ void World::resetAllKarts()
// Stil wait will all karts are in rest (and handle the case that a kart
// fell through the ground, which can happen if a kart falls for a long
// time, therefore having a high speed when hitting the ground.
int count = 0;
while(!all_finished)
{
if (count++ > 100)
{
Log::error("World", "Infitine loop waiting for all_finished?");
break;
}
m_physics->update(1.f/60.f);
all_finished=true;
for ( KartList::iterator i=m_karts.begin(); i!=m_karts.end(); i++)

@ -58,7 +58,21 @@ void IrrDebugDrawer::drawLine(const btVector3& from, const btVector3& to,
{
video::SColor c(255, (int)(color.getX()*255), (int)(color.getY()*255),
(int)(color.getZ()*255) );
draw3DLine((const core::vector3df&)from, (const core::vector3df&)to, c);
m_lines[c].push_back(from);
m_lines[c].push_back(to);
//draw3DLine((const core::vector3df&)from, (const core::vector3df&)to, c);
}
// -----------------------------------------------------------------------------
void IrrDebugDrawer::beginNextFrame()
{
for (std::map<video::SColor, std::vector<btVector3>>::iterator it = m_lines.begin(); it != m_lines.end(); it++)
{
it->second.clear();
}
}
/* EOF */

@ -23,6 +23,8 @@
#include "graphics/glwrap.hpp"
#include "utils/vec3.hpp"
#include <map>
#include <vector>
/**
* \ingroup physics
@ -39,6 +41,9 @@ public:
DM_NO_KARTS_GRAPHICS = 0x02
};
DebugModeType m_debug_mode;
std::map<video::SColor, std::vector<btVector3>> m_lines;
protected:
virtual void setDebugMode(int debug_mode) {}
/** Callback for bullet: if debug drawing should be done or not.
@ -66,6 +71,9 @@ public:
bool debugEnabled() const {return m_debug_mode!=0;}
void nextDebugMode();
void setDebugMode(DebugModeType mode);
void beginNextFrame();
const std::map<video::SColor, std::vector<btVector3>>& getLines() const { return m_lines; }
}; // IrrDebugDrawer
#endif

@ -165,6 +165,7 @@ public:
void setDebugMode(IrrDebugDrawer::DebugModeType mode) { m_debug_drawer->setDebugMode(mode); }
/** Returns true if the debug drawer is enabled. */
bool isDebug() const {return m_debug_drawer->debugEnabled(); }
IrrDebugDrawer* getDebugDrawer() { return m_debug_drawer; }
virtual btScalar solveGroup(btCollisionObject** bodies, int numBodies,
btPersistentManifold** manifold,int numManifolds,
btTypedConstraint** constraints,int numConstraints,