簡體   English   中英

繞Y軸旋轉gluLookAt

[英]Rotate about Y-Axis gluLookAt

我正在嘗試圍繞y軸旋轉查看器。 我有一個名為tranform_eye()的函數, eyez在每次更新后計算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.
}

這個答案中應用數學可以得出:

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM