绕Z轴旋转45度:glRotatef(45.0,0.0,0.0,1.0);
为了绕Z轴旋转45度(10.0,-5.0,0.0),我需要翻译吗?
答案 0 :(得分:1)
关于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
推/弹矩阵经常被误解,这就是我举例说明的原因。在新的OpenGL中,没有隐式矩阵堆栈,因此需要手动管理他的矩阵。它变得稍微复杂一点,但作为回报,没有混淆。