c++logicbezierparameterization

Moving An Object Along a Bezier Curve in OpenGL With Fixed Velocity


I'm working on an OpenGL project which simply uses a 2D array to create a bezier curve (order is start point -> start control point -> end control point -> end):

GLfloat controlPointsGirl[numControlPointsGirl][3] = {
    {1.0,0.0,0.0},{1.0,-0.5,0.0},{1.0,0.0,0.0},{-1.0,0.5,0.0}
};  

And moves a character along that path with the following formula, taken from https://www.opengl.org/discussion_boards/showthread.php/136550-Moving-object-along-a-bezier-curve :

//Drawing, initializing, display refresh every timeInterval seconds, etc.

girlX = ((1 - time)*(1 - time)*(1 - time)*controlPointsGirl[0][0]
    + (3 + time*(1 - time)*(1 - time))* controlPointsGirl[1][0]
    + (3 * time*time*(1 - time))* controlPointsGirl[2][0]
    + time*time*time*controlPointsGirl[3][0])
    /10;

cout << girlX <<" ";

girlY = ((1 - time)*(1 - time)*(1 - time)*controlPointsGirl[0][1]
    + (3 + time*(1 - time)*(1 - time))* controlPointsGirl[1][1]
    + (3 * time*time*(1 - time))* controlPointsGirl[2][1]
    + time*time*time*controlPointsGirl[3][1])
    /10;

cout << girlY << endl;

time += timeInterval;

The problem is, this logic leads to very jerky motion, which also rapidly accelerates as soon as the clock exceeds 1 second. This obviously isn't ideal; I want the velocity of the girl's motion to be fixed, and ideally I also want to be able to choose a velocity at which the motion will be carried out. I've tried a lot of tweaks to this formula but am having trouble wrapping my head around the issue, how would I alter this code to achieve the results I'm looking for?


Solution

  • Looking at the link to the formula you provided, you have a mistake in your equations. The second term uses 3 + time when it should be 3 * time

    (3 * time*(1 - time)*(1 - time))* controlPointsGirl[1][0]
    

    in both equations.