1

オブジェクトは 0,0,0 を中心に回転していますが、Y 軸を中心に回転させたいです。他のケースもあると思います

OpenGLでオブジェクトを回転させる

glRotatef が期待どおりに回転しない

しかし、ローテーションの前に翻訳がなく、まだ機能しません。

私の編集コード:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(_angle,0.0f,1.0f,0.0f);
glPushMatrix();

glTranslatef(0.0f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
    //Front
    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(1.0f, 1.0f, 1.0f);

    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f(1.0f, -1.0f, 1.0f);
    glVertex3f(1.0f, 1.0f, 1.0f);

    //Back
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, 1.0f, -1.0f);
    glVertex3f(1.0f, 1.0f, -1.0f);

    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(1.0f, -1.0f, -1.0f);
    glVertex3f(1.0f, 1.0f, -1.0f);

    //Right
    glVertex3f(1.0f, 1.0f, 1.0f);
    glVertex3f(1.0f, -1.0f, 1.0f);
    glVertex3f(1.0f, -1.0f, -1.0f);

    glVertex3f(1.0f, 1.0f, 1.0f);
    glVertex3f(1.0f, 1.0f, -1.0f);
    glVertex3f(1.0f, -1.0f, 1.0f);


    //Left
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);

    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, -1.0f);


    //Top
    glVertex3f(-1.0f, 1.0f, -1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(1.0f, 1.0f, 1.0f);

    glVertex3f(-1.0f, 1.0f, -1.0f);
    glVertex3f(1.0f, 1.0f, -1.0f);
    glVertex3f(1.0f, 1.0f, 1.0f);


    //Bottom
    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(-1.0f, -1.0f, 1.0f);
    glVertex3f(1.0f, -1.0f, 1.0f);

    glVertex3f(-1.0f, -1.0f, -1.0f);
    glVertex3f(1.0f, -1.0f, -1.0f);
    glVertex3f(1.0f, -1.0f, 1.0f);
glEnd();
glPopMatrix();

glutSwapBuffers();

私の元のコード:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glRotatef(angle,0.0f,1.0f,0.0f);  //The angle is a float that slowly increases until it reaches 360 Degrees, and then resets to 0.0
    /* This is a Cube */
glBegin(GL_TRIANGLES);
    //Front
    glVertex3f(-1.0f, -1.0f, -5.0f);
    glVertex3f(-1.0f, 1.0f, -5.0f);
    glVertex3f(1.0f, 1.0f, -5.0f);

    glVertex3f(-1.0f, -1.0f, -5.0f);
    glVertex3f(1.0f, -1.0f, -5.0f);
    glVertex3f(1.0f, 1.0f, -5.0f);

    //Back
    glVertex3f(-1.0f, -1.0f, -7.0f);
    glVertex3f(-1.0f, 1.0f, -7.0f);
    glVertex3f(1.0f, 1.0f, -7.0f);

    glVertex3f(-1.0f, -1.0f, -7.0f);
    glVertex3f(1.0f, -1.0f, -7.0f);
    glVertex3f(1.0f, 1.0f, -7.0f);

    //Right
    glVertex3f(1.0f, 1.0f, -5.0f);
    glVertex3f(1.0f, -1.0f, -5.0f);
    glVertex3f(1.0f, -1.0f, -7.0f);

    glVertex3f(1.0f, 1.0f, -5.0f);
    glVertex3f(1.0f, 1.0f, -7.0f);
    glVertex3f(1.0f, -1.0f, -5.0f);


    //Left
    glVertex3f(-1.0f, 1.0f, -5.0f);
    glVertex3f(-1.0f, -1.0f, -5.0f);
    glVertex3f(-1.0f, -1.0f, -7.0f);

    glVertex3f(-1.0f, 1.0f, -5.0f);
    glVertex3f(-1.0f, 1.0f, -7.0f);
    glVertex3f(-1.0f, -1.0f, -7.0f);


    //Top
    glVertex3f(-1.0f, 1.0f, -7.0f);
    glVertex3f(-1.0f, 1.0f, -5.0f);
    glVertex3f(1.0f, 1.0f, -5.0f);

    glVertex3f(-1.0f, 1.0f, -7.0f);
    glVertex3f(1.0f, 1.0f, -7.0f);
    glVertex3f(1.0f, 1.0f, -5.0f);


    //Bottom
    glVertex3f(-1.0f, -1.0f, -7.0f);
    glVertex3f(-1.0f, -1.0f, -5.0f);
    glVertex3f(1.0f, -1.0f, -5.0f);

    glVertex3f(-1.0f, -1.0f, -7.0f);
    glVertex3f(1.0f, -1.0f, -7.0f);
    glVertex3f(1.0f, -1.0f, -5.0f);
glEnd();

glutSwapBuffers();
4

1 に答える 1

2

オブジェクトの中心がローカル座標系の原点にあることを確認してください。

立方体の場合、X/Y は中心にあるように見えますが、Z 中心は -6 に見えます。

于 2013-01-04T16:01:19.120 に答える