PDA

View Full Version : Trajectory Plotting



NoLowFat
01-25-2006, 01:15 PM
I have a question here on how to plot trajectories. Currently I have a piece of code that looks something like this. The forum wouldn't let me use parenthesis for some reason, so I'll use " to signal curved brackets.

glClear "GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT";
glPushMatrix"";
int q;

glBegin "GL_POLYGON";
glColor3f "1.0f,0.0f,0.0f";
for "q=0; q<12; q++"
glVertex3f "RADIUS*cos"PI/6*q"+15*xdes,RADIUS*sin"PI/6*q"+15*ydes,0.0";
glEnd"";

glPopMatrix"";

glutSwapBuffers"";

xdes and ydes are some global variables defining the location of the ball. This piece of code basically draws a circle moving across the screen depending on xdes and ydes, determined by another thread, which changes over time. I got that down ok.

What if I want to also trace the trajectory over time? I suppose I could save xdes and ydes into a massive data array and draw the entire trajectory everytime the screen refreshes. But this could be computationally expensive. Is there a way for me to draw the trajectory as new position data comes along without erasing what it has already drawn? I still want the circle to be shown as moving across the screen, so I guess the screen has to be cleared to a certain extent. Any help would be much appreciated. Thanks.

01-25-2006, 08:25 PM
The basic idea is to cache your object's data in a hardware friendly format, and that means using display lists or VBOs (vertex buffer objects). The choice kinda depends on whether your data change dynamically or not. I like VBOs, since they work for both cases.

I would look into the VBOs. You could create a single circle/sphere in a VBO, then draw a thousand instances of it by merely manipulating the modelview matrix stack to position and scale individual balls, for example.

And yes, you could animate all this in realtime without any trouble at all.

Cheers