我正在开发一个OpenGL项目,该项目只使用2D数组来创建贝塞尔曲线(顺序是起点 - >开始控制点 - >结束控制点 - >结束):
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秒,它也会迅速加速。这显然不太理想;我想要修复女孩运动的速度,理想情况下我也希望能够选择运动的速度。我已经对这个公式进行了很多调整,但我无法解决这个问题,我将如何更改此代码以实现我正在寻找的结果?
答案 0 :(得分:1)
查看您提供的公式的链接,您的方程式中存在错误。第二项使用3 + time
时应为3 * time
(3 * time*(1 - time)*(1 - time))* controlPointsGirl[1][0]
这两个方程式。