public void Update(Camera camera) { Vector3 Translation = Vector3.Zero; keyState = Keyboard.GetState(); mouseState = Mouse.GetState(); float zoom = 0f; if (KeyboardControlled) { if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.A)) { Translation.X -= 0.2f; } if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.D)) { Translation.X += 0.2f; } if (keyState.IsKeyDown(Keys.PageUp) || keyState.IsKeyDown(Keys.X)) { Translation.Y += 0.2f; } if (keyState.IsKeyDown(Keys.PageDown) || keyState.IsKeyDown(Keys.Z)) { Translation.Y -= 0.2f; } if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.W)) { Translation.Z -= 0.2f; } if (keyState.IsKeyDown(Keys.Down) || keyState.IsKeyDown(Keys.S)) { Translation.Z += 0.2f; } } if (MouseControlled) { if (mouseState.MiddleButton == ButtonState.Pressed && (keyState.IsKeyDown(Keys.RightControl) || keyState.IsKeyDown(Keys.LeftControl))) { float hRot = (float)(lastMouseLocation.X - mouseState.X) / 180f; float vRot = (float)(lastMouseLocation.Y - mouseState.Y) / 180f; Vector3 rots = new Vector3(hRot, vRot, 0); if (vRot != 0 || hRot != 0) camera.Orbit(rots); } else if (mouseState.MiddleButton == ButtonState.Pressed) { Vector3 Start = new Vector3(lastMouseLocation.X, lastMouseLocation.Y, 0); Vector3 End = new Vector3(mouseState.X, mouseState.Y, 0); if (Start != Vector3.Zero || End != Vector3.Zero) camera.MoveCamera(Start, End); } if (keyState.IsKeyDown(Keys.Add)) { zoom += 1; } if (keyState.IsKeyDown(Keys.Subtract)) { zoom -= 1; } if (keyState.IsKeyDown(Keys.Z)) { camera.LookAt(new Vector3(0, 10, 0)); } if (lastScrollWheelValue != mouseState.ScrollWheelValue) { zoom = (float)(mouseState.ScrollWheelValue - lastScrollWheelValue) / 10f; lastScrollWheelValue = mouseState.ScrollWheelValue; } } camera.ZoomToTarget(zoom); camera.Strafe(Translation); lastMouseLocation = new Point(mouseState.X, mouseState.Y); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. device = graphics.GraphicsDevice; camera = new Camera(device); cameraControls = new CameraControls(); font = Content.Load<SpriteFont>("debug"); myVertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); IntializeEffect(); spriteBatch = new SpriteBatch(GraphicsDevice); cube = new Cube(); // TODO: use this.Content to load your game content here }