0

我想在 OpenGL 中移动一个对象。我在 (0,0,0) 中绘制对象,如果对象在该点上,它会很好地旋转(使用对象的中心作为旋转的参考)。当我移动对象时,问题就出现了,它使用与参考相同的点而不是它所在的点旋转。代码是:

glPushMatrix();
glRotatef(xangle,1.0f,0.0f,0.0f);
    glRotatef(yangle,0.0f,1.0f,0.0f);
    glRotatef(zangle,0.0f,0.0f,1.0f);
    glTranslatef(x,y,z);
//draw object
    glPopMatrix();

有谁知道它必须做什么,所以对象总是使用它作为参考的点旋转?

4

1 回答 1

1

只需重新排序您的转换:

glPushMatrix();
glTranslatef(x,y,z);
glRotatef(xangle,1.0f,0.0f,0.0f);
glRotatef(yangle,0.0f,1.0f,0.0f);
glRotatef(zangle,0.0f,0.0f,1.0f);
//draw object
glPopMatrix();
于 2013-05-05T20:33:00.157 回答