所以我正在制作一款带有相机的游戏,其工作方式与sims 2相机类似。 我想要完成的是一台可以:
但是,左/右部分移动有问题。我会给你我的代码。请注意,在此版本的代码中,我还没有尝试过实现它。
private float worldRotation = 0;
public void RotateAroundFocusPoint(float relativeDegrees)
{
worldRotation += MathHelper.ToRadians(relativeDegrees);
}
public Matrix World, View, Proj;
public Vector3 Position, Focus /*relative*/;
public void Update()
{
World = Matrix.CreateTranslation(-Position - Focus) *
Matrix.CreateRotationY(worldRotation);
View = Matrix.CreateLookAt(-Focus, Vector3.Zero, Vector3.Up);
}
在3D编程方面,我有点像菜鸟,所以我希望你能帮助我!
提前致谢,
安东尼
答案 0 :(得分:0)
所以我自己弄清楚了。这是一种解决方法,但我使用以下方法实现它:
private float worldRotation = 0;
public void RevolveAroundFocusPoint(float relativeDegrees)
{
worldRotation += MathHelper.ToRadians(relativeDegrees);
}
public Vector3 Modified
{
get
{
Vector3 f = Vector3.Transform(Focus, Matrix.Invert(Matrix.CreateRotationY(worldRotation)));
return new Vector3(f.X, Position.Y, f.Z);
}
}
public float Multiplier(float value, Vector3 v3)
{
return value / /*Zoom / */ (Math.Abs(v3.X) + Math.Abs(v3.Z));
}
public void MoveRight(float value)
{
Vector3 f = Modified;
float multiplier = Multiplier(value, f);
Position += new Vector3(f.Z * multiplier, 0, f.X * multiplier);
}
public void MoveLeft(float value)
{
Vector3 f = Modified;
float multiplier = Multiplier(value, f);
Position += new Vector3(-f.Z * multiplier, 0, -f.X * multiplier);
}
public void MoveBackward(float value)
{
Vector3 f = Modified;
float multiplier = Multiplier(value, f);
Position += new Vector3(-f.X * multiplier, 0, f.Z * multiplier);
}
public void MoveForward(float value)
{
Vector3 f = Modified;
float multiplier = Multiplier(value, f);
Position += new Vector3(f.X * multiplier, 0, -f.Z * multiplier);
}
public Matrix World;
public Matrix View;
public Matrix Proj;
public Vector3 Position { get; private set; }
public Vector3 Focus;
public void Update()
{
World = Matrix.CreateTranslation(-Position - Focus) *
Matrix.Invert(Matrix.CreateRotationY(worldRotation)) *
Matrix.CreateScale(Zoom) *
Matrix.CreateTranslation(Position + Focus);
View = Matrix.CreateLookAt(Position, Position + Focus, Vector3.Up);
}