camera class design

Started by
2 comments, last by Funkapotamus 17 years, 11 months ago
I want to design a simple camera system using quaternions, and am using OpenGL for the renderer (so at some point for every frame, I'll have to take my quaternion to the equivalent matrix to pass into OpenGL). Quaternions cannot holds position data, so I'll need a position vector. The position vector is easy enough to handle, a function like camera.translate(vector velocity, float time) will work. I am a little unclear how to set up the camera.rotation function. I am going to use mouselook, and my first guess is to take the xy coords, relative to the center of the screen, and use those to calculate rotational velocity about the x and y axes, then integrate time (time per frame) to give a rotational change that is the product of the rotations about the x and y axes. At the end of each frame, i will normalize my quaternion before matrix conversion. Is this plan decent? What can I do to make it better, it "feels" like something is missing? (FYI, I used to program a long time ago, and I am trying to get back into it) Thanks.
Advertisement
Are you wanting to implement a first-person shooter style camera (like in Quake), or a 6DOF 'free' camera, like in a space combat game? Or both?
If [dx,dy] is the movement of the mouse, then the cross-product of that vector with the Z-axis will give you your axis of rotation (after normalizing), and the length of [dx,dy] will give you the amount of rotation (after scaling). Actually, you can skip the cross-product and simply use [dy,dx] as your axis of rotation (after normalizing). That is what the cross-product will give you.

It is easy to convert axis/angle to a quaternion. Pass that quaternion as a parameter to the rotate function.

You may also need to invert the signs of some of the components.

However, I suggest that you use a 4x4 matrix for the camera instead of a quaternion and position. It will make implementation much easier for you. Once you have a good understanding of how cameras work, you can switch to using a quaternion (though once you have a good understanding of cameras, you might prefer using a matrix).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
I posted code from my camera class a while ago. Here's the post:

http://www.gamedev.net/community/forums/topic.asp?topic_id=335056&whichpage=1�

It's basically straight out of Quake's source.

This topic is closed to new replies.

Advertisement