Beispiel #1
0
        public InputProcessor(GamePadState initialState)
        {
            center = new UIntVector(32768, 30650);

            bindings  = new List <ControllerInputBinding>();
            lastState = initialState;

            currentControllerState           = new ControllerState();
            currentControllerState.inputMode = InputMode.Pointer;
            currentControllerState.targetingReticulePosition = center;
            currentControllerState.cursorPosition            = center;
            currentControllerState.centerPosition            = center;

            d3Bindings = new D3Bindings();
            config     = new Configuration();

            stateChangeCommands          = new Queue <StateChangeCommand>();
            cursorMoveCommands           = new Queue <CursorMoveCommand>();
            reticuleTargetedCommands     = new Queue <Command>();
            cursorTargetedCommands       = new Queue <Command>();
            untargetedCommands           = new Queue <Command>();
            centerRandomTargetedCommands = new Queue <Command>();

            CreateDefaultBindings();
        }
Beispiel #2
0
 public virtual void getLocalMapIndex(Keyframe refKF, UIntVector idxLocalCloudPoints)
 {
     solar_api_solver_mapPINVOKE.IMapper_getLocalMapIndex(swigCPtr, Keyframe.getCPtr(refKF), UIntVector.getCPtr(idxLocalCloudPoints));
     if (solar_api_solver_mapPINVOKE.SWIGPendingException.Pending)
     {
         throw solar_api_solver_mapPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #3
0
        public void Update(GamePadState newState)
        {
            currentControllerState.connected = newState.IsConnected;

            if (!newState.IsConnected)
            {
                return;
            }

            if (currentControllerState.inputMode == InputMode.Move)
            {
                int DeltaX = (int)currentControllerState.cursorPosition.X - (int)center.X;
                int DeltaY = (int)currentControllerState.cursorPosition.Y - (int)center.Y;

                Vector2 deltaVector = new Vector2(DeltaX, DeltaY);
                deltaVector.Normalize();

                deltaVector *= 1000.0f;


                currentControllerState.centerPosition = new UIntVector((uint)(center.X + deltaVector.X), (uint)(center.Y + deltaVector.Y));
                // VirtualMouse.MoveAbsolute(center.X, center.Y);
            }
            else
            {
                //
            }



            foreach (ControllerInputBinding binding in bindings)
            {
                if (binding.button != 0)
                {
                    if (binding.buttonState == ControllerButtonState.OnDown)
                    {
                        if ((newState.IsButtonDown(binding.button)) && (lastState.IsButtonUp(binding.button)))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                    else if (binding.buttonState == ControllerButtonState.OnUp)
                    {
                        if ((newState.IsButtonUp(binding.button)) && (lastState.IsButtonDown(binding.button)))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                    else if (binding.buttonState == ControllerButtonState.WhileDown)
                    {
                        if (newState.IsButtonDown(binding.button))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                    else if (binding.buttonState == ControllerButtonState.WhileUp)
                    {
                        if (newState.IsButtonUp(binding.button))
                        {
                            enqueueCommands(binding, currentControllerState);
                        }
                    }
                }

                if (binding.trigger != null)
                {
                    if (binding.trigger.side == ControllerTrigger.Left)
                    {
                        if (binding.triggerState == ControllerTriggerState.OnDown)
                        {
                            if ((newState.Triggers.Left > binding.trigger.position) && (lastState.Triggers.Left < binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.OnUp)
                        {
                            if ((newState.Triggers.Left < binding.trigger.position) && (lastState.Triggers.Left > binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileDown)
                        {
                            if (newState.Triggers.Left > 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileUp)
                        {
                            if (newState.Triggers.Left == 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                    }
                    else if (binding.trigger.side == ControllerTrigger.Right)
                    {
                        if (binding.triggerState == ControllerTriggerState.OnDown)
                        {
                            if ((newState.Triggers.Right > binding.trigger.position) && (lastState.Triggers.Right < binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.OnUp)
                        {
                            if ((newState.Triggers.Right < binding.trigger.position) && (lastState.Triggers.Right > binding.trigger.position))
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileDown)
                        {
                            if (newState.Triggers.Right > 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                        else if (binding.triggerState == ControllerTriggerState.WhileUp)
                        {
                            if (newState.Triggers.Right == 0)
                            {
                                enqueueCommands(binding, currentControllerState);
                            }
                        }
                    }
                }

                if (binding.stick != null)
                {
                    bool executeCommand;

                    if (binding.stick.side == ControllerStick.Left)
                    {
                        executeCommand = true;

                        if (binding.stick.newState == StickState.NotEqual)
                        {
                            if ((newState.ThumbSticks.Left.X == binding.stick.position.X) && (newState.ThumbSticks.Left.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.newState == StickState.Equal)
                        {
                            if ((newState.ThumbSticks.Left.X != binding.stick.position.X) || (newState.ThumbSticks.Left.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (binding.stick.oldState == StickState.NotEqual)
                        {
                            if ((lastState.ThumbSticks.Left.X == binding.stick.position.X) && (lastState.ThumbSticks.Left.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.oldState == StickState.Equal)
                        {
                            if ((lastState.ThumbSticks.Left.X != binding.stick.position.X) || (lastState.ThumbSticks.Left.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (executeCommand)
                        {
                            Microsoft.Xna.Framework.Vector2 inputCommandValue = new Microsoft.Xna.Framework.Vector2(newState.ThumbSticks.Left.X, newState.ThumbSticks.Left.Y);
                            enqueueCommands(binding, currentControllerState, inputCommandValue);
                        }
                    }
                    else if (binding.stick.side == ControllerStick.Right)
                    {
                        executeCommand = true;

                        if (binding.stick.newState == StickState.NotEqual)
                        {
                            if ((newState.ThumbSticks.Right.X == binding.stick.position.X) && (newState.ThumbSticks.Right.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.newState == StickState.Equal)
                        {
                            if ((newState.ThumbSticks.Right.X != binding.stick.position.X) || (newState.ThumbSticks.Right.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (binding.stick.oldState == StickState.NotEqual)
                        {
                            if ((lastState.ThumbSticks.Right.X == binding.stick.position.X) && (lastState.ThumbSticks.Right.Y == binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }
                        else if (binding.stick.oldState == StickState.Equal)
                        {
                            if ((lastState.ThumbSticks.Right.X != binding.stick.position.X) || (lastState.ThumbSticks.Right.Y != binding.stick.position.Y))
                            {
                                executeCommand = false;
                            }
                        }

                        if (executeCommand)
                        {
                            Microsoft.Xna.Framework.Vector2 inputCommandValue = new Microsoft.Xna.Framework.Vector2(newState.ThumbSticks.Right.X, newState.ThumbSticks.Right.Y);
                            enqueueCommands(binding, currentControllerState, inputCommandValue);
                        }
                    }
                }
            }


            while (stateChangeCommands.Count > 0)
            {
                VirtualKeyboard.AllUp();

                currentControllerState.targetingReticulePosition = currentControllerState.centerPosition;
                currentControllerState.cursorPosition            = currentControllerState.centerPosition;

                stateChangeCommands.Dequeue().Execute(ref currentControllerState);
            }

            while (cursorMoveCommands.Count > 0)
            {
                cursorMoveCommands.Dequeue().Execute(ref currentControllerState);
            }



            if (centerRandomTargetedCommands.Count > 0)
            {
                int DeltaX = (int)currentControllerState.cursorPosition.X - (int)center.X;
                int DeltaY = (int)currentControllerState.cursorPosition.Y - (int)center.Y;

                Vector2 deltaVector = new Vector2(DeltaX, DeltaY);
                deltaVector.Normalize();

                deltaVector *= 1000.0f;


                UIntVector centerOffset = new UIntVector((uint)(center.X + deltaVector.X), (uint)(center.Y + deltaVector.Y));
                VirtualMouse.MoveAbsolute(centerOffset.X, centerOffset.Y);
            }
            while (centerRandomTargetedCommands.Count > 0)
            {
                centerRandomTargetedCommands.Dequeue().Execute(ref currentControllerState);
            }



            if (reticuleTargetedCommands.Count > 0)
            {
                if ((currentControllerState.targetingReticulePosition.X == currentControllerState.centerPosition.X) && (currentControllerState.targetingReticulePosition.Y == currentControllerState.centerPosition.Y))
                {
                    VirtualMouse.MoveAbsolute(currentControllerState.cursorPosition.X, currentControllerState.cursorPosition.Y);
                }
                else
                {
                    VirtualMouse.MoveAbsolute(currentControllerState.targetingReticulePosition.X, currentControllerState.targetingReticulePosition.Y);
                }
            }

            Thread.Sleep(10);

            while (reticuleTargetedCommands.Count > 0)
            {
                reticuleTargetedCommands.Dequeue().Execute(ref currentControllerState);
            }

            //if ((currentControllerState.inputMode != InputMode.None) && (currentControllerState.inputMode != InputMode.Pointer))
            if (currentControllerState.inputMode != InputMode.None)
            {
                VirtualMouse.MoveAbsolute(currentControllerState.cursorPosition.X, currentControllerState.cursorPosition.Y);
            }
            while (cursorTargetedCommands.Count > 0)
            {
                cursorTargetedCommands.Dequeue().Execute(ref currentControllerState);
            }


            //if ((currentControllerState.inputMode != InputMode.None) && (currentControllerState.inputMode != InputMode.Pointer))



            while (untargetedCommands.Count > 0)
            {
                untargetedCommands.Dequeue().Execute(ref currentControllerState);
            }

            lastState = newState;
        }
Beispiel #4
0
 private void AddStickCursorMoveBinding(ControllerStick stick, Microsoft.Xna.Framework.Vector2 comparisonVector, StickState comparisonState, StickState oldComparisonState, MouseMoveType moveType, UIntVector moveScale, CommandTarget commandTarget, InputMode bindingMode = InputMode.All)
 {
     bindings.Add(ControllerInputBinding.createStickCursorMoveBinding(stick, comparisonVector, comparisonState, oldComparisonState, moveType, moveScale, commandTarget, bindingMode));
 }