0

オブジェクトをレンダリングして、マウスでオブジェクトを回転させようとしています。オブジェクトは 180 度回転しますが、その後、マウスの予期される動きと同様にオブジェクトが反転します (カメラの方を向いている場合は、カメラから離れた面に切り替わります)。つまり、マウスを右にドラッグするとオブジェクトが時計回りに回転し、反時計回りに回転します。次の 180 度に達すると、再び反転し、正常に戻ります。私が見ていない単純なものがあるに違いないと確信していますか?

これが私のコードです:

// 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;
}
4

1 に答える 1

0

これを修正するには、 Arcballなどを使用します。

于 2013-03-28T19:38:43.397 に答える