Exemple #1
0
        public MouseContext(Form form)
        {
            mouse = new StratumMouseManager(form);
            mouse.Initialize();

            previousState = mouse.GetState();
            currentState = previousState;
        }
Exemple #2
0
 public static void Update()
 {
     lastWheel = Wheel;
     lastX = X;
     lastY = Y;
     state = Game.Keyboard.GetState();
     mouseState = Game.Mouse.GetState();
 }
Exemple #3
0
        public InputManager(GameApp game)
        {
            _Mouse = new MouseManager(game);
            _MouseState = new MouseState();

            mouseX = 0;
            mouseY = 0;

            game.SetInputUpdater(Update);
            MouseClickEvent += game.onMouseClick;
        }
Exemple #4
0
        // Update the camera based on user input
        public void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState)
        {
            var time = (float)gameTime.TotalGameTime.TotalSeconds;
            var elapsedTime = (float)gameTime.ElapsedGameTime.Milliseconds;

            if (freeCamera)
            {
                // Calculate the yaw and pitch
                float yaw = 0.5f - mouseState.X;
                float pitch = 0.5f - mouseState.Y;

                //// Yaw
                //float yaw = 0;
                //if (keyboardState.IsKeyDown(Keys.Left)) { yaw++; }
                //if (keyboardState.IsKeyDown(Keys.Right)) { yaw--; }
                yaw *= elapsedTime * mouseSensitivity;

                //// Pitch

               // if (keyboardState.IsKeyDown(Keys.Up)) { pitch++; }
               // if (keyboardState.IsKeyDown(Keys.Down)) { pitch--; }
               // pitch *= elapsedTime * mouseSensitivity;

                // Roll with Q and E
                float roll = 0;
                if (keyboardState.IsKeyDown(Keys.Q)) { roll--; }
                if (keyboardState.IsKeyDown(Keys.E)) { roll++; }
                roll *= elapsedTime * rollSpeed;

                // Forward and backward
                if (keyboardState.IsKeyDown(Keys.W)) { MoveCamera(-rotation.Forward, elapsedTime); }
                if (keyboardState.IsKeyDown(Keys.S)) { MoveCamera(-rotation.Backward, elapsedTime); }

                // Strafe
                if (keyboardState.IsKeyDown(Keys.A)) { MoveCamera(rotation.Left, elapsedTime); }
                if (keyboardState.IsKeyDown(Keys.D)) { MoveCamera(rotation.Right, elapsedTime); }

                // Rotate camera
                rotation *= Matrix.RotationAxis(rotation.Left, pitch);
                rotation *= Matrix.RotationAxis(rotation.Forward, roll);
                rotation *= Matrix.RotationAxis(rotation.Down, yaw);
            }
            UpdateViewMatrix();
        }
