Exemplo n.º 1
0
        }//eom

        #endregion

        #region Game Methods
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth  = WindowWidth;
            graphics.PreferredBackBufferHeight = WindowHeight;
            graphics.ApplyChanges();
            //Setup Camera
            camTarget        = new Vector3(0f, 0f, 0f);
            camPosition      = new Vector3(100f, 100f, 100f);
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(60f),
                GraphicsDevice.Viewport.AspectRatio, 1f, 200f);
            viewMatrix                     = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);// Y up
            worldMatrix                    = Matrix.CreateWorld(camTarget, Vector3.Forward, Vector3.Up);
            gameState                      = GameState.Initialize;
            transformToggle                = TransformToggle.Shift;
            threeDObject                   = new ThreeDObject(camTarget, new Vector3(shiftX, shiftY, shiftZ), new Vector3(scaleX, scaleY, scaleZ));
            basicEffect                    = new BasicEffect(GraphicsDevice);
            basicEffect.View               = viewMatrix;
            basicEffect.Projection         = projectionMatrix;
            basicEffect.VertexColorEnabled = true;
            SetVertices();
            SetPoitiveGrid();
            SetNegativeGrid();
            base.Initialize();
        }//eom
Exemplo n.º 2
0
        }//eom

        protected override void Update(GameTime gameTime)
        {
            InputKeyManager.Triggers currentKeys = InputKeyManager.Read();
            switch (gameState)
            {
            case GameState.Initialize:
                // initialize - set drawingState to Drawing
                #region User input to change shift and scale
                if ((currentKeys & InputKeyManager.Triggers.UpArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftY += 1.0f;
                    }    //end if
                    else
                    {
                        scaleY += 1.0f;
                        if (scaleY == 0)
                        {
                            scaleY = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.DownArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftY -= 1.0f;
                    }    //end if
                    else
                    {
                        scaleY -= 1.0f;
                        if (scaleY == 0)
                        {
                            scaleY = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.Minus) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftZ -= 1.0f;
                    }    //end if
                    else
                    {
                        scaleZ -= 1.0f;
                        if (scaleZ == 0)
                        {
                            scaleZ = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.LeftArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftX -= 1.0f;
                    }    //end if
                    else
                    {
                        scaleX -= 1.0f;
                        if (scaleX == 0)
                        {
                            scaleX = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.RightArrow) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftX += 1.0f;
                    }    //end if
                    else
                    {
                        scaleX += 1.0f;
                        if (scaleX == 0)
                        {
                            scaleX = 1;
                        }
                    } //end else
                }     //end if

                if ((currentKeys & InputKeyManager.Triggers.Plus) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        shiftZ += 1.0f;
                    }    //end if
                    else
                    {
                        scaleZ += 1.0f;
                        //if (scaleZ == 0)
                        //    scaleZ = 1;
                    } //end else
                }     //end if
                #endregion

                if ((currentKeys & InputKeyManager.Triggers.Toggle) != 0)
                {
                    if (transformToggle == TransformToggle.Shift)
                    {
                        transformToggle = TransformToggle.Scale;
                    }    //end if
                    else
                    {
                        transformToggle = TransformToggle.Shift;
                    } //end else
                }     //end if

                // press spacebar to start the game
                if ((currentKeys & InputKeyManager.Triggers.Fire) != 0)
                {
                    threeDObject.Scale = new Vector3(scaleX, scaleY, scaleZ);
                    threeDObject.Shift = new Vector3(shiftX, shiftY, shiftZ);
                    gameState          = GameState.Drawing;
                }    //end if

                if ((currentKeys & InputKeyManager.Triggers.Reset) != 0)
                {
                    gameState = GameState.Reset;
                }    //end if

                #region Move Camera
                if ((currentKeys & InputKeyManager.Triggers.CamLeft) != 0)
                {
                    camPosition.X -= 5.0f;
                }    //end if
                if ((currentKeys & InputKeyManager.Triggers.CamRight) != 0)
                {
                    camPosition.X += 5.0f;
                }    //end if
                if ((currentKeys & InputKeyManager.Triggers.CamUp) != 0)
                {
                    camPosition.Y += 5.0f;
                }    //end if
                if ((currentKeys & InputKeyManager.Triggers.CamDown) != 0)
                {
                    camPosition.Y -= 5.0f;
                }    //end if

                viewMatrix       = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);
                basicEffect.View = viewMatrix;
                #endregion


                if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0)
                {
                    gameState = GameState.Quit;
                }    //end if
                break;

            case GameState.Drawing:
                // draw objects
                // user input to transform the twoDObject
                threeDObject.Update(gameTime);
                SetVertices();
                // pause
                gameState = GameState.Initialize;
                // reset
                if ((currentKeys & InputKeyManager.Triggers.ExitLevel) != 0)
                {
                    gameState = GameState.Reset;
                }    //end if
                break;

            case GameState.Reset:
                shiftX       = 0;
                shiftY       = 0;
                shiftZ       = 0;
                scaleX       = 1;
                scaleY       = 1;
                scaleZ       = 1;
                threeDObject = new ThreeDObject(camTarget, new Vector3(shiftX, shiftY, shiftZ), new Vector3(scaleX, scaleY, scaleZ));
                threeDObject.LoadContent(Content);

                transformToggle = TransformToggle.Shift;
                SetVertices();

                //rest camera and view
                camPosition      = new Vector3(100f, 100f, 100f);
                basicEffect.View = viewMatrix;

                if ((currentKeys & InputKeyManager.Triggers.Quit) != 0)
                {
                    gameState = GameState.Quit;
                }    //end if

                if ((currentKeys & InputKeyManager.Triggers.Reset) != 0)
                {
                    gameState = GameState.Initialize;
                }    //end if
                break;

            case GameState.Quit:
                // finished - exit
                this.Exit();
                break;
            } //end switch
            base.Update(gameTime);
        }     //eom