/// <summary> /// Provides input to camera /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Input(GameTime gameTime, InputManager input) { if (!active) return; float movementFactor = (float)gameTime.ElapsedGameTime.TotalSeconds; //Rotate camera angles.Y -= input.CurrentGamePadStates[0].ThumbSticks.Right.X * movementFactor * 1f; angles.X += input.CurrentGamePadStates[0].ThumbSticks.Right.Y * movementFactor * 1f; Matrix cameraRotation = Matrix.CreateRotationX(angles.X) * Matrix.CreateRotationY(angles.Y); //Drag camera look at if (input.Mouse_WasButtonPressed(MouseButton.Right)) { input.MouseFrozen = true; Engine.IsMouseVisible = false; } else if (input.Mouse_IsButtonDown(MouseButton.Right)) { angles.X -= movementFactor * 0.05f * input.MouseMovement.Y; } else if (input.Mouse_WasButtonReleased(MouseButton.Right)) { input.MouseFrozen = false; Engine.IsMouseVisible = true; } //Constraints angles.X = MathHelper.Clamp(angles.X, .4f, 1f); angles.Y = MathHelper.WrapAngle(angles.Y); }
internal void ExecuteMouseEvents(GameTime gameTime, InputManager input) { //TODO //don't do anything if mouse is outside window bounds //Björn //TODO //check if the mouse is over any 2D (HUD) elements first d3(gameTime, input); }
public void DefaultWhileMouseOver(GameTime gameTime, InputManager input, RigidBody hitBody, Ray hitNormalRay, float hitFraction) { if (hitBody != mouseOver3D) { if (hitBody.Tag is IMouseEvent3D) { ((IMouseEvent3D)hitBody.Tag).OnMouseOver(); } if (mouseOver3D != null && mouseOver3D.Tag is IMouseEvent3D) { ((IMouseEvent3D)mouseOver3D.Tag).OnMouseOut(); } } }
/// <summary> /// Provides input to camera /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Input(GameTime gameTime, InputManager input) { if (!active) return; float movementFactor = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector3 moveVector = new Vector3(); moveEnabled ^= input.Keyboard_WasKeyPressed(Keys.Q); if (moveEnabled) { //Move camera if (input.Keyboard_IsKeyDown(Keys.D) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.DPadRight)) moveVector.X += 1f; if (input.Keyboard_IsKeyDown(Keys.A) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.DPadLeft)) moveVector.X -= 1f; if (input.Keyboard_IsKeyDown(Keys.S) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.DPadDown)) moveVector.Z += 1f; if (input.Keyboard_IsKeyDown(Keys.W) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.DPadUp)) moveVector.Z -= 1f; if (moveVector.Length() > 0) { moveVector.Normalize(); moveVector *= MOVE_SPEED * movementFactor; } } //Rotate camera angles.Y -= input.CurrentGamePadStates[0].ThumbSticks.Right.X * movementFactor * 1f; angles.X += input.CurrentGamePadStates[0].ThumbSticks.Right.Y * movementFactor * 1f; Matrix cameraRotation = Matrix.CreateRotationX(angles.X) * Matrix.CreateRotationY(angles.Y); position += Vector3.Transform(moveVector, cameraRotation); //Drag camera look at if (input.Mouse_WasButtonPressed(MouseButton.Right)) { input.MouseFrozen = true; Engine.IsMouseVisible = false; } else if (input.Mouse_IsButtonDown(MouseButton.Right)) { angles.Y -= movementFactor * 0.05f * input.MouseMovement.X; angles.X -= movementFactor * 0.05f * input.MouseMovement.Y; } else if (input.Mouse_WasButtonReleased(MouseButton.Right)) { input.MouseFrozen = false; Engine.IsMouseVisible = true; } //Constraints angles.X = MathHelper.Clamp(angles.X, -1.4f, 1.4f); angles.Y = MathHelper.WrapAngle(angles.Y); }
private void d3(GameTime gameTime, InputManager input) { Ray mouseRay = input.MouseRay; if (mouseRay != null) //TODO: is this check really needed? //Björn { JVector rayOrigin = mouseRay.Position.ToJitterVector(); JVector rayDirection = mouseRay.Direction.ToJitterVector(); RigidBody hitBody; JVector hitNormal; float hitFraction; bool result = Engine.Physics.CollisionSystem.Raycast(rayOrigin, rayDirection, null, out hitBody, out hitNormal, out hitFraction); if (result && WhileMouseOver != null) { Ray hitNormalRay; hitNormalRay.Direction = hitNormal.ToXNAVector(); hitNormalRay.Position = mouseRay.Position + mouseRay.Direction * hitFraction; WhileMouseOver(gameTime, input, hitBody, hitNormalRay, hitFraction); } mouseOver3D = hitBody; } }
public void Input(GameTime gameTime, InputManager input) { if (input.Keyboard_IsKeyDown(Keys.D9) && gameState != GameState.Editing) { gameState = GameState.Editing; debugCamera.Position = playerCamera.Position + Vector3.Up; //+Vector3.Up only so you notice you've changed camera mode debugCamera.Target = playerCamera.Player.Position; Engine.Camera = debugCamera; mapEditor.Active = true; } if (input.Keyboard_IsKeyDown(Keys.D8) && gameState != GameState.Playing) { gameState = GameState.Playing; Engine.Camera = playerCamera; mapEditor.Active = false; } if (input.Keyboard_WasKeyReleased(Keys.Escape)) { Engine.Exit(); } }
public void whileMouseOver(GameTime gameTime, InputManager input, RigidBody _hitBody, Ray _hitNormal, float _hitDistance) { mouseOverRanSinceLastLeftMousePress = true; bool leftPressed = input.Mouse_WasButtonPressed(MouseButton.Left) && !input.Mouse_IsButtonDown(MouseButton.Right); bool rightPressed = input.Mouse_WasButtonPressed(MouseButton.Right) && !input.Mouse_IsButtonDown(MouseButton.Left); if (leftPressed || rightPressed) { bool shiftDown = input.Keyboard_IsKeyDown(Keys.LeftShift); bool ctrlDown = input.Keyboard_IsKeyDown(Keys.LeftControl); bool altDown = input.Keyboard_IsKeyDown(Keys.LeftAlt); Paused = true; //must be done before much, if not everything, else if (leftPressed) { if (ctrlDown) //expand (or reduce) selection { moveMode = MoveMode.None; selected.toggleSelection(_hitBody); return; } else { moveMode = MoveMode.CameraRelative; } } else //rightPressed { if (shiftDown) { moveMode = MoveMode.LineRelative; } else { moveMode = MoveMode.PlaneRelative; } } if (!selected.Contains(_hitBody)) { selected.Clear(); } selected.Add(_hitBody); if (altDown) //copy and move { //if (ctrlDown) //{ // selectedButNotMoving = selected; //} selected = selected.copy(true); startStateChange(null); } else //just move { startStateChange(selected); } moveOffset = _hitNormal.Position - selected.Position; switch (moveMode) { case MoveMode.CameraRelative: hitDistance = _hitDistance; break; case MoveMode.LineRelative: hitNormal = _hitNormal; break; case MoveMode.PlaneRelative: plane = new MyPlane(_hitNormal); break; } } }
public void Input(GameTime gameTime, InputManager input) { if (!Active) return; if (input.Keyboard_WasKeyPressed(Keys.S) && input.Keyboard_IsKeyDown(Keys.LeftControl)) { StorageManager.Save(Engine.Map); } if (input.Keyboard_WasKeyPressed(Keys.O) && input.Keyboard_IsKeyDown(Keys.LeftControl)) { startStateChange(null); Map newMap = StorageManager.Load(Engine); Engine.Map = newMap; finishStateChange(newMap.Bodies); } if (input.Keyboard_WasKeyPressed(Keys.Space)) { Paused = !Paused; } if (input.Keyboard_WasKeyPressed(Keys.Delete)) { startStateChange(selected); finishStateChange(null); selected.Clear(); selected.Active = false; } if (input.Mouse_WasButtonPressed(MouseButton.Left)) { mouseOverRanSinceLastLeftMousePress = false; } if (!mouseOverRanSinceLastLeftMousePress && input.Mouse_WasButtonReleased(MouseButton.Left)) { mouseOverRanSinceLastLeftMousePress = true; selected.Clear(); } bool shift = input.Keyboard_IsKeyDown(Keys.LeftShift); bool ctrl = input.Keyboard_IsKeyDown(Keys.LeftControl); bool keyZ = input.Keyboard_WasKeyPressed(Keys.Z); bool keyY = input.Keyboard_WasKeyPressed(Keys.Y); if (ctrl) { if (keyY || keyZ && shift) redo(); else if (keyZ) undo(); if (input.Keyboard_WasKeyPressed(Keys.C)) { //copy, don't set :: moveMode = MoveMode.None; } if (input.Keyboard_WasKeyPressed(Keys.Delete)) { moveMode = MoveMode.None; } if (input.Keyboard_WasKeyPressed(Keys.V)) { //paste, don't set :: moveMode = MoveMode.None; } } if (moveMode == MoveMode.None) return; //if mouse buttons were released if (input.Mouse_WasButtonReleased(MouseButton.Left) && !input.Mouse_IsButtonDown(MouseButton.Right) || input.Mouse_WasButtonReleased(MouseButton.Right) && !input.Mouse_IsButtonDown(MouseButton.Left)) { finishStateChange(selected); return; } //Update the body's position switch (moveMode) { case MoveMode.CameraRelative: hitDistance += input.MouseScroll * 0.02f; selected.Position = input.MouseRay.Position - moveOffset + input.MouseRay.Direction * hitDistance; break; case MoveMode.LineRelative: //The point on hitNormal closest to the mouseRay //Guard against parallel or almost paralell lines. if (Vector3.Dot(Vector3.Normalize(input.MouseRay.Direction), Vector3.Normalize(hitNormal.Direction)) > 0.99f) { break; } Vector3 between = input.MouseRay.Position - hitNormal.Position; Vector3 normal = Vector3.Cross(input.MouseRay.Direction, hitNormal.Direction); Vector3 R = Vector3.Divide(Vector3.Cross(between, normal), normal.LengthSquared()); Vector3 P = hitNormal.Position + hitNormal.Direction * Vector3.Dot(R, input.MouseRay.Direction); selected.Position = P - moveOffset; break; case MoveMode.PlaneRelative: float? _mouseRayPlaneIntersectionDistance = input.MouseRay.Intersects(plane.Plane); if (!_mouseRayPlaneIntersectionDistance.HasValue || _mouseRayPlaneIntersectionDistance.Value > 500) { _mouseRayPlaneIntersectionDistance = 500; } float mouseRayPlaneIntersectionDistance = (float)_mouseRayPlaneIntersectionDistance; selected.Position = input.MouseRay.Position - moveOffset + input.MouseRay.Direction * mouseRayPlaneIntersectionDistance; break; } }
public void Input(GameTime gameTime, InputManager input) { InputList.ForEach(e => e.Input(gameTime, input)); }