Beispiel #1
0
        public virtual void sixaxisMoved(SixAxisEventArgs arg)
        {
            var deltaX = -arg.SixAxisReadings.accelX;
            var deltaY = -arg.SixAxisReadings.accelY;
            //Console.WriteLine(arg.sixAxis.deltaX);

            double coefficient = Global.GyroSensitivity[deviceNumber] / 100f;
            //Collect rounding errors instead of losing motion.
            var xMotion = coefficient * deltaX;

            xMotion += hRemainder;
            var xAction = (int)xMotion;

            hRemainder += xMotion - xAction;
            hRemainder -= (int)hRemainder;
            var yMotion = coefficient * deltaY;

            yMotion += vRemainder;
            var yAction = (int)yMotion;

            vRemainder += yMotion - yAction;
            vRemainder -= (int)vRemainder;
            if (Global.GyroInvert[deviceNumber] == 2 || Global.GyroInvert[deviceNumber] == 3)
            {
                xAction *= -1;
            }
            if (Global.GyroInvert[deviceNumber] == 1 || Global.GyroInvert[deviceNumber] == 3)
            {
                yAction *= -1;
            }
            if (yAction != 0 || xAction != 0)
            {
                InputMethods.MoveCursorBy(xAction, yAction);
            }

            hDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral;
            vDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral;
        }
Beispiel #2
0
        public void touchesMoved(TouchpadEventArgs arg, bool dragging)
        {
            if (!dragging && arg.TouchReadings.Length != 1 || dragging && arg.TouchReadings.Length < 1)
            {
                return;
            }
            int deltaX, deltaY;

            if (arg.TouchReadings[0].touchID != lastTouchID)
            {
                deltaX = deltaY = 0;
                horizontalRemainder = verticalRemainder = 0.0;
                horizontalDirection = verticalDirection = Direction.Neutral;
                lastTouchID         = arg.TouchReadings[0].touchID;
            }
            else if (Global.TouchpadJitterCompensation[deviceNumber])
            {
                // Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter...

                if (dragging && arg.TouchReadings.Length > 1)
                {
                    deltaX = arg.TouchReadings[1].deltaX;
                    deltaY = arg.TouchReadings[1].deltaY;
                }
                else
                {
                    deltaX = arg.TouchReadings[0].deltaX;
                    deltaY = arg.TouchReadings[0].deltaY;
                }
                // allow only very fine, slow motions, when changing direction, even from neutral
                // TODO maybe just consume it completely?
                if (deltaX <= -1)
                {
                    if (horizontalDirection != Direction.Negative)
                    {
                        deltaX = -1;
                        horizontalRemainder = 0.0;
                    }
                }
                else if (deltaX >= 1)
                {
                    if (horizontalDirection != Direction.Positive)
                    {
                        deltaX = 1;
                        horizontalRemainder = 0.0;
                    }
                }

                if (deltaY <= -1)
                {
                    if (verticalDirection != Direction.Negative)
                    {
                        deltaY            = -1;
                        verticalRemainder = 0.0;
                    }
                }
                else if (deltaY >= 1)
                {
                    if (verticalDirection != Direction.Positive)
                    {
                        deltaY            = 1;
                        verticalRemainder = 0.0;
                    }
                }
            }
            else
            {
                if (dragging && arg.TouchReadings.Length > 1)
                {
                    deltaX = arg.TouchReadings[1].deltaX;
                    deltaY = arg.TouchReadings[1].deltaY;
                }
                else
                {
                    deltaX = arg.TouchReadings[0].deltaX;
                    deltaY = arg.TouchReadings[0].deltaY;
                }
            }

            var coefficient = Global.TouchSensitivity[deviceNumber] / 100.0;
            // Collect rounding errors instead of losing motion.
            var xMotion = coefficient * deltaX;

            if (xMotion > 0.0)
            {
                if (horizontalRemainder > 0.0)
                {
                    xMotion += horizontalRemainder;
                }
            }
            else if (xMotion < 0.0)
            {
                if (horizontalRemainder < 0.0)
                {
                    xMotion += horizontalRemainder;
                }
            }
            var xAction = (int)xMotion;

            horizontalRemainder = xMotion - xAction;

            var yMotion = coefficient * deltaY;

            if (yMotion > 0.0)
            {
                if (verticalRemainder > 0.0)
                {
                    yMotion += verticalRemainder;
                }
            }
            else if (yMotion < 0.0)
            {
                if (verticalRemainder < 0.0)
                {
                    yMotion += verticalRemainder;
                }
            }
            var yAction = (int)yMotion;

            verticalRemainder = yMotion - yAction;

            if (yAction != 0 || xAction != 0)
            {
                InputMethods.MoveCursorBy(xAction, yAction);
            }

            horizontalDirection = xMotion > 0.0 ? Direction.Positive : xMotion < 0.0 ? Direction.Negative : Direction.Neutral;
            verticalDirection   = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral;
        }