Display bounding boxes
This commit is contained in:
parent
9c9c4d2fcf
commit
cf18a8ee20
@ -113,7 +113,7 @@ IrrDriver::IrrDriver()
|
||||
m_post_processing = NULL;
|
||||
m_wind = new Wind();
|
||||
m_mipviz = m_wireframe = m_normals = m_ssaoviz = \
|
||||
m_lightviz = m_shadowviz = m_distortviz = m_rsm = m_rh = m_gi = false;
|
||||
m_lightviz = m_shadowviz = m_distortviz = m_rsm = m_rh = m_gi = m_boundingboxesviz = false;
|
||||
SkyboxCubeMap = m_last_light_bucket_distance = 0;
|
||||
m_shadow_camnodes[0] = NULL;
|
||||
m_shadow_camnodes[1] = NULL;
|
||||
|
@ -345,6 +345,7 @@ private:
|
||||
bool m_shadowviz;
|
||||
bool m_lightviz;
|
||||
bool m_distortviz;
|
||||
bool m_boundingboxesviz;
|
||||
/** Performance stats */
|
||||
unsigned m_last_light_bucket_distance;
|
||||
unsigned object_count[PASS_COUNT];
|
||||
@ -623,6 +624,7 @@ public:
|
||||
m_shadowviz = false;
|
||||
m_lightviz = false;
|
||||
m_distortviz = false;
|
||||
m_boundingboxesviz = false;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleWireframe() { m_wireframe = !m_wireframe; }
|
||||
@ -661,6 +663,10 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
bool getDistortViz() { return m_distortviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
void toggleBoundingBoxesViz() { m_boundingboxesviz = !m_boundingboxesviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool getBoundingBoxesViz() { return m_boundingboxesviz; }
|
||||
// ------------------------------------------------------------------------
|
||||
u32 getRenderPass() { return m_renderpass; }
|
||||
// ------------------------------------------------------------------------
|
||||
void addGlowingNode(scene::ISceneNode *n, float r = 1.0f, float g = 1.0f, float b = 1.0f)
|
||||
|
@ -45,8 +45,12 @@
|
||||
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
|
||||
extern std::vector<float> BoundingBoxes;
|
||||
|
||||
void IrrDriver::renderGLSL(float dt)
|
||||
{
|
||||
BoundingBoxes.clear();
|
||||
World *world = World::getWorld(); // Never NULL.
|
||||
|
||||
Track *track = world->getTrack();
|
||||
@ -185,6 +189,23 @@ void IrrDriver::renderGLSL(float dt)
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
renderScene(camnode, plc, glows, dt, track->hasShadows(), false);
|
||||
|
||||
// Render bounding boxes
|
||||
if (irr_driver->getBoundingBoxesViz())
|
||||
{
|
||||
glUseProgram(UtilShader::ColoredLine::Program);
|
||||
glBindVertexArray(UtilShader::ColoredLine::vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, UtilShader::ColoredLine::vbo);
|
||||
UtilShader::ColoredLine::setUniforms(SColor(255, 255, 0, 0));
|
||||
const float *tmp = BoundingBoxes.data();
|
||||
for (unsigned int i = 0; i < BoundingBoxes.size(); i += 1024 * 6)
|
||||
{
|
||||
unsigned count = MIN2((int)BoundingBoxes.size() - i, 1024 * 6);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(float), &tmp[i]);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, count / 3);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug physic
|
||||
// Note that drawAll must be called before rendering
|
||||
// the bullet debug view, since otherwise the camera
|
||||
|
@ -166,6 +166,18 @@ bool isBoxInFrontOfPlane(const core::plane3df &plane, const core::vector3df edge
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<float> BoundingBoxes;
|
||||
|
||||
static void addEdge(const core::vector3df &P0, const core::vector3df &P1)
|
||||
{
|
||||
BoundingBoxes.push_back(P0.X);
|
||||
BoundingBoxes.push_back(P0.Y);
|
||||
BoundingBoxes.push_back(P0.Z);
|
||||
BoundingBoxes.push_back(P1.X);
|
||||
BoundingBoxes.push_back(P1.Y);
|
||||
BoundingBoxes.push_back(P1.Z);
|
||||
}
|
||||
|
||||
static
|
||||
bool isCulledPrecise(const scene::ICameraSceneNode *cam, const scene::ISceneNode *node)
|
||||
{
|
||||
@ -201,6 +213,41 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector<scene::ISceneNode *> *Immed
|
||||
node->updateNoGL();
|
||||
DeferredUpdate.push_back(node);
|
||||
|
||||
|
||||
const core::matrix4 &trans = Node->getAbsoluteTransformation();
|
||||
|
||||
core::vector3df edges[8];
|
||||
Node->getBoundingBox().getEdges(edges);
|
||||
for (unsigned i = 0; i < 8; i++)
|
||||
trans.transformVect(edges[i]);
|
||||
|
||||
/* From irrlicht
|
||||
/3--------/7
|
||||
/ | / |
|
||||
/ | / |
|
||||
1---------5 |
|
||||
| /2- - -|- -6
|
||||
| / | /
|
||||
|/ | /
|
||||
0---------4/
|
||||
*/
|
||||
|
||||
if (irr_driver->getBoundingBoxesViz())
|
||||
{
|
||||
addEdge(edges[0], edges[1]);
|
||||
addEdge(edges[1], edges[5]);
|
||||
addEdge(edges[5], edges[4]);
|
||||
addEdge(edges[4], edges[0]);
|
||||
addEdge(edges[2], edges[3]);
|
||||
addEdge(edges[3], edges[7]);
|
||||
addEdge(edges[7], edges[6]);
|
||||
addEdge(edges[6], edges[2]);
|
||||
addEdge(edges[0], edges[2]);
|
||||
addEdge(edges[1], edges[3]);
|
||||
addEdge(edges[5], edges[7]);
|
||||
addEdge(edges[4], edges[6]);
|
||||
}
|
||||
|
||||
if (node->isImmediateDraw())
|
||||
{
|
||||
ImmediateDraw->push_back(Node);
|
||||
|
@ -67,6 +67,7 @@ enum DebugMenuCommand
|
||||
DEBUG_GRAPHICS_DISTORT_VIZ,
|
||||
DEBUG_GRAPHICS_BULLET_1,
|
||||
DEBUG_GRAPHICS_BULLET_2,
|
||||
DEBUG_GRAPHICS_BOUNDING_BOXES_VIZ,
|
||||
DEBUG_PROFILER,
|
||||
DEBUG_PROFILER_GENERATE_REPORT,
|
||||
DEBUG_FPS,
|
||||
@ -173,6 +174,7 @@ bool onEvent(const SEvent &event)
|
||||
sub->addItem(L"Distort viz", DEBUG_GRAPHICS_DISTORT_VIZ );
|
||||
sub->addItem(L"Physics debug", DEBUG_GRAPHICS_BULLET_1);
|
||||
sub->addItem(L"Physics debug (no kart)", DEBUG_GRAPHICS_BULLET_2);
|
||||
sub->addItem(L"Bounding Boxes viz", DEBUG_GRAPHICS_BOUNDING_BOXES_VIZ);
|
||||
sub->addItem(L"Reset debug views", DEBUG_GRAPHICS_RESET );
|
||||
|
||||
mnu->addItem(L"Items >",-1,true,true);
|
||||
@ -342,6 +344,11 @@ bool onEvent(const SEvent &event)
|
||||
Physics *physics = world->getPhysics();
|
||||
physics->setDebugMode(IrrDebugDrawer::DM_NO_KARTS_GRAPHICS);
|
||||
}
|
||||
else if (cmdID == DEBUG_GRAPHICS_BOUNDING_BOXES_VIZ)
|
||||
{
|
||||
irr_driver->resetDebugModes();
|
||||
irr_driver->toggleBoundingBoxesViz();
|
||||
}
|
||||
else if (cmdID == DEBUG_PROFILER)
|
||||
{
|
||||
UserConfigParams::m_profiler_enabled =
|
||||
|
Loading…
Reference in New Issue
Block a user