Home -> Code Page

Code for ship.cs
class Ship
{
    public Model Model;
    public Matrix[] Transforms;
 
    //Position of the model in world space
    public Vector3 Position = Vector3.Zero;
 
    //Velocity of the model, applied each frame to the model's position
    public Vector3 Velocity = Vector3.Zero;
    //amplifies controller speed input
    private const float VelocityScale = 5.0f;
 
    public bool isActive = true;
 
    public Matrix RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2);
    private float rotation;
    public float Rotation
    {
        get { return rotation; }
        set
        {
            float newVal = value;
            while (newVal >= MathHelper.TwoPi)
            {
                newVal -= MathHelper.TwoPi;
            }
            while (newVal < 0)
            {
                newVal += MathHelper.TwoPi;
            }
 
            if (rotation != value)
            {
                rotation = value;
                RotationMatrix =
                    Matrix.CreateRotationX(MathHelper.PiOver2) *
                    Matrix.CreateRotationZ(rotation);
            }
 
        }
    }
 
    public void Update(GamePadState controllerState)
    {
        // Rotate the model using the left thumbstick, and scale it down.
        if (Math.Abs(controllerState.ThumbSticks.Left.X) > .2) Rotation -= controllerState.ThumbSticks.Left.X * 0.10f;
 
        // Finally, add this vector to our velocity.
        Velocity += RotationMatrix.Forward * VelocityScale *
                    controllerState.Triggers.Right;
    }
}