我正在用 OpenGL 编写一个简单的应用程序。我有一个模型,我想围绕它的中心(局部坐标)旋转,然后将它连同它的局部坐标一起平移。我做了两个场景,旋转然后翻译,反之亦然。在第一种情况下,我得到了正确的旋转,但是模型然后根据世界坐标而不是模型(本地)坐标进行平移。当我首先翻译时,我得到了正确的翻译,但旋转不再围绕模型中心。这是代码,
glPushMatrix();
// ignore this
/*glRotatef(_zRoll, 0.0, 0.0, 1.0);
glRotatef(_yTilt, 1.0, 0.0, 0.0);
glRotatef(_xPan, 0.0, 1.0, 0.0);*/
glScalef(scale, scale, scale);
glTranslatef(0.0, 0.0, -2.0);
glTranslatef(_xTranslate, _yTranslate, _zTranslate); // The required translation
// The required rotation
glRotatef(_yangle, 0.0, 1.0, 0.0);
glRotatef(_zangle, 0.0, 0.0, 1.0);
glRotatef(_xangle, 1.0, 0.0, 0.0);
glTranslatef(coord.x, coord.y, coord.z); // translate to the model center
glCallList(aHelix);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glPopMatrix();
glutSwapBuffers();