给您的对象/实体/船一个位置(Vector3)和旋转(矩阵),然后您可以使用以下代码(以及此答案底部的示例)来移动船。
例如将船向前移动 5 个单位:
Entity myShip = new Entity();
myShip.GoForward(5.0f);
让你的船桶滚动 90 度
myShip.Roll(MathHelper.PiOver2);
这是示例代码
public class Entity
{
Vector3 position = Vector3.Zero;
Matrix rotation = Matrix.Identity;
public void Yaw(float amount)
{
rotation *= Matrix.CreateFromAxisAngle(rotation.Up, amount);
}
public void YawAroundWorldUp(float amount)
{
rotation *= Matrix.CreateRotationY(amount);
}
public void Pitch(float amount)
{
rotation *= Matrix.CreateFromAxisAngle(rotation.Right, amount);
}
public void Roll(float amount)
{
rotation *= Matrix.CreateFromAxisAngle(rotation.Forward, amount);
}
public void Strafe(float amount)
{
position += rotation.Right * amount;
}
public void GoForward(float amount)
{
position += rotation.Forward * amount;
}
public void Jump(float amount)
{
position += rotation.Up * amount;
}
public void Rise(float amount)
{
position += Vector3.Up * amount;
}
}