Ejemplo n.º 1
0
        private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
        {
            AnalogStick.Name  = Name;
            AnalogStick.XName = Name;
            AnalogStick.YName = Name.Replace("X", "Y");             // TODO: allow schema to dictate this but this is a convenient default
            AnalogStick.SetRangeX(RangeX);
            AnalogStick.SetRangeY(RangeY);

            ManualX.Minimum = (decimal)RangeX[0];
            ManualX.Maximum = (decimal)RangeX[2];

            ManualY.Minimum = (decimal)RangeX[0];
            ManualY.Maximum = (decimal)RangeX[2];

            MaxXNumeric.Minimum = 1;
            MaxXNumeric.Maximum = 100;
            MaxXNumeric.Value   = 100;

            MaxYNumeric.Minimum = 1;
            MaxYNumeric.Maximum = 100;
            MaxYNumeric.Value   = 100;           // Note: these trigger change events that change the analog stick too

            rangeAverageX = (int)((RangeX[0] + RangeX[2]) / 2);
            rangeAverageY = (int)((RangeY[0] + RangeY[2]) / 2);
        }
Ejemplo n.º 2
0
        void MyOwnInput()         //Better than normal stuff as it supports having two input devices simultaneosly
        {
            AnalogStick leftAnalogStick = gamePad.LeftStick;

            if ((InputManager.Keyboard.KeyDown(Keys.D) || InputManager.Keyboard.KeyDown(Keys.Right) || gamePad.ButtonDown(Xbox360GamePad.Button.DPadRight) || leftAnalogStick.AsDPadDown(Xbox360GamePad.DPadDirection.Right)) && InputActive)
            {
                input.HorinzontalInputa(1);
            }
            else if ((InputManager.Keyboard.KeyDown(Keys.A) || InputManager.Keyboard.KeyDown(Keys.Left) || gamePad.ButtonDown(Xbox360GamePad.Button.DPadLeft) || leftAnalogStick.AsDPadDown(Xbox360GamePad.DPadDirection.Left)) && InputActive)
            {
                input.HorinzontalInputa(-1);
            }
            else if ((InputManager.Keyboard.KeyDown(Keys.W) || InputManager.Keyboard.KeyDown(Keys.Up) || gamePad.ButtonDown(Xbox360GamePad.Button.DPadUp) || leftAnalogStick.AsDPadDown(Xbox360GamePad.DPadDirection.Up)) && InputActive)
            {
                input.VerticalInputb(1);
            }
            //else if (InputManager.Keyboard.KeyDown(Keys.S) || InputManager.Keyboard.KeyDown(Keys.Down) || gamePad.ButtonDown(Xbox360GamePad.Button.DPadDown) || leftAnalogStick.AsDPadDown(Xbox360GamePad.DPadDirection.Down))
            //{
            //    input.VerticalInputb(-1);
            //}
            else
            {
                input.HorinzontalInputa(0);
                input.VerticalInputb(0);
            }
            InitializePlatformerInput(input);
        }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Get Analog Stick Axis
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public static float GetAnalogAxis(AnalogStick eStick, Direction eDir)
    {
        if (eStick == AnalogStick.Left)
        {
            if (eDir == Direction.Horizontal)
            {
                return(Input.GetAxisRaw(m_sLeftStickHorizontal));
            }
            else
            {
                return(Input.GetAxisRaw(m_sLeftStickVertical));
            }
        }

        else
        {
            if (eDir == Direction.Horizontal)
            {
                return(Input.GetAxisRaw(m_sRightStickHorizontal));
            }
            else
            {
                return(Input.GetAxisRaw(m_sRightStickVertical));
            }
        }
    }
Ejemplo n.º 4
0
 private void SetAnalogMaxFromNumerics()
 {
     if (!_programmaticallyUpdatingNumerics)
     {
         AnalogStick.SetUserRange((sbyte)MaxXNumeric.Value, (sbyte)MaxYNumeric.Value);
     }
 }
Ejemplo n.º 5
0
        // read the calibration data and undo obfuscation transformation
        private void ReadCalibrationData()
        {
            byte[] buffer = new byte[16];
            // 0x04A40020 is the address of the calibration data on the wiimote
            _Wiimote.ReadMemory(0x04A40020, buffer, 0, 16);
            for (int i = 0; i < 16; i++)
            {
                buffer[i] = (byte)((buffer[i] ^ 0x17) + 0x17 & 0xFF);
            }

            AccelerometerCalibration accelerometerCalibration = new AccelerometerCalibration(
                (ushort)((buffer[0] << 2) + ((buffer[3]) & 0x3)),
                (ushort)((buffer[4] << 2) + ((buffer[7]) & 0x3)),
                (ushort)((buffer[1] << 2) + ((buffer[3] >> 2) & 0x3)),
                (ushort)((buffer[5] << 2) + ((buffer[7] >> 2) & 0x3)),
                (ushort)((buffer[2] << 2) + ((buffer[3] >> 4) & 0x3)),
                (ushort)((buffer[6] << 2) + ((buffer[7] >> 4) & 0x3)));

            _Accelerometer = new Accelerometer(accelerometerCalibration);

            AnalogStickCalibration stickCalibration = new AnalogStickCalibration(buffer[9], buffer[10], buffer[8],
                                                                                 buffer[12], buffer[13], buffer[11]);

            _Stick = new AnalogStick(stickCalibration);
        }
Ejemplo n.º 6
0
 private void SetAnalogMaxFromNumerics()
 {
     if (!_programmaticallyUpdatingNumerics)
     {
         AnalogStick.SetUserRange(ReverseX ? -MaxXNumeric.Value : MaxXNumeric.Value, ReverseY ? -MaxYNumeric.Value : MaxYNumeric.Value);
     }
 }
        private int[] getMouseMovement(AnalogStick stick)
        {
            var stickMovement = stick.Movement;
            var mouseMovement = new int[2];

            mouseMovement[0] = 0;
            mouseMovement[1] = 0;

            if (stickMovement[(int)Direction.LEFT] > minSymmetricThreshold)
            {
                mouseMovement[0] = -whichIndex(minSymmetricThreshold, maxSymmetricDirectionValue, maxMouseMovementSpeed, stickMovement[(int)Direction.LEFT]);
            }

            if (stickMovement[(int)Direction.RIGHT] > minSymmetricThreshold)
            {
                mouseMovement[0] = whichIndex(minSymmetricThreshold, maxSymmetricDirectionValue, maxMouseMovementSpeed, stickMovement[(int)Direction.RIGHT]);
            }

            if (stickMovement[(int)Direction.TOP] > minSymmetricThreshold)
            {
                mouseMovement[1] = -whichIndex(minSymmetricThreshold, maxSymmetricDirectionValue, maxMouseMovementSpeed, stickMovement[(int)Direction.TOP]);
            }

            if (stickMovement[(int)Direction.DOWN] > minSymmetricThreshold)
            {
                mouseMovement[1] = whichIndex(minSymmetricThreshold, maxSymmetricDirectionValue, maxMouseMovementSpeed, stickMovement[(int)Direction.DOWN]);
            }

            return(mouseMovement);
        }
Ejemplo n.º 8
0
        private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
        {
            AnalogStick.Name  = Name;
            AnalogStick.XName = Name;
            AnalogStick.YName = !string.IsNullOrEmpty(SecondaryName)
                                ? SecondaryName
                                : Name.Replace("X", "Y"); // Fallback
            AnalogStick.SetRangeX(RangeX);
            AnalogStick.SetRangeY(RangeY);

            ManualX.Minimum = (decimal)RangeX[0];
            ManualX.Maximum = (decimal)RangeX[2];

            ManualY.Minimum = (decimal)RangeX[0];
            ManualY.Maximum = (decimal)RangeX[2];

            MaxXNumeric.Minimum = 1;
            MaxXNumeric.Maximum = 100;
            MaxXNumeric.Value   = 100;

            MaxYNumeric.Minimum = 1;
            MaxYNumeric.Maximum = 100;
            MaxYNumeric.Value   = 100;           // Note: these trigger change events that change the analog stick too

            rangeAverageX = (int)((RangeX[0] + RangeX[2]) / 2);
            rangeAverageY = (int)((RangeY[0] + RangeY[2]) / 2);
        }
