【问题标题】:Rotate about Y-Axis gluLookAt绕 Y 轴旋转 gluLookAt
【发布时间】:2019-02-24 22:29:17
【问题描述】:

我正在尝试围绕 y 轴旋转查看器。我有一个名为tranform_eye() 的函数,它将在每次更新后计算eyexeyeyeyez 的下一个位置。

谁能帮我弄清楚如何计算eyexeyeyeyez 的值?

我的代码:

float eyex = 5;
float eyey = 5;
float eyez = 5;

void display() {

    transform_eye();

    glMatrixMode(GL_PROJECTION);     // To operate on model-view matrix
    glLoadIdentity();
    gluPerspective(40.0, 1.0, 1.0, 10000.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gluLookAt(eyex, eyey, eyez,
              0.0, 0.0, 0.0,
              0.0, 1.0, 0.0);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers

    drawTriangles();

    glutSwapBuffers();  // Swap the front and back frame buffers (double buffering)
}

void transform(){
    /// calculate new eyex, y z.
}

【问题讨论】:

    标签: c opengl matrix rotation glu


    【解决方案1】:

    从例如应用数学this answer 给我们:

    void transform()
    {
        float theta = 0.01; //angle in radians to rotate every frame
        float cosTheta = cos(theta);
        float sinTheta = sin(theta);
        float newX = cosTheta * eyeX + sinTheta * eyeZ;
        eyeZ = -sinTheta * eyeX + cosTheta * eyeZ;
        eyeX = newX;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-11
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多