Bullet physics debugdraw is scene node required?
Posted: Thu Apr 12, 2018 4:18 pm
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:
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:
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?
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 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());
}
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?