Exemple #5
0
        protected override void Update(GameTime gameTime)
        {
            keyboardState = keyboardManager.GetState();
            mouseState = mouseManager.GetState();

            // Handle base.Update
            base.Update(gameTime);

            //Update game objects
            lightsource.Update(gameTime);
            model.Update(gameTime, lightsource.getLightDirection());
            water.Update(gameTime, lightsource.getLightDirection());
            camera.Update(gameTime);

            //Enable/disable cursor control of the camera
            if (keyboardState.IsKeyPressed(Keys.Space)){
                if(enableCursor == true){
                    enableCursor = false;
                }
                else{
                    enableCursor = true;
                }
            }

            //Exit the game
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
                this.Dispose();
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        private void UpdateMouse(MouseState state, GameTime gameTime)
        {
            #if (!XBOX && !XBOX_FAKE)

              if ((state.X != mouseState.X) || (state.Y != mouseState.Y))
              {
            MouseEventArgs e = new MouseEventArgs();

            MouseButton btn = MouseButton.None;
            if (state.LeftButton.Down) btn = MouseButton.Left;
            else if (state.RightButton.Down) btn = MouseButton.Right;
            else if (state.MiddleButton.Down) btn = MouseButton.Middle;
            else if (state.XButton1.Down) btn = MouseButton.XButton1;
            else if (state.XButton2.Down) btn = MouseButton.XButton2;

            BuildMouseEvent(state, btn, ref e);
            if (MouseMove != null)
            {
              MouseMove.Invoke(this, e);
            }
              }

              // Mouse wheel position changed
              if (state.WheelDelta != mouseState.WheelDelta)
              {
              MouseEventArgs e = new MouseEventArgs();
              MouseScrollDirection direction = state.WheelDelta < mouseState.WheelDelta ? MouseScrollDirection.Down : MouseScrollDirection.Up;

              BuildMouseEvent(state, MouseButton.None, direction, ref e);

              if (MouseScroll != null)
              {
              MouseScroll.Invoke(this, e);
              }
              }

              UpdateButtons(state, gameTime);

              mouseState = state;

              #endif
        }
Exemple #7
0
 public void Update(GameTime gameTime)
 {
     previousState = currentState;
     currentState = mouse.GetState();
 }
        protected override void Update(GameTime gameTime)
        {
            keyboardState = keyboardManager.GetState();
            mouseState = mouseManager.GetState();
            model.Update(gameTime);
            sun.Update(gameTime);

            // Handle base.Update
            base.Update(gameTime);
        }
Exemple #9
0
        private void Update()
        {
            _MouseState = _Mouse.GetState();

            #region Mouse Position
            mouseX = (int)(_MouseState.X * MetaData.ScreenWidth);
            mouseY = (int)(_MouseState.Y * MetaData.ScreenHeight);
            #endregion

            #region Mouse Buttons
            if (_MouseState.LeftButton.Pressed)
                onMouseClick(EMouseButton.Left);
            if (_MouseState.RightButton.Pressed)
                onMouseClick(EMouseButton.Right);
            #endregion
        }
Exemple #10
0
    /// <summary>
    /// Initializes the user input-related variables
    /// </summary>
    /// <param id="gc"></param>
    public void Initialize(GameWindow gc)
    {
      this.gc = gc;

      mKeyb = new KeyboardManager(gc);
      mKeyb.Initialize();
      mMouse = new MouseManager(gc);
      mMouse.Initialize();

      pKeyb = mKeyb.GetState();
      pMouse = mMouse.GetState();

      nativeWindow = gc.Window.NativeWindow as System.Windows.Forms.Form;

      MouseVector = GetMouseVector();
      prevMouseVector = MouseVector;

      gc.Deactivated += win_Deactivated_handler;
      gc.Activated += win_Activated_handler;
      gc.Window.ClientSizeChanged += win_SizeChanged_handler;
    }
        protected override void Update(GameTime gameTime)
        {
            // read the current mouse state
            mouseState = mouseManager.GetState();

            base.Update(gameTime);
        }
        protected override void Update(GameTime gameTime)
        {
            // to get some input coming from the mouse and keyboard
            keyboardState = keyboardManager.GetState();
            mouseState = mouseManager.GetState();
            model.Update(gameTime);

            camera.Update(gameTime);

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
                this.Dispose();
            }

            // Handle base.Update
            base.Update(gameTime);
        }
        private static void UpdateMouse()
        {
            PointerHandled = false;
            oldMouseState = mouseState;
            mouseState = mouse.GetState();

            oldMousePosition = mousePosition;
            mousePosition.X = mouseState.X * Engine.ScreenSize.X;
            mousePosition.Y = mouseState.Y * Engine.ScreenSize.Y;
            MouseDelta = mousePosition - oldMousePosition;

            if (LockMouseToCenter)
            {
                mouse.SetPosition(new Vector2(0.5f));
                mousePosition.X = 0.5f * Engine.ScreenSize.X;
                mousePosition.Y = 0.5f * Engine.ScreenSize.Y;
            }

            CheckDragClip();
            UpdateMouseButtonStates();

            if (forceMouseRelease && !AnyMouseHeld)
            {
                ResetMouse();
                forceMouseRelease = false;
                return;
            }
        }
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Calculates the world and the view based on the model size
            view = Matrix.LookAtRH(new Vector3(0.0f, 0.0f, 7.0f), new Vector3(0, 0.0f, 0), Vector3.UnitY);
            projection = Matrix.PerspectiveFovRH(0.9f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f);

            // Update basic effect for rendering the Primitive
            basicEffect.View = view;
            basicEffect.Projection = projection;

            // Get the current state of the mouse
            mouseState = mouse.GetState();

            if (mouseState.LeftButton.Pressed)
            {
                scenario = scenario == Scenario.SkipIfUnavailable ? Scenario.StallPipeline : ++scenario;
            }
        }
 //this directly impacts the views based on the user's mouse and key input (AWSDQE and mouse)
 private Matrix UpdateViewMatrix()
 {
     keyboardState = keyboardManager.GetState();
     mouseState = mouseManager.GetState();
     float yawDx = 0.5f - mouseState.X;
     float pitchDy = 0.5f - mouseState.Y;
     yaw -= yawDx * mouseVelocity * gameTime.ElapsedGameTime.Milliseconds;
     pitch += pitchDy * mouseVelocity * gameTime.ElapsedGameTime.Milliseconds;
     if (keyboardState.IsKeyDown(Keys.Q))
     {
         roll += moveVelocity * gameTime.ElapsedGameTime.Milliseconds * .05f;
     }
     if (keyboardState.IsKeyDown(Keys.E))
     {
         roll -= moveVelocity * gameTime.ElapsedGameTime.Milliseconds * .05f;
     }
     Vector3 direction = new Vector3(
         (float)(Math.Cos(pitch) * Math.Sin(yaw)),
         (float)(Math.Sin(pitch)),
         (float)(Math.Cos(pitch) * Math.Cos(yaw)));
     Vector3 horizontalAxis = new Vector3(
         (float)(Math.Sin(yaw + Math.PI / 2f) * Math.Cos(roll)),
         (float)Math.Sin(roll), (float)(Math.Cos(yaw + Math.PI / 2f) * Math.Cos(roll)));
     Vector3 up = Vector3.Cross(direction, horizontalAxis);
     if (keyboardState.IsKeyDown(Keys.A))
     {
         Vector3 eyeChange = eye - moveVelocity * gameTime.ElapsedGameTime.Milliseconds * horizontalAxis;
         if (model.AllowMovement(eyeChange))
         {
         eye = eyeChange;
         }
     }
     if (keyboardState.IsKeyDown(Keys.D))
     {
         Vector3 eyeChange = eye + moveVelocity * gameTime.ElapsedGameTime.Milliseconds * horizontalAxis;
         if (model.AllowMovement(eyeChange))
         {
             eye = eyeChange;
         }
     }
     if (keyboardState.IsKeyDown(Keys.W))
     {
         Vector3 eyeChange = eye + moveVelocity * gameTime.ElapsedGameTime.Milliseconds * direction;
         if (model.AllowMovement(eyeChange))
         {
             eye = eyeChange;
         }
     }
     if (keyboardState.IsKeyDown(Keys.S))
     {
         Vector3 eyeChange = eye - moveVelocity * gameTime.ElapsedGameTime.Milliseconds * direction;
         if (model.AllowMovement(eyeChange))
         {
             eye = eyeChange;
         }
     }
     mouseManager.SetPosition(new Vector2(0.5f, 0.5f));
     return Matrix.LookAtLH(eye, eye + direction, up);
 }
