如何更改目标相机?
目标:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Flight
{
public class FollowCamera : CCamera
{
public Vector3 Target { get; set; }
public FollowCamera(Vector3 Position, Vector3 Target,
GraphicsDevice graphicsDevice)
: base(graphicsDevice)
{
this.Position = Position;
this.Target = Target;
}
public override void Update()
{
//Missing lines of code used to determine
//the up vector
Vector3 forward = Target - Position;
Vector3 right = Vector3.Cross(forward, Vector3.Up);
Vector3 up = Vector3.Cross(right, forward);
this.View = Matrix.CreateLookAt(Position,
Target, up);
}
}
}
我确实有一些线索可以使用这行代码进行一些修改,并添加相机应该在目标后面的距离。这行代码使我的船在屏幕周围,我需要确保相机随船一起移动。请帮忙
this.local = Matrix.CreateFromYawPitchRoll(orientation.Y, orientation.X, orientation.Z) * Matrix.CreateTranslation(position.X, position.Y, position.Z) * this.local;
答案 0 :(得分:0)
您必须将相机连接到船上,计算相机位置和目标位置
interface IPositionable { Vector3 Position }
class FollowCamera{
public IPositionable ObjectToFollow;
public FollowCamera(Vector3 RelativePosition)
{
this.RelativePosition = relativePosition
}
public override void Update()
{
//Missing lines of code used to determine
//the up vector
Vector3 forward = Target - Position;
Vector3 right = Vector3.Cross(forward, Vector3.Up);
Vector3 up = Vector3.Cross(right, forward);
Position = ObjectToFollow.Position - RelativePosition;
Target = ObjectToFollow.Position;
this.View = Matrix.CreateLookAt(Position,
Target, up);
}
}
如果考虑船的前向矢量并使用缓动函数插值此值,则移动可以非常酷和平滑。