Ejemplo n.º 9
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------

        // Initializes the controls for the game
        public static void Initialize()
        {
            Controls.arrows = new MultiGameButton[4];
            Controls.arrows[Directions.Up]    = new MultiGameButton(new GameButton(Keys.Up), new GameButton(Buttons.LeftStickUp));
            Controls.arrows[Directions.Down]  = new MultiGameButton(new GameButton(Keys.Down), new GameButton(Buttons.LeftStickDown));
            Controls.arrows[Directions.Left]  = new MultiGameButton(new GameButton(Keys.Left), new GameButton(Buttons.LeftStickLeft));
            Controls.arrows[Directions.Right] = new MultiGameButton(new GameButton(Keys.Right), new GameButton(Buttons.LeftStickRight));

            Controls.analogMovement = GamePad.GetStick(Buttons.LeftStick);

            /*
             * Controls.a				= new MultiGameButton(new GameButton(Keys.X), new GameButton(Buttons.A));
             * Controls.b				= new MultiGameButton(new GameButton(Keys.Z), new GameButton(Buttons.B));
             * Controls.x				= new MultiGameButton(new GameButton(Keys.S), new GameButton(Buttons.X));
             * Controls.y				= new MultiGameButton(new GameButton(Keys.A), new GameButton(Buttons.Y));
             * Controls.start			= new MultiGameButton(new GameButton(Keys.Enter), new GameButton(Buttons.Start));
             * Controls.select			= new MultiGameButton(new GameButton(Keys.Backslash), new GameButton(Buttons.Back));
             */

            // David's preffered control scheme:
            Controls.a      = new MultiGameButton(new GameButton(Keys.Z), new GameButton(Buttons.A));
            Controls.b      = new MultiGameButton(new GameButton(Keys.X), new GameButton(Buttons.B));
            Controls.x      = new MultiGameButton(new GameButton(Keys.S), new GameButton(Buttons.X));
            Controls.y      = new MultiGameButton(new GameButton(Keys.A), new GameButton(Buttons.Y));
            Controls.start  = new MultiGameButton(new GameButton(Keys.Enter), new GameButton(Buttons.Start));
            Controls.select = new MultiGameButton(new GameButton(Keys.RShift), new GameButton(Buttons.Back));
        }
Ejemplo n.º 10
0
    void OperateAnalogStick(AnalogStick stick, AnalogStickOperation operation, Vector3 point)
    {
        //Debug.Log(stick.ToString() + "" + operation.ToString());

        switch (operation)
        {
        case AnalogStickOperation.FadeIn:
        {
            if (stick == leftStick)
            {
                leftStickPosition = point;
            }
            else if (stick == rightStick)
            {
                rightStickPosition = point;
            }
        }
        break;

        case AnalogStickOperation.Move:
        {
            stick.moveDirection = point;
            stick.Move();
        }
        break;

        case AnalogStickOperation.Leave:
        {
            stick.ReturnToZero();
        }
        break;
        }
    }
Ejemplo n.º 11
0
 private void SetAnalogMaxFromNumerics()
 {
     if (!_programmaticallyUpdatingNumerics)
     {
         //blehh,... this damn feature
         AnalogStick.SetUserRange((float)MaxXNumeric.Value, (float)MaxYNumeric.Value);
     }
 }
Ejemplo n.º 12
0
 public AnalogInputRepeater(PlayerIndex player, AnalogStick stick, float threshold, int minMillisPerRepeat, int maxMillisPerRepeat)
     : base(player, stick)
 {
     this.threshold = threshold;
     this.millisRemaining = 0;
     this.minMillisPerRepeat = minMillisPerRepeat;
     this.maxMillisPerRepeat = maxMillisPerRepeat;
     this.isDown = false;
 }
Ejemplo n.º 13
0
 private void SetAnalogControlFromNumerics()
 {
     if (!_programmaticallyUpdatingNumerics)
     {
         AnalogStick.X        = (int)ManualX.Value;
         AnalogStick.Y        = (int)ManualY.Value;
         AnalogStick.HasValue = true;
         AnalogStick.Refresh();
     }
 }
Ejemplo n.º 14
0
        bool[] getDirectionStatus(AnalogStick stick)
        {
            var directionsPressed = new bool[4];
            var movement          = stick.Movement;

            directionsPressed[(int)Direction.TOP]   = movement[(int)Direction.TOP] > thresholdVertical;
            directionsPressed[(int)Direction.RIGHT] = movement[(int)Direction.RIGHT] > thresholdHorizontal;
            directionsPressed[(int)Direction.DOWN]  = movement[(int)Direction.DOWN] > thresholdVertical;
            directionsPressed[(int)Direction.LEFT]  = movement[(int)Direction.LEFT] > thresholdHorizontal;
            return(directionsPressed);
        }
Ejemplo n.º 15
0
        public override Vector2 getAnalogVector(AnalogStick a, PlayerIndex?pi)
        {
            if (a == AnalogStick.Left)
            {
                Vector2 v = Vector2.Zero;

                if (CurrentKeyboardState.IsKeyDown(Keys.A))
                {
                    v += new Vector2(-1.0f, 0.0f);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.D))
                {
                    v += new Vector2(1.0f, 0.0f);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.S))
                {
                    v += new Vector2(0.0f, -1.0f);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.W))
                {
                    v += new Vector2(0.0f, 1.0f);
                }

                return(v);
            }
            else
            {
                Vector2 v = Vector2.Zero;
                if (CurrentKeyboardState.IsKeyDown(Keys.Left))
                {
                    v += new Vector2(-1.0f, 0.0f);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.Right))
                {
                    v += new Vector2(1.0f, 0.0f);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.Down))
                {
                    v += new Vector2(0.0f, -1.0f);
                }
                if (CurrentKeyboardState.IsKeyDown(Keys.Up))
                {
                    v += new Vector2(0.0f, 1.0f);
                }

                return(v);
            }
        }