Exemple #16
0
    /// <summary>
    /// Updates the user inputs
    /// </summary>
    /// <param id="gameTime">Time passed since the last call to Update</param>
    public void Update(GameTime gameTime)
    {
      pKeyb = cKeyb;
      pMouse = cMouse;
      cMouse = mMouse.GetState();
      cKeyb = mKeyb.GetState();

      prevMouseVector = MouseVector;
      MouseVector = GetMouseVector();

      if (prevMouseVector != MouseVector)
      {
        MouseStill = 0;
      }
      else
      {
        MouseStill += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
      }

      UpdateNumber++;
    }
        protected override void Update(GameTime gameTime)
        {
            // Update the keyboard and mouse state
            keyboardState = keyboardManager.GetState();
            mouseState = mouseManager.GetState();
            mouseManager.SetPosition(mouseCenter);

            // Quit?
            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Update camera based on the above
            camera.Update(gameTime, keyboardState, mouseState);

            // Finally update models
            model.Update(gameTime, camera);
            sun.Update(gameTime, camera);

            // Handle base.Update
            base.Update(gameTime);
        }
Exemple #18
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            // Calculates the world and the view based on the model size
            view = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, -7.0f), new Vector3(0, 0.0f, 0), Vector3.UnitY);
            projection = Matrix.PerspectiveFovLH(0.9f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f);

            // Update basic effect for rendering the Primitive
            basicEffect.View = view;
            basicEffect.Projection = projection;

            // Get the current state of the keyboard
            keyboardState = keyboard.GetState();

            // Get the current state of the mouse
            mouseState = mouse.GetState();
        }
        protected override void Update(GameTime gameTime)
        {

            TestPause();
            if (paused) {
                inputManager.Update(gameTime);
                return;
            }

            // Get new mouse info
            mouseState = inputManager.MouseState();

            // Update camera
            camera.Update(gameTime);


            // Update the level
            level.Update(gameTime);

            // Reset on escape key
            // if (inputManager.IsKeyDown(Keys.Escape)) restartGame();

            // Handle base.Update
            base.Update(gameTime);
        }
