コード例 #1
0
ファイル: MouseWheel.cs プロジェクト: xrossb/DS4Windows
        public void touchesMoved(TouchpadEventArgs arg, bool dragging)
        {
            if (arg.touches.Length != 2 || dragging)
            {
                return;
            }

            Touch lastT0 = arg.touches[0].previousTouch;
            Touch lastT1 = arg.touches[1].previousTouch;
            Touch T0     = arg.touches[0];
            Touch T1     = arg.touches[1];

            //mouse wheel 120 == 1 wheel click according to Windows API
            double lastMidX = (lastT0.hwX + lastT1.hwX) / 2d, lastMidY = (lastT0.hwY + lastT1.hwY) / 2d,
                   currentMidX = (T0.hwX + T1.hwX) / 2d, currentMidY = (T0.hwY + T1.hwY) / 2d;
            double coefficient = Global.ScrollSensitivity[deviceNumber];
            // Adjust for touch distance: "standard" distance is 960 pixels, i.e. half the width.  Scroll farther if fingers are farther apart, and vice versa, in linear proportion.
            double touchXDistance = T1.hwX - T0.hwX, touchYDistance = T1.hwY - T0.hwY, touchDistance = Math.Sqrt(touchXDistance * touchXDistance + touchYDistance * touchYDistance);

            coefficient *= touchDistance / 960.0;

            // Collect rounding errors instead of losing motion.
            double xMotion = coefficient * (currentMidX - lastMidX);

            if ((xMotion > 0.0 && horizontalRemainder > 0.0) || (xMotion < 0.0 && horizontalRemainder < 0.0))
            {
                xMotion += horizontalRemainder;
            }
            int xAction = (int)xMotion;

            horizontalRemainder = xMotion - xAction;

            double yMotion = coefficient * (lastMidY - currentMidY);

            if ((yMotion > 0.0 && verticalRemainder > 0.0) || (yMotion < 0.0 && verticalRemainder < 0.0))
            {
                yMotion += verticalRemainder;
            }
            int yAction = (int)yMotion;

            verticalRemainder = yMotion - yAction;

            if (yAction != 0 || xAction != 0)
            {
                InputMethods.MouseWheel(yAction, xAction);
            }
        }
コード例 #2
0
        public virtual void sixaxisMoved(SixAxisEventArgs arg)
        {
            int deltaX = 0, deltaY = 0;

            deltaX = -arg.sixAxis.accelX;
            deltaY = -arg.sixAxis.accelY;
            //Console.WriteLine(arg.sixAxis.deltaX);

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

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

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

            yMotion += vRemainder;
            int 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;
        }
