コード例 #1
0
ファイル: Obstacle.cs プロジェクト: vladinooo/SpaceMission
        /*******************************************************************************************
        * Draw model in its world
        * *****************************************************************************************/
        public void Draw(Camera camera)
        {
            Matrix[] modelTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = modelTransforms[mesh.ParentBone.Index] * obstcleWorld;
                    effect.View = camera.viewMatrix;
                    effect.Projection = camera.projectionMatrix;
                }
                mesh.Draw();
            }
        }
コード例 #2
0
ファイル: SpaceShip.cs プロジェクト: vladinooo/SpaceMission
        /*******************************************************************************************
        * 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;
        }