我的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);
}
我試過了,但它似乎仍然圍繞左上角旋轉。也許我是誤解;我可以看到代碼片段嗎? –