Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make it so that either the pitch yaw or roll rotates around the world axis and not the local axis, but I'm not sure how, I've got.

Vector2 mouse_change = new Vector2(mouse_previous.X - mouse_new.X, mouse_previous.Y - mouse_new.Y);
camera_angles *= Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), mouse_change.X / 800f);
camera_angles *= Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), mouse_change.Y / 800f);

Updating every frame, then I've got.

view_matrix = Matrix.Invert(Matrix.CreateFromQuaternion(camera_angles) * Matrix.CreateTranslation(camera_position));
projection_matrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 500f);

The problem is that if I e.g. change the pitch then change the yaw then the yaw changes through the local axis, I need it to turn around the world axis so that it doesn't matter what the yaw is :/.

share|improve this question
up vote 2 down vote accepted

You should try function Quaterion.CreateFromYawPitchRoll. It should create the correct quaterion.

Or if you are using this only for view matrix, you may want also try Matrix.CreateFromYawPitchRoll.

share|improve this answer
No they both do the same thing... – jacker Feb 21 '12 at 15:02
I fixed it, kind of stupid that I didn't do this in the first place. I just made a vector3 for my angles and then added the angles to that and then calculated the quaternion from that, come to think of it I think that may be what you where suggesting :/. Thanks for the help :). – jacker Feb 21 '12 at 15:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.