Ejemplo n.º 16
0
        private void PolarNumeric_Changed(object sender, EventArgs e)
        {
            ManualX.ValueChanged -= manualXYValueChangedEventHandler;
            ManualY.ValueChanged -= manualXYValueChangedEventHandler;

            ManualX.Value = Math.Ceiling(manualR.Value * (decimal)Math.Cos(Math.PI * (double)manualTheta.Value / 180)).Clamp(-127, 127);
            ManualY.Value = Math.Ceiling(manualR.Value * (decimal)Math.Sin(Math.PI * (double)manualTheta.Value / 180)).Clamp(-127, 127);

            AnalogStick.X        = (int)ManualX.Value;
            AnalogStick.Y        = (int)ManualY.Value;
            AnalogStick.HasValue = true;
            AnalogStick.Refresh();

            ManualX.ValueChanged += manualXYValueChangedEventHandler;
            ManualY.ValueChanged += manualXYValueChangedEventHandler;
        }
Ejemplo n.º 17
0
        public Joystick(IntPtr window_handle)
        {
            hWnd = window_handle;
            AnalogStick leftStick = new AnalogStick(0, 65535, 8, s => s.X, s => s.Y);

            leftStick.Mapping = new AnalogStickToKeyMapping();

            AnalogStick rightStick = new AnalogStick(0, 65535, 9, s => s.Rx, s => s.Ry);

            rightStick.Mapping = new AnalogStickToMouseMapping();

            modules = new List <IControllerModule>();
            modules.Add(leftStick);
            modules.Add(rightStick);

            var buttonsToKeys = new Dictionary <int, int>();

            buttonsToKeys[0] = (int)FormsKeys.Space;   // A
            buttonsToKeys[1] = (int)FormsKeys.Alt;     // B
            buttonsToKeys[2] = (int)FormsKeys.Control; // X
            buttonsToKeys[3] = (int)FormsKeys.R;       // Y
            buttonsToKeys[4] = (int)FormsKeys.Q;       // Linker Bumper
            buttonsToKeys[5] = (int)FormsKeys.E;       // Rechter Bumper
            buttonsToKeys[6] = (int)FormsKeys.Escape;  // Back
            buttonsToKeys[7] = (int)FormsKeys.Enter;   // Start
            //buttonsToKeys[8] = (int)FormsKeys.I; // Klick Linker Stick
            //buttonsToKeys[9] = (int)FormsKeys.J; // Klick Rechter Stick

            List <ControllerButton> buttons = new List <ControllerButton>();

            for (int i = 0; i <= 7; ++i)
            {
                ControllerButton b = new ControllerButton(i);
                b.Mapping = new ButtonToKeyMapping((short)buttonsToKeys[i]);
                buttons.Add(b);
            }

            ButtonSet bSet = new ButtonSet(buttons);

            modules.Add(bSet);

            Trigger t = new Trigger(0, 65535);

            t.Mapping = new TriggerToTemporaryCustomMapping(20000);
            modules.Add(t);
        }
Ejemplo n.º 18
0
        public void map(AnalogStick stick)
        {
            var currentDirectionStatus = getDirectionStatus(stick);
            var releasedDirections     = getReleasedDirections(currentDirectionStatus);
            var pressedDirections      = getPressedDirections(currentDirectionStatus);

            //s += "Release:\t";
            //foreach (bool b in releasedDirections)
            //{
            //    s += b + "\t";
            //}
            //s += "\n";

            //s += "Pressed:\t";
            //foreach (bool b in pressedDirections)
            //{
            //    s += b + "\t";
            //}
            //s += "\n";

            for (int i = 0; i < releasedDirections.Length; ++i)
            {
                //string t = " ";
                if (releasedDirections[i] == true)
                {
                    InputInterface.ReleaseKey((short)directionsToKeys[(Direction)i]);
                    //t = "rel";
                }
                //s += t + "\t";
            }
            //s += "\n";

            for (int i = 0; i < pressedDirections.Length; ++i)
            {
                //string t = " ";
                if (pressedDirections[i] == true)
                {
                    InputInterface.PressKey((short)directionsToKeys[(Direction)i]);
                    // t = "prs";
                }
                //s += t + "\t";
            }

            update(currentDirectionStatus);
        }
