How to simulate path with large number of points

Hi all!
I’m trying to make an application to do path simulation and show the moving point animation. Basically, I have a set of ordered points that are pre-calculated and I want to show this path to a user. Currently My code is like following

int total = points.size();
int current = 0;
for(int current = 0;current<total;current++)
{
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
for(int i = 0; i<current; i++)
{
glVertex3f(points[i].x,points[i].y,points[i].z);
}
glEnd();
glutPostRedisplay(); //repaint the display
glFlush();
glutSwapBuffers();
}

As you can see, it repaints for every new point and the user can see a moving point. However, it works fine for small number of points. If I have a large number of points (eg 10 million), it becomes very slow at the end.

If I dont repaint previous points, everything disappears. Is there anyway to persist what I have drawn on the screen?

Thank you

Using immediate commands such as glVertex3f is very costly, so completely unsuitable for millions of points.

For much better performance, try with VBO :
http://www.opengl.org/wiki/VBO
http://www.opengl.org/wiki/VBO_-_more

You can try to split the point cloud in chunks, with static points separated from dynamic points (less vbo updates to be done).

Redrawing everything is the classic way of doing hardware-accelerated computer graphics.
If you have a static camera however, there are tricks such as draw framebuffer once (with all static points), copy it to a texture, then for all other frames, draw a full size texture quad + the moving points. It may or may not be faster.

Hi Zbuffer!
Thank you for your advice.
I will try it out.

Hi mclz522,

you are already drawing line segments, so you could also try to simplify the geometry by leaving out points that are on or close to a line segment anyway. If your curve doesn’t change, you only need to do that once.

There’s a simple recursive subdivision scheme. According to wikipedia, it’s called the “Ramer-Douglas-Peucker” algorithm. Funny, I never knew it actually had a fancy name :slight_smile:

Here’s the link: http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm