internal GamePadThumbSticks(
     GamePadThumbSticks.StickValue left,
     GamePadThumbSticks.StickValue right)
 {
     this.left  = left;
     this.right = right;
 }
Example #2
0
    Vector2 ApplyStickDeadzone(GamePadThumbSticks.StickValue stick)
    {
        float stickX = stick.X;

        if (stickX > 0)
        {
            stickX = Mathf.Clamp(stickX, stickDeadzone, 1);
            stickX = ExtensionMethods.Map(stickX, stickDeadzone, 1, 0, 1);
        }
        else if (stickX < 0)
        {
            stickX = Mathf.Clamp(stickX, -1, -stickDeadzone);
            stickX = ExtensionMethods.Map(stickX, -1, -stickDeadzone, -1, 0);
        }


        float stickY = stick.Y;

        if (stickY > 0)
        {
            stickY = Mathf.Clamp(stickY, stickDeadzone, 1);
            stickY = ExtensionMethods.Map(stickY, stickDeadzone, 1, 0, 1);
        }
        else if (stickY < 0)
        {
            stickY = Mathf.Clamp(stickY, -1, -stickDeadzone);
            stickY = ExtensionMethods.Map(stickY, -1, -stickDeadzone, -1, 0);
        }

        return(new Vector2(stickX, stickY));
    }
    void freeGearHandler(GamePadThumbSticks.StickValue input)
    {
        knob.localPosition = Vector3.Scale(new Vector3(input.X, input.Y), gearBoxSize);
        PlayerController.instance.updateGear(-1);
        currentGearArea = -1;

        GamePad.SetVibration(PlayerController.instance.gearPlayerIndex, 0f, 0f);
    }
Example #4
0
        private static void PositionStickControl(Control control, Point location, GamePadThumbSticks.StickValue value)
        {
            var deltaX = value.X * control.Width * 0.5f;
            var deltaY = value.Y * control.Height * -0.5f;

            control.Location = new Point(location.X + (int)deltaX, location.Y + (int)deltaY);
            control.Refresh();
        }
