View Full Version : Making a camera (1000th time)

06-04-2002, 07:37 AM
Im working on a proper working camera for my application...Ive go it working a bit, but an essential part is missing.
Im using gluLookAt(...) to simulate my camera. So I pass the x,y,z values of my camera as the first parameters and then a point which is faced by the camera....I could figure out the x and y coordinate, but the z coordinate???
Heres a little code:

float tDir_x, tDir_y, tDir_z;

tDir_x = x + cos(angle_z);
tDir_y = y + sin(angle_z);

tDir_z = ????; //something with angle_x...

gluLookAt(x,y,z,tDir_x ,tDir_y,tDir_z,0.0f,0.0f,-1.0f);

angle_x and angle_z are calculated by the offset of the mouse position, so you can look around with the mouse.
Someone has an idea??
Thanks in advance!!

06-04-2002, 08:58 AM
Assuming a right handed coordinate system with x-axis pointing to the right, y-axis pointing up and z-axis towards user, alpha being the rotaion around y-axis and beta being the angle between the Oxz plane and the view direction the coordinates of the vector are:

tDir_x = cosf (beta) * sinf (alpha);
tDir_y = sinf (beta);
tDir_z = cosf (beta) * cosf (alpha);

gluLookAt (x, y, z, tDir_x, tDir_y, tDir_z, 0.0f, 1.0f, 0.0f);

(Hint: cosf (beta) is the length of the projection of the view vector on the Oxz plane http://www.opengl.org/discussion_boards/ubb/smile.gif