简体   繁体   English

Xna绕世界轴旋转?

[英]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' 对于简单的答案,请对“ camera_positions”执行与对“ 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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