Example #5
0
 private void InputUpdate()
 {
     this.prevState = this.state;
     this.state     = GamePad.GetState(this.playerIndex);
     if (this._pos < this._maxLength)
     {
         if (this.state.IsConnected)
         {
             InputThread.InputStruct       inputStruct = this.inputsIn[this._pos];
             InputFilter                   inputFilter = this.leftXFilter;
             GamePadThumbSticks            thumbSticks = this.state.ThumbSticks;
             GamePadThumbSticks.StickValue left        = thumbSticks.Left;
             inputStruct.leftX = inputFilter.Filter((double)left.X);
             InputThread.InputStruct inputStruct1 = this.inputsIn[this._pos];
             InputFilter             inputFilter1 = this.leftYFilter;
             thumbSticks        = this.state.ThumbSticks;
             left               = thumbSticks.Left;
             inputStruct1.leftY = inputFilter1.Filter((double)left.Y);
             InputThread.InputStruct inputStruct2 = this.inputsIn[this._pos];
             InputFilter             inputFilter2 = this.rightXFilter;
             thumbSticks         = this.state.ThumbSticks;
             left                = thumbSticks.Right;
             inputStruct2.rightX = inputFilter2.Filter((double)left.X);
             InputThread.InputStruct inputStruct3 = this.inputsIn[this._pos];
             InputFilter             inputFilter3 = this.rightYFilter;
             thumbSticks                        = this.state.ThumbSticks;
             left                               = thumbSticks.Right;
             inputStruct3.rightY                = inputFilter3.Filter((double)left.Y);
             this.inputsIn[this._pos].time      = DateTime.UtcNow.Ticks;
             this.inputsIn[this._pos].leftXVel  = this.GetVel(this.inputsIn[this._pos].leftX, this._lastFrameData.leftX, this.inputsIn[this._pos].time, this._lastFrameData.time);
             this.inputsIn[this._pos].leftYVel  = this.GetVel(this.inputsIn[this._pos].leftY, this._lastFrameData.leftY, this.inputsIn[this._pos].time, this._lastFrameData.time);
             this.inputsIn[this._pos].rightXVel = this.GetVel(this.inputsIn[this._pos].rightX, this._lastFrameData.rightX, this.inputsIn[this._pos].time, this._lastFrameData.time);
             this.inputsIn[this._pos].rightYVel = this.GetVel(this.inputsIn[this._pos].rightY, this._lastFrameData.rightY, this.inputsIn[this._pos].time, this._lastFrameData.time);
             this._lastFrameData.leftX          = this.inputsIn[this._pos].leftX;
             this._lastFrameData.leftY          = this.inputsIn[this._pos].leftY;
             this._lastFrameData.rightX         = this.inputsIn[this._pos].rightX;
             this._lastFrameData.rightY         = this.inputsIn[this._pos].rightY;
             this._lastFrameData.time           = this.inputsIn[this._pos].time;
             this._pos++;
             return;
         }
         this.inputsIn[this._pos].leftX     = this.leftXFilter.Filter((double)((Mathf.Abs(this.inputController.player.GetAxis("LeftStickX")) < 0.1f ? 0f : this.inputController.player.GetAxis("LeftStickX"))));
         this.inputsIn[this._pos].leftY     = this.leftYFilter.Filter((double)this.inputController.player.GetAxis("LeftStickY"));
         this.inputsIn[this._pos].rightX    = this.rightXFilter.Filter((double)((Mathf.Abs(this.inputController.player.GetAxis("RightStickX")) < 0.1f ? 0f : this.inputController.player.GetAxis("RightStickX"))));
         this.inputsIn[this._pos].rightY    = this.rightYFilter.Filter((double)this.inputController.player.GetAxis("RightStickY"));
         this.inputsIn[this._pos].time      = DateTime.UtcNow.Ticks;
         this.inputsIn[this._pos].leftXVel  = this.GetVel(this.inputsIn[this._pos].leftX, this._lastFrameData.leftX, this.inputsIn[this._pos].time, this._lastFrameData.time);
         this.inputsIn[this._pos].leftYVel  = this.GetVel(this.inputsIn[this._pos].leftY, this._lastFrameData.leftY, this.inputsIn[this._pos].time, this._lastFrameData.time);
         this.inputsIn[this._pos].rightXVel = this.GetVel(this.inputsIn[this._pos].rightX, this._lastFrameData.rightX, this.inputsIn[this._pos].time, this._lastFrameData.time);
         this.inputsIn[this._pos].rightYVel = this.GetVel(this.inputsIn[this._pos].rightY, this._lastFrameData.rightY, this.inputsIn[this._pos].time, this._lastFrameData.time);
         this._lastFrameData.leftX          = this.inputsIn[this._pos].leftX;
         this._lastFrameData.leftY          = this.inputsIn[this._pos].leftY;
         this._lastFrameData.rightX         = this.inputsIn[this._pos].rightX;
         this._lastFrameData.rightY         = this.inputsIn[this._pos].rightY;
         this._lastFrameData.time           = this.inputsIn[this._pos].time;
         this._pos++;
     }
 }
