[solved] drawing 2d line

After experiencing some problems with ODE I integrated bullet physics successfully into my app. Now, I would like to integrate the bullet debug feature that draws geometry. To do this you implement an interface with a function to draw a line and pass it to the Bullet engine. I didn’t find a facility to simply draw a line to screen in panda, in 2d space, and I don’t really want to create geometry or textures just for this. Irrlicht has irrVideo->draw2DLine() so I don’t think it’s that far-fetched. Is there something like this? If not, any tip on how to do it cleanly?

EDIT: I’ve found a couple of solutions in the forum but I would like something that doesn’t add stuff to the scenegraph, since bullet is gonna be issuing that call continuously.

EDIT2: Solved, I’ll use drawing callbacks.

Cool. Can you share your code for Bullet debug rendering using drawing callbacks? I am currently using LineSegs for the same purpose, but I don’t like this approach very much (I have to add a GeomNode to the scene graph, performance is low, and I am limited to lines only).

Note that, with drawing callbacks, you’re limited to just OpenGL or DirectX.

Also, I don’t think a callback is likely to be performance improvement over simply adding a GeomNode to the scene graph. A GeomNode is, after all, an instruction to Panda to issue a draw call; and it can draw a dynamically-updated object just as easily as a static object.

Of course, integrating with an existing callback interface that expects an immediate-draw model does present a few problems with Panda’s scene graph model, so that’s some justification in itself for using Panda’s draw callback system. It’s also perfectly doable with the scene graph model, though (you would make the bullet callback simply adjust the geometry in the node according to its data).


Um… didn’t want to hijack this thread…

My current approach is to use the LineSegs class, add lines to it with each callback from Bullet, and when the frame is finished let LineSegs create a GeomNode. Then I remove all currently existing GeomNodes and add the GeomNodes from what LineSegs created:

class BulletDebugDrawer : public GeomNode...

void finish_frame() {
  GeomNode *node = _segs.create();
  delete node;

This is quite easy to code, but probably not the best approach. I think I should consider using a GeomVertexWriter (like I did for cloth/softbody meshes in PhysX).

Right, probably not the best approach, because of the overhead of creating and destroying GeomNodes each frame. You could use a GeomVertexWriter, as you suggest; or the MeshDrawer class, which is designed for this sort of thing.

Or you could simply use the LineSegs.setVertex() call to adjust the position of previously-created vertices.