PDA

View Full Version : Drawing a rigid body's path through the scene?



eratic-magician
04-23-2017, 09:48 AM
I've been working on a first-person shooter game with Bullet and OpenGL, and now have it to the point of being able to fire bullets through the scene. I'm now looking to draw the path these bullets take, from starting position to their ending position, with the entire path staying drawn until the next bullet is fired (so that the screen isn't cluttered).

I'm basically just looking for something like a red line that extends to the bullet's new position each frame, or something like that. So, by the time the bullet has gone from the gun to its final stopping place, the red line will show the exact path it took, what it bounced off of, etc.

I've tried looking for examples but I can't find anything useful. I've seen mention of leaving a trail behind an object using an accumulation buffer, but that's not really what I want.

How can this be done? Does everyone know of any examples or tutorials for this?

GClements
04-23-2017, 12:54 PM
You can draw a sequence of connected line segments with glDrawArrays(GL_LINE_STRIP). The rest is a matter of getting the positions out of the physics engine and storing them, which isn't an OpenGL issue.

eratic-magician
04-24-2017, 04:51 PM
Thanks, I can't seem to figure out how to use this properly though.

I have this:
for (i = 0; i < latestMesh; i++ {
// Render each mesh up to how many there are
// Update meshPosition[i] xyz position based off physics
}
points.push_back(vec3(meshPositions[lastestMesh].x, meshPositions[lastestMesh].y, meshPositions[lastestMesh].z));

Which adds the latest mesh's position to a vector<vec3> of points. What exactly do I need to draw the line?