Exemple #20
0
 public void UpdateInputDevices()
 {
     KeyboardState = KeyboardManager.GetState();
     KeyboardState.GetDownKeys(_downKeys);
     MouseState = MouseManager.GetState();
     if(PointerManager!=null)
         PointerState = PointerManager.GetState();
 }
        /// <summary>
        /// Update the state of all desired input devices.
        /// </summary>
        /// <param name="gameTime"></param>
        override public void Update(GameTime gameTime)
        {   
            // update state
            keyboardManager.Update(gameTime);
            keyboardState = keyboardManager.GetState();
            mouseState = mouseManager.GetState();
            pointerState = pointerManager.GetState();

              
            //mouseClick = mouseState.LeftButton.Pressed && !prevMouseState.LeftButton.Pressed;
            //mouseHeld = mouseState.LeftButton.Pressed && prevMouseState.LeftButton.Pressed;

            if (accelerometer != null) {
                accelerometerReading = accelerometer.GetCurrentReading();
                
            }

            // get mouse delta and reset mouse to centre of window
            if (useMouseDelta && mouseManager.Enabled) {
                mouseDelta = new Vector2(0.5f - mouseState.X, 0.5f - mouseState.Y);
                mouseManager.SetPosition(new Vector2(0.5f, 0.5f));
            }

            // record previous mouse state
            prevMouseState = mouseState;

 	        base.Update(gameTime);
        }
        protected override void Update(GameTime gameTime)
        {
            if (started)
            {
                // Update the keyboard and mouse state
                keyboardState = keyboardManager.GetState();
                mouseState = mouseManager.GetState();
                mouseManager.SetPosition(mouseCenter);
                accelerometerReading = input.accelerometer.GetCurrentReading();

                // Check collisions
                for (var i = 0; i < allBalls.Count; i++)
                {
                    if (!allBalls[i].Equals(player) && player.CollidedWith(allBalls[i]))
                        {
                            player.Collide(allBalls[i]);
                        }
                }

                // Quit
                if (keyboardState.IsKeyDown(Keys.Escape))
                {
                    this.Exit();
                    this.Dispose();
                    App.Current.Exit();
                }

                // Update camera based on the above
                camera.Update(gameTime, keyboardState, mouseState);

                // Finally update models
                landscape.Update(gameTime);
                sun.Update(gameTime);

                // Update balls
                for (var i = 0; i < allBalls.Count; i++)
                {
                    allBalls[i].Update(gameTime);
                }

                mainPage.UpdateScore(score);

                // Handle base.Update
                base.Update(gameTime);
            }
        }
        /// <summary>
        /// Updates the mouse states.
        /// </summary>
        /// <param name="gameTime">Not used.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            var position = platform.GetLocation();
            nextState.x = position.X;
            nextState.y = position.Y;

            if(!isFirstUpdateDone)
            {
                state = nextState;
            }

            var previousState = state;
            state = nextState;
            state.deltaX = state.X - previousState.X;
            state.deltaY = state.Y - previousState.Y;

            nextState.wheelDelta = 0;
            nextState.leftButton.ResetEvents();
            nextState.middleButton.ResetEvents();
            nextState.rightButton.ResetEvents();
            nextState.xButton1.ResetEvents();
            nextState.xButton2.ResetEvents();
            isFirstUpdateDone = true;
        }
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 public virtual void SendMouseState(MouseState state, GameTime gameTime)
 {
     UpdateMouse(state, gameTime);
 }
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        private void BuildMouseEvent(MouseState state, MouseButton button, ref MouseEventArgs e)
        {
            e.State = state;
              e.Button = button;

              e.Position = new Point((int)(mouseState.X * manager.ScreenWidth), (int)(mouseState.Y * manager.ScreenHeight));
              AdjustPosition(ref e);

              e.Position = RecalcPosition(e.Position);
              e.State = new MouseState(e.State.LeftButton, e.State.MiddleButton, e.State.RightButton, e.State.XButton1, e.State.XButton2, e.Position.X, e.Position.Y, e.State.WheelDelta);

              Point pos = RecalcPosition(new Point((int)(mouseState.X * manager.ScreenWidth), (int)(mouseState.Y * manager.ScreenHeight)));
              e.Difference = new Point(e.Position.X - pos.X, e.Position.Y - pos.Y);
        }
        ////////////////////////////////////////////////////////////////////////////    
        private void BuildMouseEvent(MouseState state, MouseButton button, MouseScrollDirection direction, ref MouseEventArgs e)
        {
            BuildMouseEvent(state, button, ref e);

            e.ScrollDirection = direction;
        }
