Drawing a rigid body's path?

Post Reply
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Drawing a rigid body's path?

Post by jimjamjack »

I have a first person shooter game made with Bullet and OpenGL, but I'm now trying to draw the path that my bullets take. They're the only moving body in my scene, and I'm aiming for something simple like a red line that draws from the body's starting position to its final position, and preferably this is only done on the last bullet fired so that the screen isn't filled with red lines. Basically, I'm looking for something that can draw a bullet's trail through the scene.

I'm asking here because I'm unsure about how to do this in OpenGL, and was hoping that Bullet provides some functionality for this (since Bullet has a debug drawer that draws rigid bodies, I was wondering if it has something that can draw a body's path...).

Failing that, since a few people use Bullet for these kind of games, does anyone have an example piece of OpenGL code that they've used for something like this?

Thanks in advance.
erbisme4@yahoo.com
Posts: 41
Joined: Fri Apr 29, 2016 2:41 pm

Re: Drawing a rigid body's path?

Post by erbisme4@yahoo.com »

You can probably fake the trajectory line using a linear spline. Get the rigidBody position at time(n), and time(n+1) and that is your endpoints for your line.

glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f); //red
glVertex3f(0.0f, 0.0f, 0.0f); //origin
glVertex3f(0.0f, 0.0f, 1.0f); //bullet fired straight up
glEnd();
Post Reply