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