OpenGL关于z轴的旋转
绕Z轴旋转45度:OpenGL关于z轴的旋转,opengl,rotation,Opengl,Rotation,绕Z轴旋转45度:glRotatef(45.0,0.0,0.0,1.0) 对于围绕点(10.0,-5.0,0.0)的Z轴旋转45度,是否需要平移?glRotatef()函数的特点是它只能围绕原点旋转。因此,对于围绕特定点的旋转,需要将该点平移到原点,执行旋转,然后平移回原点。因此,对于你的点(10,-5,0),你应该: glPushMatrix(); // you do this to avoid disturbing the transformation matrices for any co
glRotatef(45.0,0.0,0.0,1.0)代码>
对于围绕点(10.0,-5.0,0.0)的Z轴旋转45度,是否需要平移?glRotatef()函数的特点是它只能围绕原点旋转。因此,对于围绕特定点的旋转,需要将该点平移到原点,执行旋转,然后平移回原点。因此,对于你的点(10,-5,0),你应该:
glPushMatrix(); // you do this to avoid disturbing the transformation matrices for any code following the below lines
glTranslatef(-10, +5, 0); // translate so that (10, -5, 0) lies at the origin
glRotatef(45, 0, 0, 1); // now rotate
glTranslatef(10, -5, 0); // translate back
// now you have rotated the scene by 45 degrees arround z-axis, at point (10, -5, 0)
// (draw your object *here*)
glPopMatrix(); // the old matrix is back
// now it is as if nothing happened
push/pop矩阵经常被误解,这就是我举例说明的原因。在新的OpenGL中,没有隐式矩阵堆栈,因此需要手动管理矩阵。它会变得稍微复杂一些,但反过来也不会产生混淆。对于围绕点旋转,是的,您还需要进行平移。由您决定是否要平移、旋转对象,然后平移回不通过下一次变换级联的对象,或者将这两个对象放在glPushMatrix()和glPopMatrix()callspush、GLTRANSTEF、glrotatef、pop之间。谢谢