/// <summary> /// Load the graphics content. /// </summary> protected override void LoadContent() { //Set up the reference grid and sample camera grid = new SampleGrid(); grid.GridColor = Color.LimeGreen; grid.GridScale = 1.0f; grid.GridSize = 32; grid.LoadGraphicsContent(graphics.GraphicsDevice); camera = new SampleArcBallCamera( SampleArcBallCameraMode.RollConstrained); camera.Distance = 3; //orbit the camera so we're looking down the z=-1 axis //the acr-ball camera is traditionally oriented to look //at the "front" of an object camera.OrbitRight(MathHelper.Pi); //orbit up a bit for perspective camera.OrbitUp(.2f); sampleMeshes = new Model[5]; //load meshes sampleMeshes[0] = Content.Load <Model>("Cube"); sampleMeshes[1] = Content.Load <Model>("SphereHighPoly"); sampleMeshes[2] = Content.Load <Model>("SphereLowPoly"); sampleMeshes[3] = Content.Load <Model>("Cylinder"); sampleMeshes[4] = Content.Load <Model>("Cone"); //Example 1.2 //create the effect objects that correspond to the effect files //that have been imported via the Content Pipeline noLightingEffect = Content.Load <Effect>("FlatShaded"); vertexLightingEffect = Content.Load <Effect>("VertexLighting"); GetEffectParameters(); //Calculate the projection properties first on any //load callback. That way if the window gets resized, //the perspective matrix is updated accordingly float aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height; float fov = MathHelper.PiOver4 * aspectRatio * 3 / 4; projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, .1f, 1000f); //create a default world matrix world = Matrix.Identity; //grid requires a projection matrix to draw correctly grid.ProjectionMatrix = projection; //Set the grid to draw on the x/z plane around the origin grid.WorldMatrix = Matrix.Identity; }
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))) { //toggle the advanced effect enableAdvancedEffect = !enableAdvancedEffect; GetEffectParameters(); } //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 = world * Matrix.CreateFromAxisAngle(camera.Up, elapsedTime * dx); } if (dy != 0) { world = world * Matrix.CreateFromAxisAngle(camera.Right, elapsedTime * -dy); } }