Ejemplo n.º 19
0
 public override Vector2 getAnalogVector(AnalogStick a, PlayerIndex?pi)
 {
     if (pi.HasValue)
     {
         if (a == AnalogStick.Left)
         {
             return(CurrentGamepadStates[(int)pi.Value].ThumbSticks.Left);
         }
         else
         {
             return(CurrentGamepadStates[(int)pi.Value].ThumbSticks.Right);
         }
     }
     else
     {
         return(getAnalogVector(a, PlayerIndex.One));
     }
 }
        //TODO: Aktion beim Klick variabel maachen
        public void map(AnalogStick stick)
        {
            var m = getMouseMovement(stick);

            InputInterface.MoveMouse(m[0], m[1]);

            if (stick.Clicked && !previousClicked)
            {
                InputInterface.SendMouseClick(InputInterface.MOUSEEVENTF.LEFTDOWN);
            }

            if (!stick.Clicked && previousClicked)
            {
                InputInterface.SendMouseClick(InputInterface.MOUSEEVENTF.LEFTUP);
            }

            update(stick);
        }
Ejemplo n.º 21
0
        /** <summary> True if the gamepad is disabled. </summary> */
        //private static bool disabled; // I commented 'disabled' out because it is unused.

        #endregion
        //========= CONSTRUCTORS =========
        #region Constructors

        /** <summary> Initializes the gamepad listener. </summary> */
        public static void Initialize()
        {
            // States
            buttons  = new InputControl[4, NumButtons];
            sticks   = new AnalogStick[4, NumSticks];
            triggers = new Trigger[4, NumTriggers];
            //disabled		= false;

            // Setup
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < NumButtons; j++)
                {
                    buttons[i, j] = new InputControl();
                }
                for (int j = 0; j < NumSticks; j++)
                {
                    sticks[i, j] = new AnalogStick();
                }
                for (int j = 0; j < NumTriggers; j++)
                {
                    triggers[i, j] = new Trigger();
                }

                buttons[i, (int)Buttons.LeftStickRight] = sticks[i, (int)Buttons.LeftStick].Right;
                buttons[i, (int)Buttons.LeftStickDown]  = sticks[i, (int)Buttons.LeftStick].Down;
                buttons[i, (int)Buttons.LeftStickLeft]  = sticks[i, (int)Buttons.LeftStick].Left;
                buttons[i, (int)Buttons.LeftStickUp]    = sticks[i, (int)Buttons.LeftStick].Up;

                buttons[i, (int)Buttons.RightStickRight] = sticks[i, (int)Buttons.RightStick].Right;
                buttons[i, (int)Buttons.RightStickDown]  = sticks[i, (int)Buttons.RightStick].Down;
                buttons[i, (int)Buttons.RightStickLeft]  = sticks[i, (int)Buttons.RightStick].Left;
                buttons[i, (int)Buttons.RightStickUp]    = sticks[i, (int)Buttons.RightStick].Up;

                buttons[i, (int)Buttons.DPadRight]             = sticks[i, (int)Buttons.DPad].Right;
                buttons[i, (int)Buttons.DPadDown]              = sticks[i, (int)Buttons.DPad].Down;
                buttons[i, (int)Buttons.DPadLeft]              = sticks[i, (int)Buttons.DPad].Left;
                buttons[i, (int)Buttons.DPadUp]                = sticks[i, (int)Buttons.DPad].Up;
                sticks[i, (int)Buttons.DPad].DirectionDeadZone = Vector2F.Zero;

                buttons[i, (int)Buttons.LeftTriggerButton]  = triggers[i, (int)Buttons.LeftTrigger].Button;
                buttons[i, (int)Buttons.RightTriggerButton] = triggers[i, (int)Buttons.RightTrigger].Button;
            }
        }
Ejemplo n.º 22
0
 public static float GetCurrentValue(PlayerIndex player, AnalogStick stick)
 {
     switch (stick) {
         case AnalogStick.LEFT_X:
             return GamePad.GetState(player).ThumbSticks.Left.X;
         case AnalogStick.LEFT_Y:
             return GamePad.GetState(player).ThumbSticks.Left.Y;
         case AnalogStick.RIGHT_X:
             return GamePad.GetState(player).ThumbSticks.Right.X;
         case AnalogStick.RIGHT_Y:
             return GamePad.GetState(player).ThumbSticks.Right.Y;
         case AnalogStick.LEFT_TRIGGER:
             return GamePad.GetState(player).Triggers.Left;
         case AnalogStick.RIGHT_TRIGGER:
             return GamePad.GetState(player).Triggers.Right;
         default:
             return 0.0f;
     }
 }
        private void ReadCalibrationData()
        {
            byte[] buffer = new byte[16];
            _Wiimote.ReadMemory(0x04A40020, buffer, 0, 16);
            for (int i = 0; i < 16; i++)
            {
                buffer[i] = (byte)((buffer[i] ^ 0x17) + 0x17 & 0xFF);
            }

            AnalogStickCalibration leftStickCalibration = new AnalogStickCalibration((byte)(buffer[1] >> 2), (byte)(buffer[2] >> 2), (byte)(buffer[0] >> 2),
                                                                                     (byte)(buffer[4] >> 2), (byte)(buffer[5] >> 2), (byte)(buffer[3] >> 2));

            _LeftStick = new AnalogStick(leftStickCalibration);

            AnalogStickCalibration rightStickCalibration = new AnalogStickCalibration((byte)(buffer[7] >> 3), (byte)(buffer[8] >> 3), (byte)(buffer[6] >> 3),
                                                                                      (byte)(buffer[10] >> 3), (byte)(buffer[11] >> 3), (byte)(buffer[9] >> 3));

            _RightStick = new AnalogStick(rightStickCalibration);
        }
Ejemplo n.º 24
0
    void InitializeObjects()
    {
        if (!leftStick)
        {
            leftStick = transform.Find("left_analogStick").GetComponent <AnalogStick>();
        }
        if (!rightStick)
        {
            rightStick = transform.Find("right_analogStick").GetComponent <AnalogStick>();
        }
        if (!referencePlane)
        {
            referencePlane = transform.Find("referencePlane").transform;
        }

        if (!leftStickAreaPlane)
        {
            leftStickAreaPlane = transform.Find("leftStickArea").transform;
        }
        if (!rightStickAreaPlane)
        {
            rightStickAreaPlane = transform.Find("rightStickArea").transform;
        }
        if (!buttonsAreaPlane)
        {
            buttonsAreaPlane = transform.Find("buttonsArea").transform;
        }

        if (buttons == null)
        {
            buttons = transform.GetComponentsInChildren <ButtonController>();
        }



        if (!controllerCamera)
        {
            controllerCamera = Camera.main;
        }

        mainCameraTransform = controllerCamera.transform;
    }
Ejemplo n.º 25
0
        private void PolarNumeric_Changed(object sender, EventArgs e)
        {
            ManualX.ValueChanged -= ManualXY_ValueChanged;             //TODO is setting and checking a bool faster than subscription?
            ManualY.ValueChanged -= ManualXY_ValueChanged;

            var rect = PolarRectConversion.PolarDegToRect((double)manualR.Value, (double)manualTheta.Value);

            rect = new Tuple <double, double>(
                rangeAverageX + Math.Ceiling(rect.Item1).Clamp(-127, 127),
                rangeAverageY + Math.Ceiling(rect.Item2).Clamp(-127, 127));
            ManualX.Value        = (decimal)rect.Item1;
            ManualY.Value        = (decimal)rect.Item2;
            AnalogStick.X        = (int)rect.Item1;
            AnalogStick.Y        = (int)rect.Item2;
            AnalogStick.HasValue = true;
            AnalogStick.Refresh();

            ManualX.ValueChanged += ManualXY_ValueChanged;
            ManualY.ValueChanged += ManualXY_ValueChanged;
        }
Ejemplo n.º 26
0
        private void VirtualPadAnalogStick_Load(object sender, EventArgs e)
        {
            AnalogStick.Init(
                Name,
                RangeX,
                !string.IsNullOrEmpty(SecondaryName) ? SecondaryName : Name.Replace("X", "Y"),
                RangeY
                );

            ManualX.Minimum     = RangeX.Min;
            ManualX.Maximum     = RangeX.Max;
            ManualY.Minimum     = RangeY.Min;
            ManualY.Maximum     = RangeY.Max;
            MaxXNumeric.Minimum = 1;
            MaxXNumeric.Maximum = 100;
            MaxYNumeric.Minimum = 1;
            MaxYNumeric.Maximum = 100;

            // these trigger Change events that set the analog stick's values too
            MaxXNumeric.Value = 100;
            MaxYNumeric.Value = 100;
        }
Ejemplo n.º 27
0
 /// <summary>
 ///
 /// </summary>
 public Analog(AnalogStick analogStick)
 {
     Horizontal = Vertical = 0;
     AnalogStick = analogStick;
 }
Ejemplo n.º 28
0
 public void SetPrevious(IController previous)
 {
     AnalogStick.SetPrevious(previous);
 }
