Basic Object Movement
From XNAWiki
This is a simple class which you can use to move objects in your world, easily, based on their rotation. The float values "amount" for each one, are simply how much or rotation you want, and can be passed in from controller, mouse, keyboard, or time. You'd simply have to give the Entity class a model to see this in action.
public class Entity
{
Vector3 position = Vector3.Zero;
Matrix rotation = Matrix.Identity;
public void Yaw(float amount)
{
this.rotation *= Matrix.CreateFromAxisAngle(this.rotation.Up, amount);
}
public void YawAroundWorldUp(float amount)
{
this.rotation *= Matrix.CreateRotationY(amount);
}
public void Pitch(float amount)
{
this.rotation *= Matrix.CreateFromAxisAngle(this.rotation.Right, amount);
}
public void Roll(float amount)
{
this.rotation *= Matrix.CreateFromAxisAngle(this.rotation.Forward, amount);
}
public void Strafe(float amount)
{
this.position += this.rotation.Right * amount;
}
public void Walk(float amount)
{
this.position += this.rotation.Forward * amount;
}
public void Jump(float amount)
{
this.position += this.rotation.Up * amount;
}
public void Rise(float amount)
{
this.position += Vector3.Up * amount;
}
}