在 OpenGL 中以固定速度沿贝塞尔曲线移动对象
Moving An Object Along a Bezier Curve in OpenGL With Fixed Velocity
我正在做一个 OpenGL 项目,它简单地使用二维数组来创建贝塞尔曲线(顺序是起点 -> 开始控制点 -> 结束控制点 -> 结束):
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}
};
并使用以下公式沿该路径移动一个字符,该公式取自 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;
问题是,这种逻辑会导致非常不稳定的运动,一旦时钟超过 1 秒,运动也会迅速加速。这显然不理想;我希望女孩的运动速度是固定的,理想情况下我还希望能够选择执行运动的速度。我已尝试对这个公式进行很多调整,但我无法解决这个问题,我将如何更改此代码以获得我正在寻找的结果?
查看 link 您提供的公式,您的方程式有误。第二项使用 3 + time
而应该是 3 * time
(3 * time*(1 - time)*(1 - time))* controlPointsGirl[1][0]
在两个方程中。
我正在做一个 OpenGL 项目,它简单地使用二维数组来创建贝塞尔曲线(顺序是起点 -> 开始控制点 -> 结束控制点 -> 结束):
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}
};
并使用以下公式沿该路径移动一个字符,该公式取自 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;
问题是,这种逻辑会导致非常不稳定的运动,一旦时钟超过 1 秒,运动也会迅速加速。这显然不理想;我希望女孩的运动速度是固定的,理想情况下我还希望能够选择执行运动的速度。我已尝试对这个公式进行很多调整,但我无法解决这个问题,我将如何更改此代码以获得我正在寻找的结果?
查看 link 您提供的公式,您的方程式有误。第二项使用 3 + time
而应该是 3 * time
(3 * time*(1 - time)*(1 - time))* controlPointsGirl[1][0]
在两个方程中。