Example #6
0
 Quaternion PointerRotation(GamePadThumbSticks.StickValue a)
 {
     if ((Mathf.Abs(a.X) > .2f) || (Mathf.Abs(a.Y) > .2f))
     {
         float temp = (Mathf.Atan2(a.X, -a.Y) * Mathf.Rad2Deg) - 90;
         //Debug.Log (temp);
         currentRot = Quaternion.Euler(0, 0, temp);
         return(currentRot);
     }
     else
     {
         return(currentRot);
     }
 }
    private Vector3 ComputeMoveAmount(GamePadThumbSticks.StickValue _gamePadLeftThumbStickValue)
    {
        float xMove = 0;
        float zMove = 0;

        if (Mathf.Abs(_gamePadLeftThumbStickValue.X) > .4)
        {
            xMove = _gamePadLeftThumbStickValue.X * 5.0f;
        }
        if (Mathf.Abs(_gamePadLeftThumbStickValue.Y) > .4)
        {
            zMove = _gamePadLeftThumbStickValue.Y * 5.0f;
        }
        return(new Vector3(xMove, 0.0f, zMove));
    }
    // Update is called once per frame
    void Update()
    {
        GamePadState state = GamePad.GetState(PlayerController.instance.gearPlayerIndex);

        GamePadThumbSticks.StickValue transmissionInput = state.ThumbSticks.Right;

        if (inputStrength(transmissionInput) <= PlayerController.instance.freeGearThreshold)
        {
            //Debug.LogWarning ("Input strength" + inputStrength(transmissionInput));
            freeGearHandler(transmissionInput);
        }
        else
        {
            lockedGearHandler(transmissionInput);
        }
    }
    private void Reducer(PlayerAction action)
    {
        switch (action.GetType().ToString())
        {
        case "UpdatePlayerBoxcastHitAction":
            _objectBoxcastHit = ((UpdatePlayerBoxcastHitAction)action).objectBoxcastHit;
            break;

        case "UpdateGamePadRightTriggerPressedAction":
            _gamePadRightTriggerPressedAmount = ((UpdateGamePadRightTriggerPressedAction)action).gamePadRightTriggerPressedAmount;
            break;

        case "UpdateGamePadLeftTriggerPressedAction":
            _gamePadLeftTriggerPressedAmount = ((UpdateGamePadLeftTriggerPressedAction)action).gamePadLeftTriggerPressedAmount;
            break;

        case "UpdatePlayerIndexAction":
            _playerIndex = ((UpdatePlayerIndexAction)action).playerIndex;
            break;

        case "UpdateGamePadRightThumbStickMovedAction":
            _gamePadRightThumbStickValue = ((UpdateGamePadRightThumbStickMovedAction)action).gamePadRightThumbStickValue;
            break;

        case "UpdateGamePadLeftThumbStickMovedAction":
            _gamePadLeftThumbStickValue = ((UpdateGamePadLeftThumbStickMovedAction)action).gamePadLeftThumbStickValue;
            break;

        case "UpdateInsideHazardAction":
            _hazardInside = ((UpdateInsideHazardAction)action).hazardInside;
            break;

        case "UpdateAddColliderAction":
            _collidersInside.Add(((UpdateAddColliderAction)action).collider);
            break;

        case "UpdateRemoveColliderAction":
            _collidersInside.Remove(((UpdateRemoveColliderAction)action).collider);
            break;

        default:
            Debug.Log("no type of action");
            // don't change internal state
            break;
        }
    }
    private float ComputeRotateAmount(GamePadThumbSticks.StickValue _gamePadRightThumbStickValue, List <Collider> _collidersInside)
    {
        float returnRotateAmount = 0;

        if (Mathf.Abs(_gamePadRightThumbStickValue.X) > .4)
        {
            returnRotateAmount += _gamePadRightThumbStickValue.X * 50.0f;
        }
        foreach (Collider col in _collidersInside)
        {
            string collObjTag = col.gameObject.tag;
            if (collObjTag == "Hazard")
            {
                HazardStore hazStore = col.gameObject.GetComponent <HazardStore> ();
                if (hazStore.GetType().ToString() == "Rotator_HazardStore")
                {
                    returnRotateAmount += ((Rotator_HazardStore)hazStore).rotateEffect;
                }
            }
        }

        return(returnRotateAmount);
    }
    void lockedGearHandler(GamePadThumbSticks.StickValue input)
    {
        if (currentGearArea == -1)
        {
            float normalizedAngle = (Mathf.PI / 2 + gearRad + 2 * Mathf.PI - inputAngle(input)) / gearRad;
            currentGearArea = Mathf.FloorToInt(normalizedAngle + 0.5f) % gearCount;
        }
        //	Debug.Log ("Closest gear area" + currentGearArea);

        float maxGearAreaAngle = getGearRad(currentGearArea) + PlayerController.instance.gearRestrictedRoamingProportion * gearRad / 2;
        float minGearAreaAngle = getGearRad(currentGearArea) - PlayerController.instance.gearRestrictedRoamingProportion * gearRad / 2;

        //Debug.Log(minGearAreaAngle + ", " + inputAngle (input) + ", " + maxGearAreaAngle);

        float clampedAngle = Mathf.Clamp(inputAngle(input) + 2 * Mathf.PI, minGearAreaAngle + 2 * Mathf.PI, maxGearAreaAngle + 2 * Mathf.PI);

        setTransmissionRumble(inputAngle(input) + 2 * Mathf.PI, minGearAreaAngle + 2 * Mathf.PI, maxGearAreaAngle + 2 * Mathf.PI);

        knob.localPosition = Vector3.Scale(
            new Vector3(
                Mathf.Cos(clampedAngle) * inputStrength(input),
                Mathf.Sin(clampedAngle) * inputStrength(input),
                0
                ),
            gearBoxSize
            );

        if (inputStrength(input) > PlayerController.instance.acceptedGearThreshold)
        {
            if (currentGearArea == -1)
            {
                Debug.LogError("Gear validated without valid Gear area !!!");
            }
            PlayerController.instance.updateGear(currentGearArea);
        }
    }