Ejemplo n.º 29
0
 public Vector2 getAnalogVector(AnalogStick a, PlayerIndex? pi)
 {
     return controller.getAnalogVector(a, pi);
 }
        private void ReadCalibrationData()
        {
            byte[] buffer = new byte[16];
            _Wiimote.ReadMemory(0x04A40020, buffer, 0, 16);
            for (int i = 0; i < 16; i++)
            {
                buffer[i] = (byte)((buffer[i] ^ 0x17) + 0x17 & 0xFF);
            }

            AnalogStickCalibration leftStickCalibration = new AnalogStickCalibration((byte)(buffer[1] >> 2), (byte)(buffer[2] >> 2), (byte)(buffer[0] >> 2),
                                                               (byte)(buffer[4]>>2),(byte)(buffer[5]>>2),(byte)(buffer[3]>>2));

            _LeftStick = new AnalogStick(leftStickCalibration);

            AnalogStickCalibration rightStickCalibration = new AnalogStickCalibration((byte)(buffer[7] >> 3), (byte)(buffer[8] >> 3), (byte)(buffer[6] >> 3),
                                                               (byte)(buffer[10]>>3),(byte)(buffer[11]>>3),(byte)(buffer[9]>>3));

            _RightStick = new AnalogStick(rightStickCalibration);
        }
Ejemplo n.º 31
0
 public void Clear()
 {
     AnalogStick.Clear();
 }
Ejemplo n.º 32
0
 public AnalogInput(PlayerIndex player, AnalogStick stick)
 {
     this.player = player;
     this.stick = stick;
 }
Ejemplo n.º 33
0
 public override Vector2 getAnalogVector(AnalogStick a, PlayerIndex? pi)
 {
     if (pi.HasValue)
     {
         if (a == AnalogStick.Left)
         {
             return CurrentGamepadStates[(int)pi.Value].ThumbSticks.Left;
         }
         else
         {
             return CurrentGamepadStates[(int)pi.Value].ThumbSticks.Right;
         }
     }
     else
     {
         return getAnalogVector(a, PlayerIndex.One);
     }
 }
Ejemplo n.º 34
0
 public abstract Vector2 getAnalogVector(AnalogStick a, PlayerIndex? pi);
Ejemplo n.º 35
0
        public override Vector2 getAnalogVector(AnalogStick a, PlayerIndex? pi)
        {
            if (a == AnalogStick.Left)
            {
                Vector2 v = Vector2.Zero;

                if (CurrentKeyboardState.IsKeyDown(Keys.A)) v += new Vector2(-1.0f, 0.0f);
                if (CurrentKeyboardState.IsKeyDown(Keys.D)) v += new Vector2(1.0f, 0.0f);
                if (CurrentKeyboardState.IsKeyDown(Keys.S)) v += new Vector2(0.0f, -1.0f);
                if (CurrentKeyboardState.IsKeyDown(Keys.W)) v += new Vector2(0.0f, 1.0f);

                return v;
            }
            else
            {
                Vector2 v = Vector2.Zero;
                if (CurrentKeyboardState.IsKeyDown(Keys.Left)) v += new Vector2(-1.0f, 0.0f);
                if (CurrentKeyboardState.IsKeyDown(Keys.Right)) v += new Vector2(1.0f, 0.0f);
                if (CurrentKeyboardState.IsKeyDown(Keys.Down)) v += new Vector2(0.0f, -1.0f);
                if (CurrentKeyboardState.IsKeyDown(Keys.Up)) v += new Vector2(0.0f, 1.0f);

                return v;
            }
        }
Ejemplo n.º 36
0
 public Vector2 getAnalogVector(AnalogStick a, PlayerIndex?pi)
 {
     return(controller.getAnalogVector(a, pi));
 }
Ejemplo n.º 37
0
 public abstract Vector2 getAnalogVector(AnalogStick a, PlayerIndex?pi);
Ejemplo n.º 38
0
        // read the calibration data and undo obfuscation transformation
        private void ReadCalibrationData()
        {
            byte[] buffer = new byte[16];
            // 0x04A40020 is the address of the calibration data on the wiimote
            _Wiimote.ReadMemory(0x04A40020, buffer, 0, 16);
            for (int i = 0; i < 16; i++)
            {
                buffer[i] = (byte)((buffer[i] ^ 0x17) + 0x17 & 0xFF);
            }

            AccelerometerCalibration accelerometerCalibration = new AccelerometerCalibration(
                 (ushort)((buffer[0] << 2) + ((buffer[3]) & 0x3)),
                 (ushort)((buffer[4] << 2) + ((buffer[7]) & 0x3)),
                 (ushort)((buffer[1] << 2) + ((buffer[3] >> 2) & 0x3)),
                 (ushort)((buffer[5] << 2) + ((buffer[7] >> 2) & 0x3)),
                 (ushort)((buffer[2] << 2) + ((buffer[3] >> 4) & 0x3)),
                 (ushort)((buffer[6] << 2) + ((buffer[7] >> 4) & 0x3)));

            _Accelerometer = new Accelerometer(accelerometerCalibration);

            AnalogStickCalibration stickCalibration = new AnalogStickCalibration(buffer[9], buffer[10], buffer[8],
                                                           buffer[12],buffer[13], buffer[11]);

            _Stick = new AnalogStick(stickCalibration);
        }
