如何在OpenGL中获得变换坐标?

时间:2012-08-28 01:49:40

标签: opengl

我画出如下的实心球体:

glPushMatrix();
    glScalef(0.015, 0.015, 0.015);
    glRotatef(90, 1.0, 0.0, 0.0);
    glTranslatef(0.0, 200, 0.0);
    glRotatef(-20, 0.0, 0.0, 1.0);
    glRotatef(-20, 1.0, 0.0, 0.0);
    glTranslatef(78.75, -110.74, -13.53);
    glutSolidSphere(4.0f,15,15);
glPopMatrix();

如何获得此实心球体的变换坐标?

2 个答案:

答案 0 :(得分:-1)

您可以通过函数GL_MODELVIEW_MATRIX获取状态变量glget

它从ModelView堆栈返回当前矩阵。我认为这就是你所需要的。

答案 1 :(得分:-1)

将已转换的坐标放在变量中,然后您将不必检索变形的形状坐标。

float solidSphereX = whatever;
float solidSphereY = whatever;
float solidSphereZ = whatever;
float solidSphereRotationX = whatever in radians;
float solidSphereRotationY = whatever in radians;
float solidSphereRotationZ = whatever in radians;
...
glPushMatrix();
glRotatef(solidSphereRotationX, solidSphereRotationY, solidSphereRotationZ);
glTranslatef(solidSphereX, solidSphereY, solidSphereZ);
glPopMatrix();