我正在尝试仅旋转我使用 LWJGL 在 Java 中创建的场景中的两个对象之一。
现在,当我尝试旋转一个对象时,它不会围绕它的中心旋转,而是以大圆圈旋转。在谷歌上搜索后,我现在知道它应该像这样工作:
glPushMatrix();
glBegin();
//Code in here
glEnd();
glRotate();
glPopMatrix();
但这对我不起作用。物体没有旋转。这是我的渲染代码:
public void render() {
glPushMatrix();
glRotatef(rotate, 0, 1.0f, 0);
glBegin(GL_QUADS);
// Top
glVertex3f(-centerX + size, centerY + size, -centerZ - size);
glVertex3f(-centerX - size, centerY + size, -centerZ - size);
glVertex3f(-centerX - size, centerY + size, -centerZ + size);
glVertex3f(-centerX + size, centerY + size, -centerZ + size);
// Bottom
glVertex3f(-centerX + size, centerY - size, -centerZ + size);
glVertex3f(-centerX - size, centerY - size, -centerZ + size);
glVertex3f(-centerX - size, centerY - size, -centerZ - size);
glVertex3f(-centerX + size, centerY - size, -centerZ - size);
// One side
glVertex3f(-centerX + size, centerY + size, -centerZ + size);
glVertex3f(-centerX - size, centerY + size, -centerZ + size);
glVertex3f(-centerX - size, centerY - size, -centerZ + size);
glVertex3f(-centerX + size, centerY - size, -centerZ + size);
// Moar sides
glVertex3f(-centerX + size, centerY - size, -centerZ - size);
glVertex3f(-centerX - size, centerY - size, -centerZ - size);
glVertex3f(-centerX - size, centerY + size, -centerZ - size);
glVertex3f(-centerX + size, centerY + size, -centerZ - size);
// Last side
glVertex3f(-centerX - size, centerY + size, -centerZ + size);
glVertex3f(-centerX - size, centerY + size, -centerZ - size);
glVertex3f(-centerX - size, centerY - size, -centerZ - size);
glVertex3f(-centerX - size, centerY - size, -centerZ + size);
// Real last side
glVertex3f(-centerX + size, centerY + size, -centerZ - size);
glVertex3f(-centerX + size, centerY + size, -centerZ + size);
glVertex3f(-centerX + size, centerY - size, -centerZ + size);
glVertex3f(-centerX + size, centerY - size, -centerZ - size);
glEnd();
glPopMatrix();
rotate++;
}
我现在尝试解决这个问题几个小时,但无法让它工作。