Ejemplo n.º 39
0
 public void Set(IController controller)
 {
     AnalogStick.Set(controller);
     SetNumericsFromAnalog();
 }
Ejemplo n.º 40
0
        private PlayerMotionType moveModeWater;                         // For swimming.


        //-----------------------------------------------------------------------------
        // Constructors
        //-----------------------------------------------------------------------------

        public PlayerMoveComponent(Player player)
        {
            this.player = player;

            // Default settings.
            autoAccelerate   = false;
            moveSpeedScale   = 1.0f;
            moveCondition    = PlayerMoveCondition.FreeMovement;
            canLedgeJump     = true;
            canJump          = true;
            canPush          = true;
            canUseWarpPoint  = true;
            isStrafing       = false;
            isSprinting      = false;
            sprintTimer      = 0;
            sprintSpeedScale = 1.5f;

            // Internal.
            allowMovementControl = true;
            moveAxes             = new bool[] { false, false };
            motion               = Vector2F.Zero;
            isMoving             = false;
            velocityPrev         = Vector2F.Zero;
            moveAngle            = Angles.South;
            mode                 = new PlayerMotionType();
            jumpStartTile        = -Point2I.One;
            isCapeDeployed       = false;
            doomedToFallInHole   = false;
            holeTile             = null;
            holeDoomTimer        = 0;
            holeSlipVelocity     = Vector2F.Zero;
            fallingInHole        = false;
            isOnColorBarrier     = false;
            isOnSideScrollLadder = false;
            climbCollisionBox    = new Rectangle2F(-1, -7, 2, 9);

            // Controls.
            analogMode  = false;
            analogStick = GamePad.GetStick(Buttons.LeftStick);
            analogAngle = 0.0f;
            moveButtons = new InputControl[4];
            moveButtons[Directions.Up]    = Controls.Up;
            moveButtons[Directions.Down]  = Controls.Down;
            moveButtons[Directions.Left]  = Controls.Left;
            moveButtons[Directions.Right] = Controls.Right;

            // Normal movement.
            moveModeNormal               = new PlayerMotionType();
            moveModeNormal.MoveSpeed     = 1.0f;
            moveModeNormal.CanLedgeJump  = true;
            moveModeNormal.CanRoomChange = true;

            // Slow movement.
            moveModeSlow           = new PlayerMotionType(moveModeNormal);
            moveModeSlow.MoveSpeed = 0.5f;

            // Grass movement.
            moveModeGrass           = new PlayerMotionType(moveModeNormal);
            moveModeGrass.MoveSpeed = 0.75f;

            // Ice movement.
            moveModeIce                    = new PlayerMotionType();
            moveModeIce.MoveSpeed          = 1.0f;
            moveModeIce.CanLedgeJump       = true;
            moveModeIce.CanRoomChange      = true;
            moveModeIce.IsSlippery         = true;
            moveModeIce.Acceleration       = 0.02f;
            moveModeIce.Deceleration       = 0.05f;
            moveModeIce.MinSpeed           = 0.05f;
            moveModeIce.DirectionSnapCount = 32;

            // Air/jump movement.
            moveModeAir                    = new PlayerMotionType();
            moveModeAir.IsStrafing         = true;
            moveModeAir.MoveSpeed          = 1.0f;
            moveModeAir.CanLedgeJump       = false;
            moveModeAir.CanRoomChange      = false;
            moveModeAir.IsSlippery         = true;
            moveModeAir.Acceleration       = 0.1f;
            moveModeAir.Deceleration       = 0.0f;
            moveModeAir.MinSpeed           = 0.05f;
            moveModeAir.DirectionSnapCount = 8;                     //32;

            // Water/swim movement.
            moveModeWater                    = new PlayerMotionType();
            moveModeWater.MoveSpeed          = 0.5f;
            moveModeWater.CanLedgeJump       = true;
            moveModeWater.CanRoomChange      = true;
            moveModeWater.IsSlippery         = true;
            moveModeWater.Acceleration       = 0.08f;
            moveModeWater.Deceleration       = 0.05f;
            moveModeWater.MinSpeed           = 0.05f;
            moveModeWater.DirectionSnapCount = 32;

            mode = moveModeNormal;
        }