# first person camera rotation order and slerp

This topic is 3027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

[if you rotate your head 90 degrees to the right then 90 degrees up your ears are still level, but if you rotate your head 90 degrees up then 90 degrees right your left ear is pointing up and your right ear is pointing down... the z axis has rolled] when implementing a first person camera, one must rotate about the y axis before rotating about the x axis in order to preserve or constrain rotation of the z axis? http://www.gamedev.net/reference/programming/features/quatcam/ i created a camera similar to this and it works fine initially
_orientation = _targetOrientation;
but when i slerp there i get some z axis roll...
_orientation = Quaternion.Slerp(_orientation, _targetOrientation, (float)time);
someone else describes a similar problem here http://www.ogre3d.org/forums/viewtopic.php?f=2&t=50618 can anyone help please? how can i constrain z through slerp? i have to do two slerps? or its as easy as changing the order of operations inside a slerp code? like do y before x as above? http://opentk.svn.sourceforge.net/viewvc/opentk/trunk/Source/OpenTK/Math/Quaternion.cs?view=markup thanks a lot

##### Share on other sites
For something like this I might just interpolate the Euler angles. Since presumably you'll be clamping your angles to reasonable ways that a neck can bend, it's not like you'll run into singularities ("gimbal lock").

Either that, or just construct your rotation matrices directly from your "look-at" vector, the up vector, and their cross product.

##### Share on other sites
Quote:
 Original post by rakkaragewhen implementing a first person camera, one must rotate about the y axis before rotating about the x axis in order to preserve or constrain rotation of the z axis?

for my FPS camera, my order of rotation is Y, X, then Z.

This post prompted me to do some reading, and it seems to me that the need for quaternions may arise with more complicated physics where something can bounce off something else, and fly off in a random direction, where the order of rotations may not always be the same...right? correct me if Im wrong..

##### Share on other sites
Quote:
 This post prompted me to do some reading, and it seems to me that the need for quaternions may arise with more complicated physics where something can bounce off something else, and fly off in a random direction, where the order of rotations may not always be the same...right?
No, not really. It is true that Euler angles aren't a particularly good choice for the type of simulation you describe; however, it's not quaternions per se that are the solution to this problem, but rather arbitrary incremental rotations (which you can achieve using a variety of representations, including quaternions, matrices, and vectors).

##### Share on other sites
Quote:
 Original post by CPPNickfor my FPS camera, my order of rotation is Y, X, then Z.

which agrees with what i said right? you must do y before x... if you change order to x, y, z you will get unintended z axis roll. so how can i constrain the same way during a slerp? thank you

##### Share on other sites
I'm just learning about all this myself..I just got my first project together, where you are standing in a room with one point light, where you can strafe with the keyboard and look with the mouse..I didn't realize how jerky the mouse look was until I moved the mouse really slow and then compared the result with COD4, which was perfectly smooth...So I think I know what you mean now, and I'm looking into it to. I'll let you know what I find.

EDIT: also, on the last page of his quatcam tutorial, he says that he may do a tutorial about SLERP..

maybe you should just ask him:

Robert Crossland
xg0blin@yahoo.com (this email adress is from 2003, but you never know..lol)

EDIT: found this too: http://www.dhpoware.com/demos/index.html
it has some examples of quat cams with source and all

[Edited by - CPPNick on November 8, 2009 11:24:26 PM]