我的对象围绕 0,0,0 旋转,但我希望它在 Y 轴上围绕自身旋转。我知道还有其他情况
但我在旋转之前没有任何翻译,但它仍然不起作用。
我的编辑代码:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(_angle,0.0f,1.0f,0.0f);
glPushMatrix();
glTranslatef(0.0f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
//Front
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
//Back
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
//Right
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
//Left
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
//Top
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, -1.0f);
glVertex3f(1.0f, 1.0f, 1.0f);
//Bottom
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glEnd();
glPopMatrix();
glutSwapBuffers();
我的原始代码:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle,0.0f,1.0f,0.0f); //The angle is a float that slowly increases until it reaches 360 Degrees, and then resets to 0.0
/* This is a Cube */
glBegin(GL_TRIANGLES);
//Front
glVertex3f(-1.0f, -1.0f, -5.0f);
glVertex3f(-1.0f, 1.0f, -5.0f);
glVertex3f(1.0f, 1.0f, -5.0f);
glVertex3f(-1.0f, -1.0f, -5.0f);
glVertex3f(1.0f, -1.0f, -5.0f);
glVertex3f(1.0f, 1.0f, -5.0f);
//Back
glVertex3f(-1.0f, -1.0f, -7.0f);
glVertex3f(-1.0f, 1.0f, -7.0f);
glVertex3f(1.0f, 1.0f, -7.0f);
glVertex3f(-1.0f, -1.0f, -7.0f);
glVertex3f(1.0f, -1.0f, -7.0f);
glVertex3f(1.0f, 1.0f, -7.0f);
//Right
glVertex3f(1.0f, 1.0f, -5.0f);
glVertex3f(1.0f, -1.0f, -5.0f);
glVertex3f(1.0f, -1.0f, -7.0f);
glVertex3f(1.0f, 1.0f, -5.0f);
glVertex3f(1.0f, 1.0f, -7.0f);
glVertex3f(1.0f, -1.0f, -5.0f);
//Left
glVertex3f(-1.0f, 1.0f, -5.0f);
glVertex3f(-1.0f, -1.0f, -5.0f);
glVertex3f(-1.0f, -1.0f, -7.0f);
glVertex3f(-1.0f, 1.0f, -5.0f);
glVertex3f(-1.0f, 1.0f, -7.0f);
glVertex3f(-1.0f, -1.0f, -7.0f);
//Top
glVertex3f(-1.0f, 1.0f, -7.0f);
glVertex3f(-1.0f, 1.0f, -5.0f);
glVertex3f(1.0f, 1.0f, -5.0f);
glVertex3f(-1.0f, 1.0f, -7.0f);
glVertex3f(1.0f, 1.0f, -7.0f);
glVertex3f(1.0f, 1.0f, -5.0f);
//Bottom
glVertex3f(-1.0f, -1.0f, -7.0f);
glVertex3f(-1.0f, -1.0f, -5.0f);
glVertex3f(1.0f, -1.0f, -5.0f);
glVertex3f(-1.0f, -1.0f, -7.0f);
glVertex3f(1.0f, -1.0f, -7.0f);
glVertex3f(1.0f, -1.0f, -5.0f);
glEnd();
glutSwapBuffers();