简体   繁体   中英

Rotate about Y-Axis gluLookAt

I am trying to rotate the viewer about the y-axis. I have a function called tranform_eye() which will calculate the next position of eyex , eyey and eyez after each update.

Can anyone help me figure out how to calculate the values for eyex , eyey and eyez ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM