Bullet physics debugdraw is scene node required?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
nullReference
Posts: 17
Joined: Mon Jan 08, 2018 2:45 pm

Bullet physics debugdraw is scene node required?

Post by nullReference »

I am working on adding functionality to display bullet debug lines and so far everything makes since from what I have read. However when it comes to actually drawing the lines I am a little confused as to whether or not a custom scene node will be required. I have been looking at this previous thread on the forms (last post), as well as this article. In the forum post the user displays the following code:

Code: Select all

 
static void BulletToIrr(const btVector3& in, vector3df& result)
{
    result.set(in.getX(),in.getY(),-in.getZ());
}
 
class BulletDebugDraw : public btIDebugDraw
{
    public:
    //
    // debug functionality
    //
    void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
    {
        vector3df v1,v2;
        BulletToIrr(from,v1);
        BulletToIrr(to,v2);
 
        // handle bullet simplex debug color bug...
        SColor icolor((u32)color.x()*255.0, (u32)color.y()*255.0, (u32)color.z()*255.0);
        S3DVertex vert1(v1,v1,icolor,vector2df());
        S3DVertex vert2(v2,v2,icolor,vector2df());
        m_debugNode->addLine(vert1,vert2);
    }
    void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,float distance,int lifeTime,const btVector3& color)
    {
    }
    void draw3dText(const btVector3& location,const char* textString)
    {
    }
}
 
The user is using a custom scene node to add all of the lines output by bullet to the scene. At first this made sense to me until I started thinking, shouldn't a scene node be responsible for a single scene element? From what I can tell if this were to be implemented in this fashion `m_debugNode` would be responsible for drawing all lines for all collision objects in the scene. Is that OK (I could be over thinking this)?

The second example I located shows the following example code:

Code: Select all

 
void BulletDebugRender::drawLine( const btVector3& from,const btVector3& to, const btVector3& color )
{
    drawLine(from, to, color, color);
}
 
void BulletDebugRender::drawLine( const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor )
{
    SColorf fromC;  fromC.set(fromColor[0],fromColor[1],fromColor[2],fromColor[3]);
    SColorf toC;    toC.set(toColor[0],toColor[1],toColor[2],toColor[3]);
 
    Graphics->drawLine(from, to, fromC, toC);
}
 
// Implementation of Graphics::drawLine
void Graphics::drawLine( const vector3df &from, const vector3df &to, const SColorf &fromColor, const SColorf &tocolor )
{
    matrix4 id;
    id.makeIdentity();
    m_Driver->setTransform(video::ETS_WORLD, id);
    m_Driver->draw3DLine(from, to, fromColor.toSColor());
}
 
From what I can tell, this is simply calling `irr::video::IVideoDriver::draw3DLine()` and creating a 3Dline for each line of every collision object without using a scene node? Is that correct?

If I am correct in my assumptions and both examples are working as I have explained, which method should be preferred to draw the lines to the screen?
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bullet physics debugdraw is scene node required?

Post by CuteAlien »

You do not need scenenodes to draw lines. It makes sometimes sense to use the draw function if you already have a custom scene-node as you generally set the correct transformations in there.

But also makes often sense to draw lines somewhere else (between beginScene() and endScene()). You have a little less control over draw-order that way (as you can't draw in between different scene-nodes).
But for debug-lines you generally just draw them last. I often have for debugging some more or less global array (static hidden inside some class using static functions, but just a global would work as well) which can be filled with lines from anywhere - and then I draw that array (in DEBUG only) before endScene. And then clear it again.

Anyway - it's kinda up to you. Just be sure to call driver->setTransform and usually also driver->setMaterial before you start drawing your lines.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply