Мой объект вращается вокруг 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();
Убедитесь, что центр вашего объекта находится в начале локальной системы координат.
Для вашего куба ваш X / Y кажется центрированным, но ваш Z-центр выглядит как -6.
Других решений пока нет …