Example #12
0
 public Vector2 GetStickVector(XboxControlStick stick)
 {
     GamePadThumbSticks.StickValue stickValue = XboxControlSticktoStickValue(gamePadState, stick);
     return(new Vector2(stickValue.X, stickValue.Y).normalized);
 }
 public void UpdateGamePadLeftThumbStickMovedActionRequested(GamePadThumbSticks.StickValue leftThumbStickValue)
 {
     playerStore.Dispatch(new UpdateGamePadLeftThumbStickMovedAction(leftThumbStickValue));
 }
Example #14
0
 Vector2 GetStickDirection(GamePadThumbSticks.StickValue val)
 {
     return(new Vector2(val.X, val.Y));
 }
 float inputAngle(GamePadThumbSticks.StickValue input)
 {
     return(Mathf.Atan2(input.Y, input.X) % (2 * Mathf.PI));
 }
Example #16
0
 public static bool CompareSticks(this GamePadThumbSticks.StickValue sticka, GamePadThumbSticks.StickValue stickb)
 {
     return(sticka.X.Equals(stickb.X) && sticka.Y.Equals(stickb.Y));
 }
 public UpdateGamePadLeftThumbStickMovedAction(GamePadThumbSticks.StickValue gamePadLeftThumbStickValue)
 {
     this.gamePadLeftThumbStickValue = gamePadLeftThumbStickValue;
 }
Example #18
0
 Vector2 ApplyStickDeadzone(GamePadThumbSticks.StickValue stick, float stickDeadzone)
 {
     return(ApplyStickDeadzone(new Vector2(stick.X, stick.Y), stickDeadzone));
 }
        private IEnumerator updateCoroutine()
        {
            // Written, 16.10.2020

            if (MoControlsSaveData.loadedSaveData.emulateMouse)
            {
                XboxController xboxController = MoControlsGO.xboxController;

                simulateLeftClick();
                simulateRightClick();
                if (xboxController.isConnected)
                {
                    GamePadThumbSticks.StickValue stickValue_temp = default;
                    Vector2 stickValue = Vector2.zero;
                    int     moveX;
                    int     moveY;

                    switch (MoControlsSaveData.loadedSaveData.mouseInputType)
                    {
                    case InputTypeEnum.LS:
                        stickValue_temp = xboxController.getLeftStick();
                        break;

                    case InputTypeEnum.RS:
                        stickValue_temp = xboxController.getRightStick();
                        break;

                    case InputTypeEnum.DPad:
                        if (xboxController.dPadLeft.state == ButtonState.Pressed)
                        {
                            stickValue.x = -1;
                        }
                        if (xboxController.dPadRight.state == ButtonState.Pressed)
                        {
                            stickValue.x = 1;
                        }
                        if (xboxController.dPadUp.state == ButtonState.Pressed)
                        {
                            stickValue.y = 1;
                        }
                        if (xboxController.dPadDown.state == ButtonState.Pressed)
                        {
                            stickValue.y = -1;
                        }
                        break;
                    }
                    if (MoControlsSaveData.loadedSaveData.mouseInputType != InputTypeEnum.DPad)
                    {
                        stickValue.x = stickValue_temp.X;
                        stickValue.y = stickValue_temp.Y;
                    }
                    if (stickValue != Vector2.zero)
                    {
                        // Deadzone
                        stickValue = stickValue.doDeadzoneCheck(MoControlsSaveData.loadedSaveData.mouseDeadzone, MoControlsSaveData.loadedSaveData.mouseDeadzoneType);
                        // Sensitivity
                        stickValue = stickValue.doSensitivityOperation(MoControlsSaveData.loadedSaveData.mouseSensitivity);

                        moveX = (int)stickValue.x;
                        moveY = (int)stickValue.y * -1; // '* -1' xbox controller y axis is naturally inverted. so changing the that..;
                        simulateMouseMove(moveX, moveY);
                        yield return(null);             //new WaitForEndOfFrame();
                    }
                }
            }
        }
 float inputStrength(GamePadThumbSticks.StickValue input)
 {
     return(Mathf.Sqrt(input.X * input.X + input.Y * input.Y));
 }
Example #21
0
 public static Vector2 ThumbSticksToVector(GamePadThumbSticks.StickValue value)
 {
     return(new Vector2(value.X, value.Y));
 }