Camera system in OpenGL!!!

Started by
11 comments, last by Moonchild7 21 years ago
Is there any detailed tutorials explaining the more flexible way of camera handling??
Advertisement
Ahhhh.... managed to get the mouse view rotation and zoom features working OK

But still not able to move point of interest properly, only along the global axis *snif* The info I am storing is:

camera heading = horizontal angle with interest point
camera inclination = vertical angle with interest point
orbit distance = distance from interest point to camera position
interest point position = XYZ coords of interest point

Do I need to store any other information (view vector, up vector, right vector...) to be able to move along the viewing direction?

I have tried to do it by calculating the camera position:

camPos[X] = camera->interestPoint[X];
camPos[Y] = camera->viewDistance * sin(Radians(camera->viewInclination));
camPos[Z] = camera->viewDistance * cos(Radians(camera->viewInclination));

(I want my camera to always be "behind" the interest point, i.e. when you press the "forward" key it should always go in the viewing direction)

I have managed this using vectors, but then the camera wouldn''t orbit properly.

Arghh! If it''s not one thing it is another... damn me!!

the interesting part first: do you want the camera to rotate with the object or not?

after directx i tend to always keep the matrices for each object around. i find it easier than keeping track of the modelview matrix.

the problem is, that theres is no seperate view matrix, so you have to call glulookat BEFORE any other transformations. in your case you dont know what to call glulookat with before the object has moved. if you had the matrix for both it would look like this:

//object stuff
glloadmatrix(objectmatrix) //this contains the last position and orientation
glrotate(rotation for frame)
gltranslate(movement for frame) //these are small steps so the order doesnt matter much.. AND they are local.. so moving right will strafe etc.
glgetmatrix(objectmatrix)

you now have all you need with doing sin/cos whatever yourself

the camera//
glloadmatrix(objectmatrix) //if camera should follow rotations

/*
//if camera should not follow rotations though obviously you dont need the object matrix and would only need its position
glidentity
gltranslate(object position)
*/

glrotate(camera left/right)
glrotate(camera up/down)
gltranslate(backwards)
glgetmatrix(cameramatrix)

glulookat()
glpush()
//hope nobody saw this before editing
glmultmatrix(objectmatrix)
render object
glpop()

if multmatrix seems to do the opposite of what you need you can relax.. forget the first part, load your objects matrix (or just do transformations) and multiply the cams matrix to it.

[edited by - Trienco on April 1, 2003 3:25:40 AM]
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement