Question

In my glut application I'm simulating a plane with the camera. When the planes speed is low I intend to have the nose start to point towards the ground as the camera falls. My first instinct was to just change the pitch until it was pointed downwards at -90degrees. However I can't just change the pitch because if the plane is tilted on its side or upside down then it would note be changing direction towards the ground.

Now i'm trying to do a rough simulation of this by shifting the 'lookAt.y' downwards. To do this I am trying to get all the current camera coordinates that I use to set the camera (eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z). Then recall the set with the new modified values.

I've been working with the Camera.cpp and Camera.h to control my camera functions. They can be found here

after adding methods to get all the values, only the eye values are actually updated when various camera motions are made. I guess my question is how do I retrieve these values.

The glLoadMaxtrix call is in this function

void Camera :: setModelViewMatrix(void)

{ // load model view matrix with existing camera values

    float m[16];

    Vector3 eVec(eye.x, eye.y, eye.z);

    m[0] =  u.x; m[4] =  u.y; m[8]  =  u.z;  m[12] = -eVec.dot(u);

    m[1] =  v.x; m[5] =  v.y; m[9]  =  v.z;  m[13] = -eVec.dot(v);

    m[2] =  n.x; m[6] =  n.y; m[10] =  n.z;  m[14] = -eVec.dot(n);

    m[3] =  0;   m[7] =  0;   m[11] =  0;    m[15] = 1.0;

look.x = u.y; look.y = v.y; look.z = n.y; 

    glMatrixMode(GL_MODELVIEW);

    glLoadMatrixf(m);

}

Is there a way to get 'eye', 'lookAt', and 'up' values from the matrix here? Or should I do something else to get these values?

-Thanks in advance for your help

Was it helpful?

Solution

The camera class you link to is not an actual OpenGL class, but it should be simple enough to work with.

The function quoted just takes the current values of the camera object and sends them to OpenGL. If you look at the camera's set function, you can see how the program calculates the values it actually stores.

The eye value is stored directly. The lookAt value is just the value of (eye - n), by vector math. The up value is the hardest, but if I remember my vector math correctly, I believe that up = (n cross u).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top