Quaternion camera issue

Started by
5 comments, last by Wilhelm van Huyssteen 15 years, 3 months ago
hey. couple days back i posted on the same thing and i thought i got it working but i was wrong. i have a first person Quaternion camera that works with my mouse. when i pitch it works fine, when i yaw it works fine, but when i pitch and yaw it starts to roll as wel and it looks pretty messed up. what could possible cuase this and how can i go about fixing it? thnx
Advertisement
What you're describing is actually normal, if you think about the individual motions you are making with your mouse.

For example, lets say you pitch up, then yaw left. You pitch up, and your camera is now pointed along an upward vector. Now you yaw to the left. Instead of yawing along the ground plane (as you seem to be expecting it to), it rotates left along the upward-pitched angle created by the initial pitch movement. The end result is the camera view appears to slide downward at an angle.

If you draw it out you'll see how this is functioning exactly right. And if you continue to yaw and pitch in repeated motions, the camera will appear to slowly roll all the way around as each rotation is added to each previous rotation.

The only way to "prevent" this, to create a FPS-style camera which always remains level to the ground, is to clamp the yaw so that it is applied relative to the ground plane, rather than relative to the current camera angle.
thnx for clearing that up for me

i understand what u mean. could you maybe point me to a article or tutorial that might help me implement this FPS style camera? im stil new to quaternions and your words "to clamp the yaw so that it is applied relative to the ground plane, rather than relative to the current camera angle." scares me more than it does anything else :p

[Edited by - EternityZA on January 10, 2009 5:37:47 PM]
Quote:Original post by EternityZA
thnx for clearing that up for me

i understand what u mean. could you maybe point me to a article or tutorial that might help me implement this FPS style camera? im stil new to quaternions and your words "to clamp the yaw so that it is applied relative to the ground plane, rather than relative to the current camera angle." scares me more than it does anything else :p
A good first step would be to ditch the quaternions: they don't offer any benefits to speak of in this context, and in fact are probably just getting in the way.

As has already been pointed out, you want to think of yaw as being relative to a fixed up vector, and pitch as being relative to a local side vector.

The easiest way to accomplish this is probably to use an Euler-angle pair (yaw and pitch). The rotations should be combined in the order pitch->yaw (whether that translates to yaw*pitch or pitch*yaw in matrix terms depends on whether you're using row- or column-vector notation).

Each update, adjust the yaw and pitch based on mouse input. Then, build an Euler-angle rotation matrix from scratch using the current yaw and pitch.

I'll leave it at that for now, but post back if you have further questions.
thnx for the reply

That is how I was doing it till recently.

in the past week or 2 ive been rewriting pieces of my engine to move from eular angles to quaternions for the simple reason of being able to implement SLERP (theres also the gimbal lock issue but i gues that doesnt matter for a camera that can only pitch and yaw)

up to now ive interpolated between eular angles and i never realy got my animations 100% smoothed out. In the future i also want to be able to roll the camera when needed. This seems imposible to accomplish using just eular angles (correct me if im wrong). although for now il be happy if i can just smoothly pitch and yaw it.

i guess i can use eular angles for my camera and quaternions for the rest if it can do whats needed.

i dont mind studying quaternions some more if needed since ive been doing so the past 7 days and i got most of it working.

what would you recommend?
I would recommend this:

CameraQuaternion=QuaternionFromAxisAndAngle(0,1,0,yaw)*QuaternionFromAxisAndAngle(1,0,0,pitch);
to convert from Euler angles to camera quaternion.
Quaternions multiply together in same way as rotation matrices; above formula is same as first doing pitch then yaw rotation with glRotate.

Its not so much that you really want euler angles here IMO (considering as you may/will need interpolation), but that you want mouse to work in euler angles.
To convert back in case you ever need it, just calculate camera's forward vector, and from here find pitch and yaw angles (simple trigonometry left as exercise of the reader ;-) )
This way you can have both your euler angle behavior and interpolation.

Note: the axis vector may differ depending to your coordinate system conventions. Use same axises that you use in turns now.
Thnx a lot Dmytry! That solves my problem and my camera now behaves as intended.

This topic is closed to new replies.

Advertisement