简体   繁体   中英

Xna rotate around world axis?

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);

For a simple answer, do to 'camera_position' the same rotation you are doing to the 'camera_angles'

//Add these operations
camera_position = Vector3.Transform(camera_position, Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), mouse_change.X / 800f));

camera_position = Vector3.Transform(camera_position, Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), mouse_change.Y / 800f));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM