我的 XNA 游戏使用 Farseer Physics,这是一个 2d 物理引擎,带有用于物理引擎数据的可选渲染器,以帮助您进行调试。可视化调试数据非常有用,因此我将其设置为根据相机的状态进行绘制。这完美地工作,除了z轴旋转。看,我有一个支持移动、缩放和 z 轴旋转的相机类。我的调试类使用 Farseer 的调试渲染器创建矩阵,使调试数据根据相机绘制,它做得很好,除了一件事.. z 轴旋转使用屏幕的左上角 ( 0, 0),而我的相机使用视口的中心作为 (0, 0) 旋转。有人对我有什么建议吗?如果我可以让调试抽屉从中心旋转,它将与我的相机完美配合。
public void Draw(Camera2D camera, GraphicsDevice graphicsDevice)
{
// Projection (location and zoom)
float width = (1f / camera.Zoom) * ConvertUnits.ToSimUnits(graphicsDevice.Viewport.Width / 2);
float height = (-1f / camera.Zoom) * ConvertUnits.ToSimUnits(graphicsDevice.Viewport.Height / 2);
//projection = Matrix.CreateOrthographic(width, height, 1f, 1000000f);
projection = Matrix.CreateOrthographicOffCenter(
-width,
width,
-height,
height,
0f, 1000000f);
// View (translation and rotation)
float xTranslation = -1 * ConvertUnits.ToSimUnits(camera.Position.X);
float yTranslation = -1 * ConvertUnits.ToSimUnits(camera.Position.Y);
Vector3 translationVector = new Vector3(xTranslation, yTranslation, 0f);
view = Matrix.CreateRotationZ(camera.Rotation) * Matrix.Identity;
view.Translation = translationVector;
DebugViewXNA.RenderDebugData(ref projection, ref view);
}