2017-04-30 15:42:09 +02:00
|
|
|
|
|
2015-02-08 22:51:52 +01:00
|
|
|
|
namespace DS4Windows
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
class MouseCursor
|
|
|
|
|
{
|
|
|
|
|
private readonly int deviceNumber;
|
|
|
|
|
public MouseCursor(int deviceNum)
|
|
|
|
|
{
|
|
|
|
|
deviceNumber = deviceNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep track of remainders when performing moves or we lose fractional parts.
|
|
|
|
|
private double horizontalRemainder = 0.0, verticalRemainder = 0.0;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
private double hRemainder = 0.0, vRemainder = 0.0;
|
2014-03-31 22:33:16 +02:00
|
|
|
|
/** Indicate x/y direction for doing jitter compensation, etc. */
|
|
|
|
|
public enum Direction { Negative, Neutral, Positive }
|
|
|
|
|
// Track direction vector separately and very trivially for now.
|
|
|
|
|
private Direction horizontalDirection = Direction.Neutral, verticalDirection = Direction.Neutral;
|
2015-11-28 06:47:26 +01:00
|
|
|
|
private Direction hDirection = Direction.Neutral, vDirection = Direction.Neutral;
|
|
|
|
|
|
2017-06-24 11:52:39 +02:00
|
|
|
|
double verticalScale = 0.0;
|
|
|
|
|
|
2015-11-28 06:47:26 +01:00
|
|
|
|
public virtual void sixaxisMoved(SixAxisEventArgs arg)
|
|
|
|
|
{
|
|
|
|
|
int deltaX = 0, deltaY = 0;
|
2017-06-22 03:07:21 +02:00
|
|
|
|
deltaX = -arg.sixAxis.gyroXFull;
|
|
|
|
|
deltaY = -arg.sixAxis.gyroYFull;
|
2015-12-13 22:30:54 +01:00
|
|
|
|
//Console.WriteLine(arg.sixAxis.deltaX);
|
|
|
|
|
|
2017-06-27 08:38:01 +02:00
|
|
|
|
double coefficient = (Global.getGyroSensitivity(deviceNumber) * 0.01) * 0.0095;
|
|
|
|
|
double offset = 0.14725;
|
2017-06-22 06:18:15 +02:00
|
|
|
|
double tempAngle = System.Math.Atan2(-deltaY, deltaX);
|
|
|
|
|
double normX = System.Math.Abs(System.Math.Cos(tempAngle));
|
|
|
|
|
double normY = System.Math.Abs(System.Math.Sin(tempAngle));
|
|
|
|
|
int signX = System.Math.Sign(deltaX);
|
|
|
|
|
int signY = System.Math.Sign(deltaY);
|
2017-06-22 03:07:21 +02:00
|
|
|
|
|
|
|
|
|
if ((hRemainder > 0) != (deltaX > 0))
|
|
|
|
|
{
|
|
|
|
|
hRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((vRemainder > 0) != (deltaY > 0))
|
|
|
|
|
{
|
|
|
|
|
vRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-25 04:09:03 +02:00
|
|
|
|
int deadzone = 12;
|
2017-06-22 06:18:15 +02:00
|
|
|
|
//int deadzone = 0;
|
|
|
|
|
int deadzoneX = (int)System.Math.Abs(normX * deadzone);
|
|
|
|
|
int deadzoneY = (int)System.Math.Abs(normY * deadzone);
|
|
|
|
|
|
|
|
|
|
if (System.Math.Abs(deltaX) > deadzoneX)
|
|
|
|
|
{
|
|
|
|
|
deltaX -= signX * deadzoneX;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deltaX = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (System.Math.Abs(deltaY) > deadzoneY)
|
|
|
|
|
{
|
|
|
|
|
deltaY -= signY * deadzoneY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deltaY = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double xMotion = deltaX != 0 ? coefficient * deltaX + (normX * (offset * signX)) : 0;
|
|
|
|
|
int xAction = 0;
|
|
|
|
|
if (xMotion != 0.0)
|
|
|
|
|
{
|
|
|
|
|
xMotion += hRemainder;
|
|
|
|
|
xAction = (int)xMotion;
|
|
|
|
|
hRemainder = xMotion - xAction;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 03:07:21 +02:00
|
|
|
|
//hRemainder -= (int)hRemainder;
|
2017-06-25 04:09:03 +02:00
|
|
|
|
verticalScale = Global.getGyroSensVerticalScale(deviceNumber) * 0.01;
|
2017-06-24 11:52:39 +02:00
|
|
|
|
double yMotion = deltaY != 0 ? (coefficient * verticalScale) * deltaY + (normY * (offset * signY)) : 0;
|
2017-06-22 06:18:15 +02:00
|
|
|
|
int yAction = 0;
|
|
|
|
|
if (yMotion != 0.0)
|
|
|
|
|
{
|
|
|
|
|
yMotion += vRemainder;
|
|
|
|
|
yAction = (int)yMotion;
|
|
|
|
|
vRemainder = yMotion - yAction;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 03:07:21 +02:00
|
|
|
|
//vRemainder -= (int)vRemainder;
|
2017-04-16 07:15:54 +02:00
|
|
|
|
|
2017-06-24 11:52:39 +02:00
|
|
|
|
int gyroInvert = Global.getGyroInvert(deviceNumber);
|
2017-04-16 07:15:54 +02:00
|
|
|
|
if (gyroInvert == 2 || gyroInvert == 3)
|
2015-11-28 06:47:26 +01:00
|
|
|
|
xAction *= -1;
|
2017-04-16 07:15:54 +02:00
|
|
|
|
|
|
|
|
|
if (gyroInvert == 1 || gyroInvert == 3)
|
2015-11-28 06:47:26 +01:00
|
|
|
|
yAction *= -1;
|
2017-04-16 07:15:54 +02:00
|
|
|
|
|
2015-11-28 06:47:26 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
2014-03-29 06:56:30 +01:00
|
|
|
|
|
2017-06-22 16:36:40 +02:00
|
|
|
|
public void mouseRemainderReset()
|
|
|
|
|
{
|
|
|
|
|
hRemainder = vRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 06:56:30 +01:00
|
|
|
|
public void touchesBegan(TouchpadEventArgs arg)
|
|
|
|
|
{
|
|
|
|
|
if (arg.touches.Length == 1)
|
2014-03-31 22:33:16 +02:00
|
|
|
|
{
|
2014-03-29 06:56:30 +01:00
|
|
|
|
horizontalRemainder = verticalRemainder = 0.0;
|
2014-03-31 22:33:16 +02:00
|
|
|
|
horizontalDirection = verticalDirection = Direction.Neutral;
|
|
|
|
|
}
|
2014-03-29 06:56:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte lastTouchID;
|
2015-06-01 21:04:22 +02:00
|
|
|
|
public void touchesMoved(TouchpadEventArgs arg, bool dragging)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
2017-04-16 07:15:54 +02:00
|
|
|
|
int touchesLen = arg.touches.Length;
|
|
|
|
|
if ((!dragging && touchesLen != 1) || (dragging && touchesLen < 1))
|
2014-03-29 06:56:30 +01:00
|
|
|
|
return;
|
2017-04-16 07:15:54 +02:00
|
|
|
|
|
2014-03-29 06:56:30 +01:00
|
|
|
|
int deltaX, deltaY;
|
|
|
|
|
if (arg.touches[0].touchID != lastTouchID)
|
|
|
|
|
{
|
|
|
|
|
deltaX = deltaY = 0;
|
|
|
|
|
horizontalRemainder = verticalRemainder = 0.0;
|
2014-03-31 22:33:16 +02:00
|
|
|
|
horizontalDirection = verticalDirection = Direction.Neutral;
|
2014-03-29 06:56:30 +01:00
|
|
|
|
lastTouchID = arg.touches[0].touchID;
|
|
|
|
|
}
|
2015-02-08 22:51:52 +01:00
|
|
|
|
else if (Global.TouchpadJitterCompensation[deviceNumber])
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
// Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter...
|
2017-04-16 07:15:54 +02:00
|
|
|
|
if (dragging && touchesLen > 1)
|
2015-06-01 21:04:22 +02:00
|
|
|
|
{
|
|
|
|
|
deltaX = arg.touches[1].deltaX;
|
|
|
|
|
deltaY = arg.touches[1].deltaY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deltaX = arg.touches[0].deltaX;
|
|
|
|
|
deltaY = arg.touches[0].deltaY;
|
|
|
|
|
}
|
2017-04-16 07:15:54 +02:00
|
|
|
|
|
2014-04-27 21:32:09 +02:00
|
|
|
|
// allow only very fine, slow motions, when changing direction, even from neutral
|
|
|
|
|
// TODO maybe just consume it completely?
|
|
|
|
|
if (deltaX <= -1)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if (horizontalDirection != Direction.Negative)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaX = -1;
|
|
|
|
|
horizontalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
else if (deltaX >= 1)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if (horizontalDirection != Direction.Positive)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaX = 1;
|
|
|
|
|
horizontalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if (deltaY <= -1)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if (verticalDirection != Direction.Negative)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaY = -1;
|
|
|
|
|
verticalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
else if (deltaY >= 1)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if (verticalDirection != Direction.Positive)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaY = 1;
|
|
|
|
|
verticalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-04-16 07:15:54 +02:00
|
|
|
|
if (dragging && touchesLen > 1)
|
2015-06-01 21:04:22 +02:00
|
|
|
|
{
|
|
|
|
|
deltaX = arg.touches[1].deltaX;
|
|
|
|
|
deltaY = arg.touches[1].deltaY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deltaX = arg.touches[0].deltaX;
|
|
|
|
|
deltaY = arg.touches[0].deltaY;
|
|
|
|
|
}
|
2014-03-29 06:56:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-08 22:51:52 +01:00
|
|
|
|
double coefficient = Global.TouchSensitivity[deviceNumber] / 100.0;
|
2014-03-29 06:56:30 +01:00
|
|
|
|
// 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);
|
2014-03-31 22:33:16 +02:00
|
|
|
|
|
2014-04-27 21:32:09 +02:00
|
|
|
|
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;
|
2014-03-29 06:56:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|