Sign in to follow this  
RichardS

Avoiding introducing roll while changing pitch & yaw with quaternions

Recommended Posts

I just got my basic quaternion camera almost working, except that some motions introduce undesired roll to the view. Specfically, if I move the view in a circle around it's original direction, the view rolls clockwise (contents roll counter-clockwise). Does anyone know what might be introducing this issue, and how I may be able to resolve it? As a worst case solution, I can entirely disallow roll, and remove it in a post-processing step, but I would like to preserve the ability to do a deliberate roll if at all possible. The relevant bit of code:
quaternionf input;
	
input = quaternionf::axisAngleToQuaternion(vector3f(1.0f, 0.0f, 0.0f), -dy);
orientation = orientation.multiply(input);
	
input = quaternionf::axisAngleToQuaternion(vector3f(0.0f, 1.0f, 0.0f), -dx);
orientation = orientation.multiply(input);

Share this post


Link to post
Share on other sites
That's how rotations work. Roll accumulates if you just rotate around the two main world-space axes. You have to rotate around the quaternion-local axes to avoid that.

A better way to do a camera is to keep the values in a space where you know what they mean (such as pitch and yaw), and converting to quaternion each step. When the player inputs "rotate right" then you just add to the yaw.

Share this post


Link to post
Share on other sites
Again, for reference, the final working bit, which emulates the behavior of a FPS view.

dx and dy are scaled mouse position deltas.


quaternionf inputx, inputy;

inputx = quatf_from_axisangle(vector3f(1.0f, 0.0f, 0.0f), -dy);
inputy = quatf_from_axisangle(vector3f(0.0f, 1.0f, 0.0f), -dx);

orientation = quatf_multiply(quatf_multiply(inputy, orientation), inputx);


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this