Skip to main content
gamedev.net
🔒 Locked

Managing Camera Transformations

Started by Luca D Mar 9, 2009 at 10:14 AM 1 replies 850+ views
Original Post
Luca D
Luca D
Hi, I'm trying to understand which is a good solution to work with camera transformations: to allow the user to freely move around the space, or to rotate around a selected object, I've chosen to use gluLookAt. Hence, in my Camera class, I store informations about camera position and direction with two vectors. It works fine, but now I need to know the camera rotation angles for other tasks. How can I obtain them? Should I store their value or get them from the previous two vectors? Actually, when the user moves the mouse of dx and dy, I just do: Camera.Direction.x += dx; Camera.Direction.y += dy; Camera.Direction.Normalize(); Instead, using the arrow keys: Camera.Position.x += dx; Camera.Position.y += dy; And finally: gluLookAt(Camera.Position.x, ...); If I'd save something like: float RotX, RotY, RotZ; How could I update all these angles since I just know dx/dy? Thanks for any hints!
cignox1
cignox1
one way to get the camera rotation angles from the direction could be to use acos(X_axis dot X_camera) for eache of the three axes.

Alternatively, you can simply use angles directly and build your direction vector from them. Basic trigonometry is involved, but nothing too exhotic.
MJP
MJP
I'd really suggest finding a good 3D math library to use for things like this. For a concise, robust implementation of a camera you'll want more than just gluLookAt at your disposal. For instance you could store your rotation about the X-axis and rotation about Y-axis in two float's, and then create a single matrix representing the combined rotation. You could then use that to rotate your direction vector.

Unfortunately I don't really know of any good math libraries compatible with OpenGL, but I'm sure someone here or in the GL forum could recommend one.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.