コード例 #3
0
        public virtual void sixaxisMoved(SixAxisEventArgs arg)
        {
            int deltaX = 0, deltaY = 0;

            deltaX = Global.getGyroMouseHorizontalAxis(deviceNumber) == 0 ? arg.sixAxis.gyroYawFull :
                     arg.sixAxis.gyroRollFull;
            deltaY = -arg.sixAxis.gyroPitchFull;
            //tempDouble = arg.sixAxis.elapsed * 0.001 * 200.0; // Base default speed on 5 ms
            tempDouble = arg.sixAxis.elapsed * 200.0; // Base default speed on 5 ms

            gyroSmooth = Global.getGyroSmoothing(deviceNumber);
            double gyroSmoothWeight = 0.0;

            coefficient = (Global.getGyroSensitivity(deviceNumber) * 0.01) * GYRO_MOUSE_COEFFICIENT;
            double offset           = GYRO_MOUSE_OFFSET;

            if (gyroSmooth)
            {
                gyroSmoothWeight = Global.getGyroSmoothingWeight(deviceNumber);
                if (gyroSmoothWeight > 0.0)
                {
                    offset = GYRO_SMOOTH_MOUSE_OFFSET;
                }
            }

            double tempAngle = Math.Atan2(-deltaY, deltaX);
            double normX     = Math.Abs(Math.Cos(tempAngle));
            double normY     = Math.Abs(Math.Sin(tempAngle));
            int    signX     = Math.Sign(deltaX);
            int    signY     = Math.Sign(deltaY);

            if (deltaX == 0 || (hRemainder > 0 != deltaX > 0))
            {
                hRemainder = 0.0;
            }

            if (deltaY == 0 || (vRemainder > 0 != deltaY > 0))
            {
                vRemainder = 0.0;
            }

            int deadzoneX = (int)Math.Abs(normX * GYRO_MOUSE_DEADZONE);
            int deadzoneY = (int)Math.Abs(normY * GYRO_MOUSE_DEADZONE);

            if (Math.Abs(deltaX) > deadzoneX)
            {
                deltaX -= signX * deadzoneX;
            }
            else
            {
                deltaX = 0;
            }

            if (Math.Abs(deltaY) > deadzoneY)
            {
                deltaY -= signY * deadzoneY;
            }
            else
            {
                deltaY = 0;
            }

            double xMotion = deltaX != 0 ? coefficient * (deltaX * tempDouble)
                             + (normX * (offset * signX)) : 0;

            int xAction = 0;

            if (xMotion != 0.0)
            {
                xMotion += hRemainder;
            }
            else
            {
                hRemainder = 0.0;
            }

            verticalScale = Global.getGyroSensVerticalScale(deviceNumber) * 0.01;
            double yMotion = deltaY != 0 ? (coefficient * verticalScale) * (deltaY * tempDouble)
                             + (normY * (offset * signY)) : 0;

            int yAction = 0;

            if (yMotion != 0.0)
            {
                yMotion += vRemainder;
            }
            else
            {
                vRemainder = 0.0;
            }

            if (gyroSmooth)
            {
                int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN;
                xSmoothBuffer[iIndex] = xMotion;
                ySmoothBuffer[iIndex] = yMotion;
                smoothBufferTail      = iIndex + 1;

                double currentWeight = 1.0;
                double finalWeight = 0.0;
                double x_out = 0.0, y_out = 0.0;
                int    idx = 0;
                for (int i = 0; i < SMOOTH_BUFFER_LEN; i++)
                {
                    idx            = (smoothBufferTail - i - 1 + SMOOTH_BUFFER_LEN) % SMOOTH_BUFFER_LEN;
                    x_out         += xSmoothBuffer[idx] * currentWeight;
                    y_out         += ySmoothBuffer[idx] * currentWeight;
                    finalWeight   += currentWeight;
                    currentWeight *= gyroSmoothWeight;
                }

                x_out  /= finalWeight;
                xMotion = x_out;
                y_out  /= finalWeight;
                yMotion = y_out;
            }

            hRemainder = vRemainder = 0.0;
            if (xMotion != 0.0)
            {
                xAction    = (int)xMotion;
                hRemainder = xMotion - xAction;
            }

            if (yMotion != 0.0)
            {
                yAction    = (int)yMotion;
                vRemainder = yMotion - yAction;
            }

            int gyroInvert = Global.getGyroInvert(deviceNumber);

            if ((gyroInvert & 0x02) == 2)
            {
                xAction *= -1;
            }

            if ((gyroInvert & 0x01) == 1)
            {
                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;
        }
コード例 #4
0
        public void TouchMoveCursor(int dx, int dy, bool disableInvert = false)
        {
            double tempAngle           = Math.Atan2(-dy, dx);
            double normX               = Math.Abs(Math.Cos(tempAngle));
            double normY               = Math.Abs(Math.Sin(tempAngle));
            int    signX               = Math.Sign(dx);
            int    signY               = Math.Sign(dy);
            double coefficient         = Global.getTouchSensitivity(deviceNumber) * 0.01;
            bool   jitterCompenstation = Global.getTouchpadJitterCompensation(deviceNumber);

            double xMotion = dx != 0 ?
                             coefficient * dx + (normX * (TOUCHPAD_MOUSE_OFFSET * signX)) : 0.0;

            double yMotion = dy != 0 ?
                             coefficient * dy + (normY * (TOUCHPAD_MOUSE_OFFSET * signY)) : 0.0;

            if (jitterCompenstation)
            {
                double absX = Math.Abs(xMotion);
                if (absX <= normX * 0.15)
                {
                    xMotion = signX * Math.Pow(absX / 0.15f, 1.408) * 0.15;
                }

                double absY = Math.Abs(yMotion);
                if (absY <= normY * 0.15)
                {
                    yMotion = signY * Math.Pow(absY / 0.15f, 1.408) * 0.15;
                }
            }

            // Collect rounding errors instead of losing motion.
            if (xMotion > 0.0 && horizontalRemainder > 0.0)
            {
                xMotion += horizontalRemainder;
            }
            else if (xMotion < 0.0 && horizontalRemainder < 0.0)
            {
                xMotion += horizontalRemainder;
            }
            int xAction = (int)xMotion;

            horizontalRemainder = xMotion - xAction;

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

            verticalRemainder = yMotion - yAction;

            if (disableInvert == false)
            {
                int touchpadInvert = tempInt = Global.getTouchpadInvert(deviceNumber);
                if ((touchpadInvert & 0x02) == 2)
                {
                    xAction *= -1;
                }

                if ((touchpadInvert & 0x01) == 1)
                {
                    yAction *= -1;
                }
            }

            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;
        }
コード例 #5
0
        public void touchesMoved(TouchpadEventArgs arg, bool dragging, bool disableInvert = false)
        {
            int touchesLen = arg.touches.Length;

            if ((!dragging && touchesLen != 1) || (dragging && touchesLen < 1))
            {
                return;
            }

            int deltaX = 0, deltaY = 0;

            if (arg.touches[0].touchID != lastTouchID)
            {
                deltaX = deltaY = 0;
                horizontalRemainder = verticalRemainder = 0.0;
                horizontalDirection = verticalDirection = Direction.Neutral;
                lastTouchID         = arg.touches[0].touchID;
            }
            else
            {
                if (dragging && touchesLen > 1)
                {
                    deltaX = arg.touches[1].deltaX;
                    deltaY = arg.touches[1].deltaY;
                }
                else
                {
                    deltaX = arg.touches[0].deltaX;
                    deltaY = arg.touches[0].deltaY;
                }
            }

            double tempAngle           = Math.Atan2(-deltaY, deltaX);
            double normX               = Math.Abs(Math.Cos(tempAngle));
            double normY               = Math.Abs(Math.Sin(tempAngle));
            int    signX               = Math.Sign(deltaX);
            int    signY               = Math.Sign(deltaY);
            double coefficient         = Global.getTouchSensitivity(deviceNumber) * 0.01;
            bool   jitterCompenstation = Global.getTouchpadJitterCompensation(deviceNumber);

            double xMotion = deltaX != 0 ?
                             coefficient * deltaX + (normX * (TOUCHPAD_MOUSE_OFFSET * signX)) : 0.0;

            double yMotion = deltaY != 0 ?
                             coefficient * deltaY + (normY * (TOUCHPAD_MOUSE_OFFSET * signY)) : 0.0;

            if (jitterCompenstation)
            {
                double absX = Math.Abs(xMotion);
                if (absX <= normX * 0.4)
                {
                    xMotion = signX * Math.Pow(absX / 0.4f, 1.44) * 0.4;
                }

                double absY = Math.Abs(yMotion);
                if (absY <= normY * 0.4)
                {
                    yMotion = signY * Math.Pow(absY / 0.4f, 1.44) * 0.4;
                }
            }

            // Collect rounding errors instead of losing motion.
            if (xMotion > 0.0 && horizontalRemainder > 0.0)
            {
                xMotion += horizontalRemainder;
            }
            else if (xMotion < 0.0 && horizontalRemainder < 0.0)
            {
                xMotion += horizontalRemainder;
            }
            int xAction = (int)xMotion;

            horizontalRemainder = xMotion - xAction;

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

            verticalRemainder = yMotion - yAction;

            if (disableInvert == false)
            {
                int touchpadInvert = tempInt = Global.getTouchpadInvert(deviceNumber);
                if ((touchpadInvert & 0x02) == 2)
                {
                    xAction *= -1;
                }

                if ((touchpadInvert & 0x01) == 1)
                {
                    yAction *= -1;
                }
            }

            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;
        }
コード例 #6
0
ファイル: MouseCursor.cs プロジェクト: mdaouas/DS4Windows
        public void touchesMoved(TouchpadEventArgs arg, bool dragging)
        {
            if ((!dragging && arg.touches.Length != 1) || (dragging && arg.touches.Length < 1))
            {
                return;
            }
            int deltaX, deltaY;

            if (arg.touches[0].touchID != lastTouchID)
            {
                deltaX = deltaY = 0;
                horizontalRemainder = verticalRemainder = 0.0;
                horizontalDirection = verticalDirection = Direction.Neutral;
                lastTouchID         = arg.touches[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.touches.Length > 1)
                {
                    deltaX = arg.touches[1].deltaX;
                    deltaY = arg.touches[1].deltaY;
                }
                else
                {
                    deltaX = arg.touches[0].deltaX;
                    deltaY = arg.touches[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.touches.Length > 1)
                {
                    deltaX = arg.touches[1].deltaX;
                    deltaY = arg.touches[1].deltaY;
                }
                else
                {
                    deltaX = arg.touches[0].deltaX;
                    deltaY = arg.touches[0].deltaY;
                }
            }

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

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

            horizontalRemainder = xMotion - xAction;

            double yMotion = coefficient * deltaY;

            if (yMotion > 0.0)
            {
                if (verticalRemainder > 0.0)
                {
                    yMotion += verticalRemainder;
                }
            }
            else if (yMotion < 0.0)
            {
                if (verticalRemainder < 0.0)
                {
                    yMotion += verticalRemainder;
                }
            }
            int 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;
        }