物体绕其侧面旋转

时间:2012-12-01 07:35:57

标签: c++ opengl 3d

我正在尝试使用对象在我的项目中创建一些旋转动画。

目前,要为对象设置动画,我编写了一些补间功能,将参数作为value from, value to, value time并将对象从from Param补间到to Param,并在给定时间内补充对象的运动。但是,我需要创建一些类似于以下内容的动画:

enter image description here

物体必须绕某一侧旋转。所以,如果使用这种算法,可以使用:

for(int rotationAmount = 0;rotationAmount<=90;rotationAmount++){
glPushMatrix();
glRotatef(rotationAmount,1,0,0);
Rectangle(500,500,200,100);
glPopMatrix();
}

我仍然没有得到所需的效果,因为矩形而不是围绕某一侧旋转看起来像围绕一些大圆圈的旋转并回来。真的很欢迎这里有关于如何实现上述目标的一些建议吗?

1 个答案:

答案 0 :(得分:2)

glRotatef将当前矩阵乘以旋转矩阵。旋转矩阵围绕坐标旋转。您需要将对象转换为对象的一侧,执行旋转,然后转换回来。

point_type point_on_the_side;
for(int rotationAmount = 0;rotationAmount<=90;rotationAmount++){
    glPushMatrix();
    glTranslatef(-point_on_the_side.x, -point_on_the_side.y, -point_on_the_side.z);
    glRotatef(rotationAmount,1,0,0);
    glTranslatef(point_on_the_side.x, point_on_the_side.y, point_on_the_side.z);
    Rectangle(500,500,200,100);
    glPopMatrix();
}