简体   繁体   English

绕Y轴旋转gluLookAt

[英]Rotate about Y-Axis gluLookAt

I am trying to rotate the viewer about the y-axis. 我正在尝试围绕y轴旋转查看器。 I have a function called tranform_eye() which will calculate the next position of eyex , eyey and eyez after each update. 我有一个名为tranform_eye()的函数, eyez在每次更新后计算eyexeyeyeyez的下一个位置。

Can anyone help me figure out how to calculate the values for eyex , eyey and eyez ? 谁能帮我找出如何计算eyexeyeyeyez的值?

My Code: 我的代码:

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

Applying the math from eg this answer gives us: 这个答案中应用数学可以得出:

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