コード例 #1
0
        /// <summary>
        /// Initialize the sample.
        /// </summary>
        protected override void Initialize()
        {
            // create a default world and matrix
            world = Matrix.Identity;

            // create the mesh array
            sampleMeshes = new Model[5];

            // Set up the reference grid
            grid           = new SampleGrid();
            grid.GridColor = Color.LimeGreen;
            grid.GridScale = 1.0f;
            grid.GridSize  = 32;
            // Set the grid to draw on the x/z plane around the origin
            grid.WorldMatrix = Matrix.Identity;

            // set up the sample camera
            camera          = new SampleArcBallCamera(SampleArcBallCameraMode.RollConstrained);
            camera.Distance = 3;
            // orbit the camera so we're looking down the z=-1 axis,
            // at the "front" of the object
            camera.OrbitRight(MathHelper.Pi);
            // orbit up a bit for perspective
            camera.OrbitUp(.2f);

            // set the initial effect, technique, and mesh
            activeMesh        = 1;
            activeCombination = 0;
            activeEffect      = effectTechniqueCombinations[activeCombination, 0];
            activeTechnique   = effectTechniqueCombinations[activeCombination, 1];

            // set the initial specular values
            specularPower     = 16;
            specularIntensity = 1;

            base.Initialize();
        }
コード例 #2
0
        private void HandleInput(GameTime gameTime, GamePadState gpState,
                                 KeyboardState kbState)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Handle input for selecting meshes
            if (((gpState.Buttons.X == ButtonState.Pressed) &&
                 (lastGpState.Buttons.X == ButtonState.Released)) ||
                (kbState.IsKeyDown(Keys.Tab) && lastKbState.IsKeyUp(Keys.Tab)))
            {
                //switch the active mesh
                activeMesh = (activeMesh + 1) % sampleMeshes.Length;
            }


            //Handle input for selecting the active effect
            if (((gpState.Buttons.Y == ButtonState.Pressed) &&
                 (lastGpState.Buttons.Y == ButtonState.Released)) ||
                (kbState.IsKeyDown(Keys.Space) && lastKbState.IsKeyUp(Keys.Space)))
            {
                activeCombination = (activeCombination + 1) %
                                    effectTechniqueCombinationCount;
                activeEffect    = effectTechniqueCombinations[activeCombination, 0];
                activeTechnique = effectTechniqueCombinations[activeCombination, 1];
            }


            //handle mesh rotation inputs
            float dx =
                SampleArcBallCamera.ReadKeyboardAxis(kbState, Keys.Left, Keys.Right) +
                gpState.ThumbSticks.Left.X;
            float dy =
                SampleArcBallCamera.ReadKeyboardAxis(kbState, Keys.Down, Keys.Up) +
                gpState.ThumbSticks.Left.Y;

            //apply mesh rotation to world matrix
            if (dx != 0)
            {
                world *= Matrix.CreateFromAxisAngle(camera.Up, elapsedTime * dx);
            }
            if (dy != 0)
            {
                world *= Matrix.CreateFromAxisAngle(camera.Right, elapsedTime * -dy);
            }


            //handle specular power and intensity inputs
            float dPower = SampleArcBallCamera.ReadKeyboardAxis(kbState,
                                                                Keys.Multiply, Keys.Divide);

            if (gpState.DPad.Right == ButtonState.Pressed)
            {
                dPower = 1;
            }
            if (gpState.DPad.Left == ButtonState.Pressed)
            {
                dPower = -1;
            }

            float dIntensity = SampleArcBallCamera.ReadKeyboardAxis(kbState,
                                                                    Keys.Add, Keys.Subtract);

            if (gpState.DPad.Up == ButtonState.Pressed)
            {
                dIntensity = 1;
            }
            if (gpState.DPad.Down == ButtonState.Pressed)
            {
                dIntensity = -1;
            }

            if (dPower != 0)
            {
                specularPower *= 1 + (elapsedTime * dPower);
                specularPower  = MathHelper.Clamp(specularPower,
                                                  specularPowerMinimum, specularPowerMaximum);
            }

            if (dIntensity != 0)
            {
                specularIntensity *= 1 + (elapsedTime * dIntensity);
                specularIntensity  = MathHelper.Clamp(specularIntensity,
                                                      specularIntensityMinimum, specularIntensityMaximum);
            }
        }