代码之家  ›  专栏  ›  技术社区  ›  glennbrann

绕Y轴旋转GluLookat

  •  0
  • glennbrann  · 技术社区  · 6 年前

    我正试着让观察者绕y轴旋转。我有一个函数 tranform_eye() 它将计算 eyex , eyey eyez 每次更新后。

    有谁能帮我计算一下 艾克斯 , 艾伊 眼罩 ?

    我的代码:

    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.
    }
    
    0 回复  |  直到 6 年前
        1
  •  2
  •   Nico Schertler    6 年前

    应用例如 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;
    }