1
我正在嘗試製作一個簡單的等距遊戲引擎,但是有一些相機問題。當我擁有它時,我可以從前面看到我的模型。但我想從等軸測角度看它。我嘗試了很多方法,但似乎沒有任何工作。也許我陷入了代碼本身?你們可以幫我解碼嗎?XNA C#用3D模型創建等軸測視圖
public class Camera : PositionedObject
{
#region Fields
private Matrix cameraRotation;
#endregion
#region Properties
public Matrix View
{
get;
set;
}
public Matrix Projection
{
get;
protected set;
}
public Vector3 Target
{
get;
set;
}
#endregion
#region Constructor
public Camera(Game game, Vector3 position, Vector3 target, Vector3 rotation, bool Orthographic, float near, float far)
: base(game)
{
Position = position;
RotationInRadians = rotation;
Target = target;
if (Orthographic)
{
Projection = Matrix.CreateOrthographic(Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height,
near, far);
}
else
{
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
(float)Game.Window.ClientBounds.Width/(float)Game.Window.ClientBounds.Height, near, far);
}
}
#endregion
#region Public Methods
public override void Initialize()
{
base.Initialize();
cameraRotation = Matrix.Identity;
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
cameraRotation = Matrix.CreateFromAxisAngle(cameraRotation.Forward, RotationInRadians.Z)
* Matrix.CreateFromAxisAngle(cameraRotation.Right, RotationInRadians.X)
* Matrix.CreateFromAxisAngle(cameraRotation.Up, RotationInRadians.Y);
Target = Position + cameraRotation.Forward;
View = Matrix.CreateLookAt(Position, Target, cameraRotation.Up);
}
public void Draw(BasicEffect effect)
{
effect.View = View;
effect.Projection = Projection;
}
#endregion
}
謝謝,真的幫了我很多。我現在確實得到了很好的等距視圖。我現在唯一面臨的問題是它始終專注於這一點,所以如果我移動相機,它不會像遊戲機相機那樣移動。可能是因爲我太靠近焦點了。我是否應該將所有物體和相機從焦點處移回來,或者有辦法始終讓它看起來處於某個角度,並在移動相機時真正創建等軸測視圖?或者當然,我應該移動所有的物體而不是相機。這種情況下最好的選擇是什麼?謝謝你的好回答! – Worempie 2013-02-22 20:57:48
當你想移動你的相機時,你只需「移動」FocusPoint,相機將繼續保持相對於該位置的正確位置和方向:) – 2013-02-25 07:51:49
固定:D非常感謝! – Worempie 2013-03-10 10:30:30