[英]OpenGL rotate 3D Cube on own Axis
I have a 3D cube and I want to rotate it, but not using X,Y,Z Axis. 我有一个3D立方体,但我想旋转它,但不使用X,Y,Z轴。
I would like to rotate the cube on its own Axis. 我想在自己的轴上旋转立方体。
For example: I move my cube from right to left : my cube should rotate on bottom-left-axis of vertex about 90 Degree and not on Z-Axis about 90 Degree. 例如:我将多维数据集从右向左移动:我的多维数据集应该在顶点的左下轴上旋转大约90度,而不在Z轴上旋转大约90度。
I tried this : 我尝试了这个:
//prespektive...
gluPerspective(45,1.0,2.0,30.0);
//look at...
gluLookAt(0.0,2.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
//try to rotate cube on bottom-right-axis
glTranslatef(-(-0.7), 0.40, -(-0.25));
glRotatef(90, 1,0,0);
glRotatef(90, 0,1,0);
glRotatef(90, 0,0,1);
glTranslatef(-0.7, 0.40, -0.25);
But it is not working. 但这是行不通的。 Any idea ?
任何想法 ?
Why did you spoil projection matrix. 你为什么破坏投影矩阵。 Before rotating the cube go to
MODELVIEW
matrix mode 旋转多维数据集之前,请转到
MODELVIEW
矩阵模式
// Setup the projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1.0,1.0,30.0); // front clip plane to 1.0
// Now go to modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//look at...
gluLookAt(0.0,2.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
//try to rotate cube on bottom-right-axis
glTranslatef(-(-0.7), 0.40, -(-0.25));
glRotatef(90, 1,0,0);
glRotatef(90, 0,1,0);
glRotatef(90, 0,0,1);
glTranslatef(-0.7, 0.40, -0.25);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.