/******************************************************************************************* * Update model state * *****************************************************************************************/ public void Update(KeyboardState keyBoardState, Camera camera, Ground ground) { GroundHit(); // update camera camera.Update(shipWorld); //Rotate ship along world Up Vector if (keyBoardState.IsKeyDown(Keys.Left)) { shipRotationGlobal = Matrix.CreateRotationY(.02f) * shipRotationGlobal; if (shipRotationLocal.Up.X > tiltLimitLeft) { shipRotationLocal = Matrix.CreateRotationZ(.02f) * shipRotationLocal; } } if (keyBoardState.IsKeyUp(Keys.Left)) { if (shipRotationLocal.Up.X < tiltLimitMiddle) { shipRotationLocal = Matrix.CreateRotationZ(-.02f) * shipRotationLocal; } } //Rotate ship along world Up Vector if (keyBoardState.IsKeyDown(Keys.Right)) { shipRotationGlobal = Matrix.CreateRotationY(-.02f) * shipRotationGlobal; if (shipRotationLocal.Up.X < tiltLimitRight) { shipRotationLocal = Matrix.CreateRotationZ(-.02f) * shipRotationLocal; } } if (keyBoardState.IsKeyUp(Keys.Right)) { if (shipRotationLocal.Up.X > tiltLimitMiddle) { shipRotationLocal = Matrix.CreateRotationZ(.02f) * shipRotationLocal; } } //Rotate ship along its Right Vector if (keyBoardState.IsKeyDown(Keys.Down)) { if (shipRotationLocal.Up.Z < tiltLimitUp) { shipRotationLocal = Matrix.CreateRotationX(.02f) * shipRotationLocal; } } if (keyBoardState.IsKeyDown(Keys.Up)) { if (shipRotationLocal.Up.Z > tiltLimitDown) { shipRotationLocal = Matrix.CreateRotationX(-.02f) * shipRotationLocal; } } shipWorld = shipRotationLocal * shipRotationGlobal; //Move ship Forward, Back, Left, and Right if (keyBoardState.IsKeyDown(Keys.A)) { shipTranslation *= Matrix.CreateTranslation(shipWorld.Forward); //Console.WriteLine(shipTranslation.Translation.Y.ToString()); } if (keyBoardState.IsKeyDown(Keys.Z)) { shipTranslation *= Matrix.CreateTranslation(shipWorld.Backward); } if (keyBoardState.IsKeyDown(Keys.Q)) { shipTranslation *= Matrix.CreateTranslation(-shipWorld.Right); } if (keyBoardState.IsKeyDown(Keys.W)) { shipTranslation *= Matrix.CreateTranslation(shipWorld.Right); } shipWorld = shipWorld * shipTranslation; }
protected override void Initialize() { // initialize objects spaceship = new SpaceShip(); ground = new Ground(); base.Initialize(); }