Exemple #27
0
        /// <summary>
        /// Updates the mouse states.
        /// </summary>
        /// <param name="gameTime">Not used.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            state = nextState;

            nextState.leftButton.ResetEvents();
            nextState.middleButton.ResetEvents();
            nextState.rightButton.ResetEvents();
            nextState.xButton1.ResetEvents();
            nextState.xButton2.ResetEvents();
        }
        ////////////////////////////////////////////////////////////////////////////        
        ////////////////////////////////////////////////////////////////////////////
        private void UpdateButtons(MouseState state, GameTime gameTime)
        {
            #if (!XBOX && !XBOX_FAKE)

              MouseEventArgs e = new MouseEventArgs();

              foreach (InputMouseButton btn in mouseButtons)
              {
            ButtonState bs; // = ButtonState.Released;

            if (btn.Button == MouseButton.Left) bs = state.LeftButton;
            else if (btn.Button == MouseButton.Right) bs = state.RightButton;
            else if (btn.Button == MouseButton.Middle) bs = state.MiddleButton;
            else if (btn.Button == MouseButton.XButton1) bs = state.XButton1;
            else if (btn.Button == MouseButton.XButton2) bs = state.XButton2;
            else continue;

            bool pressed = (bs.Down);
            if (pressed)
            {
              double ms = gameTime.ElapsedGameTime.TotalMilliseconds;
              if (pressed) btn.Countdown -= ms;
            }

            if ((pressed) && (!btn.Pressed))
            {
              btn.Pressed = true;
              BuildMouseEvent(state, btn.Button, ref e);

              if (MouseDown != null) MouseDown.Invoke(this, e);
              if (MousePress != null) MousePress.Invoke(this, e);
            }
            else if ((!pressed) && (btn.Pressed))
            {
              btn.Pressed = false;
              btn.Countdown = RepeatDelay;
              BuildMouseEvent(state, btn.Button, ref e);

              if (MouseUp != null) MouseUp.Invoke(this, e);
            }
            else if (btn.Pressed && btn.Countdown < 0)
            {
              e.Button = btn.Button;
              btn.Countdown = RepeatRate;
              BuildMouseEvent(state, btn.Button, ref e);

              if (MousePress != null) MousePress.Invoke(this, e);
            }
              }

              #endif
        }
        protected override void Update(GameTime gameTime)
        {
            mouse = Mouse.GetState();
            keyboard = Keyboard.GetState();

            switch(gameState)
            {
                case GameStates.MainMenu:
                    menu.Update(gameTime);
                    break;
                case GameStates.Play:
                    level.Update(gameTime);
                    break;
                case GameStates.Pause:
                    menu.Update(gameTime);
                    break;
                case GameStates.EndGame:
                    menu.Update(gameTime);
                    break;
                default:
                    break;
            }

            if (CurrentKeyboard.IsKeyDown(Keys.Alt) && CurrentKeyboard.IsKeyDown(Keys.F4)) Exit();

            currentSound.Volume = vol;

            base.Update(gameTime);
        }
        protected override void Update(GameTime gameTime)
        {
            // Getting input device states
            keyboardState = keyboardManager.GetState();
            mouseState = mouseManager.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            model.Update(gameTime);
            camera.Update(gameTime);

            // Handle base.Update
            base.Update(gameTime);
        }