Xna绕世界轴旋转
本文关键字:旋转 世界 Xna | 更新日期: 2023-09-27 18:25:10
我想让俯仰偏航或滚转绕世界轴旋转,而不是绕局部轴旋转,但我不确定如何,我已经做到了。
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);
更新每一帧,然后我就有了。
view_matrix = Matrix.Invert(Matrix.CreateFromQuaternion(camera_angles) * Matrix.CreateTranslation(camera_position));
projection_matrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 500f);
对于一个简单的答案,对"camera_position"执行与对"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));