OpenGL glulookat function

459 Views Asked by At

I want to be able to view a planet sphere centred 0,0,0 with 10 units radius, 360 degrees and up down by clicking my keyboard buttons. What parameters do I put inside the glulookat() function as? I know the Center XYZ should be 000 but what should eye and up vector be?

void gluLookAt( GLdouble eyeX,
    GLdouble eyeY,
    GLdouble eyeZ,
    GLdouble centerX,
    GLdouble centerY,
    GLdouble centerZ,
    GLdouble upX,
    GLdouble upY,
    GLdouble upZ);
1

There are 1 best solutions below

0
Yakov Galka On

Don't use lookAt for this! The amount of trigonometry involved in calculating the eye vector is equivalent to building the view matrix from scratch.

Instead, maintain your camera pitch and yaw, and apply those by a series of translations and rotations:

glTranslatef(0, 0, -radius);
glRotatef(-pitch, 1, 0, 0);
glRotatef(-yaw, 0, 0, 1); // assumes Z is up