View Full Version : Moving object along a bezier curve

A. Kueken
01-22-2005, 03:11 PM

I constructed my Object/Model in a DisplayList. Now i want to move this object along a bezier curve.

Here is my code for the curve:

void drawCurve(void) {
float pointsforcurve[4][3];
int i = 0;

glColor3f(1.0, 0.0, 0.0);

/* Converting 2i point array to 3f point array */
for (i = 0; i < 4; i++) {
pointsforcurve[i][0] = (float)points[i][0];
pointsforcurve[i][1] = (float)points[i][1];
pointsforcurve[i][2] = 0.0f;

glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &amp;pointsforcurve[0][0]);


for(i = 0; i < 100; i++) {
}This code works fine for me, but I do not know, how to move my object alonge the curve, because the gl EvalCoord function do not return the point of the curve.

In order to move it along, i need the coords of the curvepoints, to make something like this:

glTranslatef(xofcurvepoint, yofcurvepoint, zofcurvepoint);
glCallList(listForkLifter);Can someone help me? Or is there a better way to do it?

thx Alexander

01-22-2005, 04:58 PM
You cant get that information from opengl. You need to compute the value of the bezier parametric equation yourself.

I would suggest keeping track of the bezier curve yourself. If you have 2 endpoints(A and D), then you need 2 additional control points(B&C) to form tangents to the curve at these 2 endpoints. Thus you need 4 points to create a bezier curve between 2 points. With these four points, you can compute a position at any point along the curve with the following (maybe you know this already):
p(t) =
(1-t)^3 * A +
(3t*(1-t)^2)* B +
(3*t*t*(1-t))* C +

Picking the tangent is up to you. ;)