C++ OpenGl-对象在旋转180度后反转
我渲染了一个对象,我正试图用鼠标旋转该对象。对象将精细旋转180度,但此后,对象将反转(如果面向摄影机,则切换为面向摄影机),正如鼠标的预期移动一样,即,如果向右拖动鼠标将顺时针旋转对象,则对象现在将逆时针旋转。一旦达到下一个180度,它将再次反转并恢复法线。我肯定有一些简单的东西我只是看不到 这是我的密码:C++ OpenGl-对象在旋转180度后反转,c++,opengl,rotation,C++,Opengl,Rotation,我渲染了一个对象,我正试图用鼠标旋转该对象。对象将精细旋转180度,但此后,对象将反转(如果面向摄影机,则切换为面向摄影机),正如鼠标的预期移动一样,即,如果向右拖动鼠标将顺时针旋转对象,则对象现在将逆时针旋转。一旦达到下一个180度,它将再次反转并恢复法线。我肯定有一些简单的东西我只是看不到 这是我的密码: // Detect mouse state void mouse(int button, int state, int x, int y) { if (button == GLUT
// Detect mouse state
void
mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
moving = 1;
beginX = x;
beginY = y;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
{
moving = 0;
}
}
// Detect mouse movement
void motion(int x, int y)
{
if (moving)
{
angleX = (angleX + (x - beginX));
angleY = (angleY + (y - beginY));
beginX = x;
beginY = y;
newModel = 1;
glutPostRedisplay();
}
}
// Rotate object
void recalcModelView(void)
{
// Get object's centre
int hh = head->GetHeight() / 2;
int hw = head->GetWidth() / 2;
int hd = head->GetDepth() / 2;
glPopMatrix();
glPushMatrix();
// Rotate object based on mouse movement
glTranslatef(hw, hd, hh);
float temp1 = angleX / 5;
float temp2 = angleY / 5;
printf("TEMP1: %g\n", temp1);
printf("TEMP2: %g\n", temp2);
glRotatef(temp1, 0.0, 1.0, 0.0);
glRotatef(-temp2, 1.0, 0.0, 0.0);
glTranslatef(-hw, -hd, -hh);
newModel = 0;
}
使用类似的方法来解决此问题。您能准确解释一下“反转为预期的移动”是什么意思吗?我认为你的代码看起来不错。我不是OpenGL专家,但你使用的
glPopMatrix();glPushMatrix()代码>序列可疑。@Xymostech道歉。那是个打字错误。这意味着鼠标移动也会反转,即如果将鼠标向右拖动,对象通常会顺时针旋转,那么向右拖动鼠标将使对象逆时针旋转