使用 glRotatef() 时 OpenGL 坐标问题

OpenGL issue with coordinates when using glRotatef()

我是 OpenGL 的初学者(使用 LWJGL),我正在尝试对模型应用 90 度的旋转。问题是,当旋转应用于模型时,它似乎也改变了它的坐标,导致模型被放置在边界之外。我尝试过转换坐标,但不确定在哪里使用此方法,也不知道 glTranslate() 使用哪些参数。这是我正在使用的以下代码片段:

public void renderModel(int index) {
    Model model = Editor.models.get(index);
    glMatrixMode(GL_MODELVIEW);

    // apply rotation
    float rotation = 90f;
    glRotate(rotation, 0, 1, 0);

    for (int triangle = 0; triangle < model.face_cnt; triangle++) {
        if (model.face_verts.get(triangle).length == 3) {
            glBegin(GL_TRIANGLES);
        } else {
            glBegin(GL_QUADS);
        }
        for (int i = 0; i < model.face_verts.get(triangle).length; i++) {
                int point_a = model.face_verts.get(triangle)[i];

                float modelX = (float)((model.vert_x.get(point_a)) + x);
                float modelZ = (float)((model.vert_y.get(point_a)) - z4);
                float modelY = (float)((model.vert_z.get(point_a)) + y);

                glVertex3f(modelX, -modelZ, -modelY); // draw
        }
        glEnd();
    }
}

不将平移添加到顶点坐标(删除 + x- z4+ y)。

旋转模型然后平移它。 glTranslate has to be de done before glRotate,因为遗留的OpenGL矩阵运算指定了一个矩阵并将当前矩阵乘以新矩阵:

public void renderModel(int index) {
    Model model = Editor.models.get(index);
    glMatrixMode(GL_MODELVIEW);

    // apply rotation
    float rotation = 90f;

    glTranslate(x, -z4, y);
    glRotate(rotation, 0, 1, 0);

    for (int triangle = 0; triangle < model.face_cnt; triangle++) {
        if (model.face_verts.get(triangle).length == 3) {
            glBegin(GL_TRIANGLES);
        } else {
            glBegin(GL_QUADS);
        }
        for (int i = 0; i < model.face_verts.get(triangle).length; i++) {
                int point_a = model.face_verts.get(triangle)[i];

                float modelX = (float)((model.vert_x.get(point_a)));
                float modelZ = (float)((model.vert_y.get(point_a)));
                float modelY = (float)((model.vert_z.get(point_a)));

                glVertex3f(modelX, -modelZ, -modelY); // draw
        }
        glEnd();
    }
}