我使用了C ++ / OpenGL并画了一个旋转的立方体。现在我想让它在旋转时水平移动。我把一行glTranslatef(0.01,0,0)。它水平移动但不旋转。以下是我的代码。知道如何修复它以便立方体在旋转时可以水平移动吗?
void drawcube(void) {
int p[][3] = { { 1, 1, 1 }, { 1, -1, 1 }, { -1, -1, 1 }, { -1, 1, 1 },
{ 1, 1, -1 }, { 1, -1, -1 }, { -1, -1, -1 }, { -1, 1, -1 } };
int e[][4] = { { 0, 3, 2, 1 }, { 3, 7, 6, 2 }, { 7, 4, 5, 6 }, { 4, 0, 1, 5 },
{ 0, 4, 7, 3 }, { 1, 2, 6, 5 } };
float c[][3] = { { 1.0, 0, 0 }, { 0, 1.0, 0 }, { 1.0, 1.0, 0.0 },{ 0, 0, 1.0 }, { .6, 0, .6 }, { 0, .6, .6 } };
int i;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.01, 0, 0);
glRotatef(global.angle, 1.0, 1.0, 1.0);
for (i = 0; i < 6; ++i) {
glColor3fv(c[i]);
glBegin(GL_QUADS);
glVertex3iv(p[e[i][0]]);
glVertex3iv(p[e[i][1]]);
glVertex3iv(p[e[i][2]]);
glVertex3iv(p[e[i][3]]);
glEnd();
}
glutSwapBuffers();
}