Start using 128 as proper axis midpoint. Changed some mapping routines.

Helps with mouse cursor in Civ 4
This commit is contained in:
Travis Nickles 2019-01-13 13:32:38 -06:00
parent ccfc74e2fa
commit a8a55b46dc
3 changed files with 141 additions and 137 deletions

View File

@ -515,26 +515,26 @@ namespace DS4Windows
int lsMaxZone = getLSMaxzone(device); int lsMaxZone = getLSMaxzone(device);
if (lsDeadzone > 0 || lsAntiDead > 0 || lsMaxZone != 100) if (lsDeadzone > 0 || lsAntiDead > 0 || lsMaxZone != 100)
{ {
double lsSquared = Math.Pow(cState.LX - 127.5f, 2) + Math.Pow(cState.LY - 127.5f, 2); double lsSquared = Math.Pow(cState.LX - 128f, 2) + Math.Pow(cState.LY - 128f, 2);
double lsDeadzoneSquared = Math.Pow(lsDeadzone, 2); double lsDeadzoneSquared = Math.Pow(lsDeadzone, 2);
if (lsDeadzone > 0 && lsSquared <= lsDeadzoneSquared) if (lsDeadzone > 0 && lsSquared <= lsDeadzoneSquared)
{ {
dState.LX = 127; dState.LX = 128;
dState.LY = 127; dState.LY = 128;
} }
else if ((lsDeadzone > 0 && lsSquared > lsDeadzoneSquared) || lsAntiDead > 0 || lsMaxZone != 100) else if ((lsDeadzone > 0 && lsSquared > lsDeadzoneSquared) || lsAntiDead > 0 || lsMaxZone != 100)
{ {
double r = Math.Atan2(-(dState.LY - 127.5), (dState.LX - 127.5)); double r = Math.Atan2(-(dState.LY - 128.0), (dState.LX - 128.0));
double maxXValue = dState.LX >= 127.5 ? 127.5 : -127.5; double maxXValue = dState.LX >= 128.0 ? 127.0 : -128;
double maxYValue = dState.LY >= 127.5 ? 127.5 : -127.5; double maxYValue = dState.LY >= 128.0 ? 127.0 : -128;
double ratio = lsMaxZone / 100.0; double ratio = lsMaxZone / 100.0;
double maxZoneXNegValue = (ratio * -127.5) + 127.5; double maxZoneXNegValue = (ratio * -128) + 128;
double maxZoneXPosValue = (ratio * 127.5) + 127.5; double maxZoneXPosValue = (ratio * 127) + 128;
double maxZoneYNegValue = maxZoneXNegValue; double maxZoneYNegValue = maxZoneXNegValue;
double maxZoneYPosValue = maxZoneXPosValue; double maxZoneYPosValue = maxZoneXPosValue;
double maxZoneX = dState.LX >= 127.5 ? (maxZoneXPosValue - 127.5) : (maxZoneXNegValue - 127.5); double maxZoneX = dState.LX >= 128.0 ? (maxZoneXPosValue - 128.0) : (maxZoneXNegValue - 128.0);
double maxZoneY = dState.LY >= 127.5 ? (maxZoneYPosValue - 127.5) : (maxZoneYNegValue - 127.5); double maxZoneY = dState.LY >= 128.0 ? (maxZoneYPosValue - 128.0) : (maxZoneYNegValue - 128.0);
double tempLsXDead = 0.0, tempLsYDead = 0.0; double tempLsXDead = 0.0, tempLsYDead = 0.0;
double tempOutputX = 0.0, tempOutputY = 0.0; double tempOutputX = 0.0, tempOutputY = 0.0;
@ -547,16 +547,16 @@ namespace DS4Windows
{ {
double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue);
double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue);
tempOutputX = ((currentX - 127.5 - tempLsXDead) / (maxZoneX - tempLsXDead)); tempOutputX = ((currentX - 128.0 - tempLsXDead) / (maxZoneX - tempLsXDead));
tempOutputY = ((currentY - 127.5 - tempLsYDead) / (maxZoneY - tempLsYDead)); tempOutputY = ((currentY - 128.0 - tempLsYDead) / (maxZoneY - tempLsYDead));
} }
} }
else else
{ {
double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue);
double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue);
tempOutputX = (currentX - 127.5) / maxZoneX; tempOutputX = (currentX - 128.0) / maxZoneX;
tempOutputY = (currentY - 127.5) / maxZoneY; tempOutputY = (currentY - 128.0) / maxZoneY;
} }
double tempLsXAntiDeadPercent = 0.0, tempLsYAntiDeadPercent = 0.0; double tempLsXAntiDeadPercent = 0.0, tempLsYAntiDeadPercent = 0.0;
@ -568,20 +568,20 @@ namespace DS4Windows
if (tempOutputX > 0.0) if (tempOutputX > 0.0)
{ {
dState.LX = (byte)((((1.0 - tempLsXAntiDeadPercent) * tempOutputX + tempLsXAntiDeadPercent)) * maxXValue + 127.5); dState.LX = (byte)((((1.0 - tempLsXAntiDeadPercent) * tempOutputX + tempLsXAntiDeadPercent)) * maxXValue + 128.0);
} }
else else
{ {
dState.LX = 127; dState.LX = 128;
} }
if (tempOutputY > 0.0) if (tempOutputY > 0.0)
{ {
dState.LY = (byte)((((1.0 - tempLsYAntiDeadPercent) * tempOutputY + tempLsYAntiDeadPercent)) * maxYValue + 127.5); dState.LY = (byte)((((1.0 - tempLsYAntiDeadPercent) * tempOutputY + tempLsYAntiDeadPercent)) * maxYValue + 128.0);
} }
else else
{ {
dState.LY = 127; dState.LY = 128;
} }
} }
} }
@ -591,26 +591,26 @@ namespace DS4Windows
int rsMaxZone = getRSMaxzone(device); int rsMaxZone = getRSMaxzone(device);
if (rsDeadzone > 0 || rsAntiDead > 0 || rsMaxZone != 100) if (rsDeadzone > 0 || rsAntiDead > 0 || rsMaxZone != 100)
{ {
double rsSquared = Math.Pow(cState.RX - 127.5, 2) + Math.Pow(cState.RY - 127.5, 2); double rsSquared = Math.Pow(cState.RX - 128.0, 2) + Math.Pow(cState.RY - 128.0, 2);
double rsDeadzoneSquared = Math.Pow(rsDeadzone, 2); double rsDeadzoneSquared = Math.Pow(rsDeadzone, 2);
if (rsDeadzone > 0 && rsSquared <= rsDeadzoneSquared) if (rsDeadzone > 0 && rsSquared <= rsDeadzoneSquared)
{ {
dState.RX = 127; dState.RX = 128;
dState.RY = 127; dState.RY = 128;
} }
else if ((rsDeadzone > 0 && rsSquared > rsDeadzoneSquared) || rsAntiDead > 0 || rsMaxZone != 100) else if ((rsDeadzone > 0 && rsSquared > rsDeadzoneSquared) || rsAntiDead > 0 || rsMaxZone != 100)
{ {
double r = Math.Atan2(-(dState.RY - 127.5), (dState.RX - 127.5)); double r = Math.Atan2(-(dState.RY - 128.0), (dState.RX - 128.0));
double maxXValue = dState.RX >= 127.5 ? 127.5 : -127.5; double maxXValue = dState.RX >= 128.0 ? 127 : -128;
double maxYValue = dState.RY >= 127.5 ? 127.5 : -127.5; double maxYValue = dState.RY >= 128.0 ? 127 : -128;
double ratio = rsMaxZone / 100.0; double ratio = rsMaxZone / 100.0;
double maxZoneXNegValue = (ratio * -127.5) + 127.5; double maxZoneXNegValue = (ratio * -128.0) + 128.0;
double maxZoneXPosValue = (ratio * 127.5) + 127.5; double maxZoneXPosValue = (ratio * 127.0) + 128.0;
double maxZoneYNegValue = maxZoneXNegValue; double maxZoneYNegValue = maxZoneXNegValue;
double maxZoneYPosValue = maxZoneXPosValue; double maxZoneYPosValue = maxZoneXPosValue;
double maxZoneX = dState.RX >= 127.5 ? (maxZoneXPosValue - 127.5) : (maxZoneXNegValue - 127.5); double maxZoneX = dState.RX >= 128.0 ? (maxZoneXPosValue - 128.0) : (maxZoneXNegValue - 128.0);
double maxZoneY = dState.RY >= 127.5 ? (maxZoneYPosValue - 127.5) : (maxZoneYNegValue - 127.5); double maxZoneY = dState.RY >= 128.0 ? (maxZoneYPosValue - 128.0) : (maxZoneYNegValue - 128.0);
double tempRsXDead = 0.0, tempRsYDead = 0.0; double tempRsXDead = 0.0, tempRsYDead = 0.0;
double tempOutputX = 0.0, tempOutputY = 0.0; double tempOutputX = 0.0, tempOutputY = 0.0;
@ -624,8 +624,8 @@ namespace DS4Windows
double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue);
double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue);
tempOutputX = ((currentX - 127.5 - tempRsXDead) / (maxZoneX - tempRsXDead)); tempOutputX = ((currentX - 128.0 - tempRsXDead) / (maxZoneX - tempRsXDead));
tempOutputY = ((currentY - 127.5 - tempRsYDead) / (maxZoneY - tempRsYDead)); tempOutputY = ((currentY - 128.0 - tempRsYDead) / (maxZoneY - tempRsYDead));
} }
} }
else else
@ -633,8 +633,8 @@ namespace DS4Windows
double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue); double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue);
double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue); double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue);
tempOutputX = (currentX - 127.5) / maxZoneX; tempOutputX = (currentX - 128.0) / maxZoneX;
tempOutputY = (currentY - 127.5) / maxZoneY; tempOutputY = (currentY - 128.0) / maxZoneY;
} }
double tempRsXAntiDeadPercent = 0.0, tempRsYAntiDeadPercent = 0.0; double tempRsXAntiDeadPercent = 0.0, tempRsYAntiDeadPercent = 0.0;
@ -646,20 +646,20 @@ namespace DS4Windows
if (tempOutputX > 0.0) if (tempOutputX > 0.0)
{ {
dState.RX = (byte)((((1.0 - tempRsXAntiDeadPercent) * tempOutputX + tempRsXAntiDeadPercent)) * maxXValue + 127.5); dState.RX = (byte)((((1.0 - tempRsXAntiDeadPercent) * tempOutputX + tempRsXAntiDeadPercent)) * maxXValue + 128.0);
} }
else else
{ {
dState.RX = 127; dState.RX = 128;
} }
if (tempOutputY > 0.0) if (tempOutputY > 0.0)
{ {
dState.RY = (byte)((((1.0 - tempRsYAntiDeadPercent) * tempOutputY + tempRsYAntiDeadPercent)) * maxYValue + 127.5); dState.RY = (byte)((((1.0 - tempRsYAntiDeadPercent) * tempOutputY + tempRsYAntiDeadPercent)) * maxYValue + 128.0);
} }
else else
{ {
dState.RY = 127; dState.RY = 128;
} }
} }
} }
@ -743,15 +743,15 @@ namespace DS4Windows
double lsSens = getLSSens(device); double lsSens = getLSSens(device);
if (lsSens != 1.0) if (lsSens != 1.0)
{ {
dState.LX = (byte)Global.Clamp(0, lsSens * (dState.LX - 127.5) + 127.5, 255); dState.LX = (byte)Global.Clamp(0, lsSens * (dState.LX - 128.0) + 127.0, 255);
dState.LY = (byte)Global.Clamp(0, lsSens * (dState.LY - 127.5) + 127.5, 255); dState.LY = (byte)Global.Clamp(0, lsSens * (dState.LY - 128.0) + 127.0, 255);
} }
double rsSens = getRSSens(device); double rsSens = getRSSens(device);
if (rsSens != 1.0) if (rsSens != 1.0)
{ {
dState.RX = (byte)Global.Clamp(0, rsSens * (dState.RX - 127.5) + 127.5, 255); dState.RX = (byte)Global.Clamp(0, rsSens * (dState.RX - 128.0) + 127.0, 255);
dState.RY = (byte)Global.Clamp(0, rsSens * (dState.RY - 127.5) + 127.5, 255); dState.RY = (byte)Global.Clamp(0, rsSens * (dState.RY - 128.0) + 127.0, 255);
} }
double l2Sens = getL2Sens(device); double l2Sens = getL2Sens(device);
@ -765,8 +765,10 @@ namespace DS4Windows
int lsOutCurveMode = lsOutCurveModeArray[device] = getLsOutCurveMode(device); int lsOutCurveMode = lsOutCurveModeArray[device] = getLsOutCurveMode(device);
if (lsOutCurveMode > 0) if (lsOutCurveMode > 0)
{ {
double tempX = (dState.LX - 127.5) / 127.5; double capX = dState.LX >= 128 ? 127.0 : 128.0;
double tempY = (dState.LY - 127.5) / 127.5; double capY = dState.LY >= 128 ? 127.0 : 128.0;
double tempX = (dState.LX - 128.0) / capX;
double tempY = (dState.LY - 128.0) / capY;
double signX = tempX >= 0.0 ? 1.0 : -1.0; double signX = tempX >= 0.0 ? 1.0 : -1.0;
double signY = tempY >= 0.0 ? 1.0 : -1.0; double signY = tempY >= 0.0 ? 1.0 : -1.0;
@ -803,30 +805,32 @@ namespace DS4Windows
outputY = (absY * 1.7296) - 0.7296; outputY = (absY * 1.7296) - 0.7296;
} }
dState.LX = (byte)(outputX * signX * 127.5 + 127.5); dState.LX = (byte)(outputX * signX * capX + 128.0);
dState.LY = (byte)(outputY * signY * 127.5 + 127.5); dState.LY = (byte)(outputY * signY * capY + 128.0);
} }
else if (lsOutCurveMode == 2) else if (lsOutCurveMode == 2)
{ {
double outputX = tempX * tempX; double outputX = tempX * tempX;
double outputY = tempY * tempY; double outputY = tempY * tempY;
dState.LX = (byte)(outputX * signX * 127.5 + 127.5); dState.LX = (byte)(outputX * signX * capX + 128.0);
dState.LY = (byte)(outputY * signY * 127.5 + 127.5); dState.LY = (byte)(outputY * signY * capY + 128.0);
} }
else if (lsOutCurveMode == 3) else if (lsOutCurveMode == 3)
{ {
double outputX = tempX * tempX * tempX; double outputX = tempX * tempX * tempX;
double outputY = tempY * tempY * tempY; double outputY = tempY * tempY * tempY;
dState.LX = (byte)(outputX * 127.5 + 127.5); dState.LX = (byte)(outputX * capX + 128.0);
dState.LY = (byte)(outputY * 127.5 + 127.5); dState.LY = (byte)(outputY * capY + 128.0);
} }
} }
int rsOutCurveMode = rsOutCurveModeArray[device] = getRsOutCurveMode(device); int rsOutCurveMode = rsOutCurveModeArray[device] = getRsOutCurveMode(device);
if (rsOutCurveMode > 0) if (rsOutCurveMode > 0)
{ {
double tempX = (dState.RX - 127.5) / 127.5; double capX = dState.RX >= 128 ? 127.0 : 128.0;
double tempY = (dState.RY - 127.5) / 127.5; double capY = dState.RY >= 128 ? 127.0 : 128.0;
double tempX = (dState.RX - 128.0) / capX;
double tempY = (dState.RY - 128.0) / capY;
double signX = tempX >= 0.0 ? 1.0 : -1.0; double signX = tempX >= 0.0 ? 1.0 : -1.0;
double signY = tempY >= 0.0 ? 1.0 : -1.0; double signY = tempY >= 0.0 ? 1.0 : -1.0;
@ -863,22 +867,22 @@ namespace DS4Windows
outputY = (absY * 1.7296) - 0.7296; outputY = (absY * 1.7296) - 0.7296;
} }
dState.RX = (byte)(outputX * signX * 127.5 + 127.5); dState.RX = (byte)(outputX * signX * capX + 128.0);
dState.RY = (byte)(outputY * signY * 127.5 + 127.5); dState.RY = (byte)(outputY * signY * capY + 128.0);
} }
else if (rsOutCurveMode == 2) else if (rsOutCurveMode == 2)
{ {
double outputX = tempX * tempX; double outputX = tempX * tempX;
double outputY = tempY * tempY; double outputY = tempY * tempY;
dState.RX = (byte)(outputX * signX * 127.5 + 127.5); dState.RX = (byte)(outputX * signX * capX + 128.0);
dState.RY = (byte)(outputY * signY * 127.5 + 127.5); dState.RY = (byte)(outputY * signY * capY + 128.0);
} }
else if (rsOutCurveMode == 3) else if (rsOutCurveMode == 3)
{ {
double outputX = tempX * tempX * tempX; double outputX = tempX * tempX * tempX;
double outputY = tempY * tempY * tempY; double outputY = tempY * tempY * tempY;
dState.RX = (byte)(outputX * 127.5 + 127.5); dState.RX = (byte)(outputX * capX + 128.0);
dState.RY = (byte)(outputY * 127.5 + 127.5); dState.RY = (byte)(outputY * capY + 128.0);
} }
} }
@ -1113,10 +1117,10 @@ namespace DS4Windows
Mouse tp, ControlService ctrl) Mouse tp, ControlService ctrl)
{ {
/* TODO: This method is slow sauce. Find ways to speed up action execution */ /* TODO: This method is slow sauce. Find ways to speed up action execution */
MappedState.LX = 127; MappedState.LX = 128;
MappedState.LY = 127; MappedState.LY = 128;
MappedState.RX = 127; MappedState.RX = 128;
MappedState.RY = 127; MappedState.RY = 128;
double tempMouseDeltaX = 0.0; double tempMouseDeltaX = 0.0;
double tempMouseDeltaY = 0.0; double tempMouseDeltaY = 0.0;
int mouseDeltaX = 0; int mouseDeltaX = 0;
@ -2511,9 +2515,9 @@ namespace DS4Windows
{ {
case DS4Controls.LXNeg: case DS4Controls.LXNeg:
{ {
if (cState.LX < 127 - deadzoneL) if (cState.LX < 128 - deadzoneL)
{ {
double diff = -(cState.LX - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL); double diff = -(cState.LX - 128 - deadzoneL) / (double)(0 - 128 - deadzoneL);
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET; //tempMouseOffsetX = MOUSESTICKOFFSET;
tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET; tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
@ -2526,9 +2530,9 @@ namespace DS4Windows
} }
case DS4Controls.LXPos: case DS4Controls.LXPos:
{ {
if (cState.LX > 127 + deadzoneL) if (cState.LX > 128 + deadzoneL)
{ {
double diff = (cState.LX - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL); double diff = (cState.LX - 128 + deadzoneL) / (double)(255 - 128 + deadzoneL);
tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET; tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET; //tempMouseOffsetX = MOUSESTICKOFFSET;
@ -2541,9 +2545,9 @@ namespace DS4Windows
} }
case DS4Controls.RXNeg: case DS4Controls.RXNeg:
{ {
if (cState.RX < 127 - deadzoneR) if (cState.RX < 128 - deadzoneR)
{ {
double diff = -(cState.RX - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR); double diff = -(cState.RX - 128 - deadzoneR) / (double)(0 - 128 - deadzoneR);
tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET; tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET; //tempMouseOffsetX = MOUSESTICKOFFSET;
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
@ -2556,9 +2560,9 @@ namespace DS4Windows
} }
case DS4Controls.RXPos: case DS4Controls.RXPos:
{ {
if (cState.RX > 127 + deadzoneR) if (cState.RX > 128 + deadzoneR)
{ {
double diff = (cState.RX - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR); double diff = (cState.RX - 128 + deadzoneR) / (double)(255 - 128 + deadzoneR);
tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET; tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
//tempMouseOffsetX = MOUSESTICKOFFSET; //tempMouseOffsetX = MOUSESTICKOFFSET;
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
@ -2571,9 +2575,9 @@ namespace DS4Windows
} }
case DS4Controls.LYNeg: case DS4Controls.LYNeg:
{ {
if (cState.LY < 127 - deadzoneL) if (cState.LY < 128 - deadzoneL)
{ {
double diff = -(cState.LY - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL); double diff = -(cState.LY - 128 - deadzoneL) / (double)(0 - 128 - deadzoneL);
tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET; tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET; //tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
@ -2586,9 +2590,9 @@ namespace DS4Windows
} }
case DS4Controls.LYPos: case DS4Controls.LYPos:
{ {
if (cState.LY > 127 + deadzoneL) if (cState.LY > 128 + deadzoneL)
{ {
double diff = (cState.LY - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL); double diff = (cState.LY - 128 + deadzoneL) / (double)(255 - 128 + deadzoneL);
tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET; tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET; //tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
@ -2601,9 +2605,9 @@ namespace DS4Windows
} }
case DS4Controls.RYNeg: case DS4Controls.RYNeg:
{ {
if (cState.RY < 127 - deadzoneR) if (cState.RY < 128 - deadzoneR)
{ {
double diff = -(cState.RY - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR); double diff = -(cState.RY - 128 - deadzoneR) / (double)(0 - 128 - deadzoneR);
tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET; tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET; //tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
@ -2616,9 +2620,9 @@ namespace DS4Windows
} }
case DS4Controls.RYPos: case DS4Controls.RYPos:
{ {
if (cState.RY > 127 + deadzoneR) if (cState.RY > 128 + deadzoneR)
{ {
double diff = (cState.RY - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR); double diff = (cState.RY - 128 + deadzoneR) / (double)(255 - 128 + deadzoneR);
tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET; tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
//tempMouseOffsetY = MOUSESTICKOFFSET; //tempMouseOffsetY = MOUSESTICKOFFSET;
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET; //tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
@ -2769,11 +2773,11 @@ namespace DS4Windows
switch (control) switch (control)
{ {
case DS4Controls.LXNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break; case DS4Controls.LXNeg: result = (byte)(axisValue - 128.0f >= 0 ? 0 : -(axisValue - 128.0f) * 1.9921875f); break;
case DS4Controls.LYNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break; case DS4Controls.LYNeg: result = (byte)(axisValue - 128.0f >= 0 ? 0 : -(axisValue - 128.0f) * 1.9921875f); break;
case DS4Controls.RXNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break; case DS4Controls.RXNeg: result = (byte)(axisValue - 128.0f >= 0 ? 0 : -(axisValue - 128.0f) * 1.9921875f); break;
case DS4Controls.RYNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break; case DS4Controls.RYNeg: result = (byte)(axisValue - 128.0f >= 0 ? 0 : -(axisValue - 128.0f) * 1.9921875f); break;
default: result = (byte)(axisValue - 127.5f < 0 ? 0 : (axisValue - 127.5f) * 2); break; default: result = (byte)(axisValue - 128.0f < 0 ? 0 : (axisValue - 128.0f) * 2.0078740157480315f); break;
} }
} }
else if (controlType == DS4StateFieldMapping.ControlType.Trigger) else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
@ -2868,14 +2872,14 @@ namespace DS4Windows
{ {
switch (control) switch (control)
{ {
case DS4Controls.LXNeg: result = (byte)(cState.LX - 127.5f > 0 ? 0 : -(cState.LX - 127.5f) * 2); break; case DS4Controls.LXNeg: result = (byte)(cState.LX - 128.0f >= 0 ? 0 : -(cState.LX - 128.0f) * 1.9921875f); break;
case DS4Controls.LYNeg: result = (byte)(cState.LY - 127.5f > 0 ? 0 : -(cState.LY - 127.5f) * 2); break; case DS4Controls.LYNeg: result = (byte)(cState.LY - 128.0f >= 0 ? 0 : -(cState.LY - 128.0f) * 1.9921875f); break;
case DS4Controls.RXNeg: result = (byte)(cState.RX - 127.5f > 0 ? 0 : -(cState.RX - 127.5f) * 2); break; case DS4Controls.RXNeg: result = (byte)(cState.RX - 128.0f >= 0 ? 0 : -(cState.RX - 128.0f) * 1.9921875f); break;
case DS4Controls.RYNeg: result = (byte)(cState.RY - 127.5f > 0 ? 0 : -(cState.RY - 127.5f) * 2); break; case DS4Controls.RYNeg: result = (byte)(cState.RY - 128.0f >= 0 ? 0 : -(cState.RY - 128.0f) * 1.9921875f); break;
case DS4Controls.LXPos: result = (byte)(cState.LX - 127.5f < 0 ? 0 : (cState.LX - 127.5f) * 2); break; case DS4Controls.LXPos: result = (byte)(cState.LX - 128.0f < 0 ? 0 : (cState.LX - 128.0f) * 2.0078740157480315f); break;
case DS4Controls.LYPos: result = (byte)(cState.LY - 127.5f < 0 ? 0 : (cState.LY - 127.5f) * 2); break; case DS4Controls.LYPos: result = (byte)(cState.LY - 128.0f < 0 ? 0 : (cState.LY - 128.0f) * 2.0078740157480315f); break;
case DS4Controls.RXPos: result = (byte)(cState.RX - 127.5f < 0 ? 0 : (cState.RX - 127.5f) * 2); break; case DS4Controls.RXPos: result = (byte)(cState.RX - 128.0f < 0 ? 0 : (cState.RX - 128.0f) * 2.0078740157480315f); break;
case DS4Controls.RYPos: result = (byte)(cState.RY - 127.5f < 0 ? 0 : (cState.RY - 127.5f) * 2); break; case DS4Controls.RYPos: result = (byte)(cState.RY - 128.0f < 0 ? 0 : (cState.RY - 128.0f) * 2.0078740157480315f); break;
default: break; default: break;
} }
} }
@ -2996,14 +3000,14 @@ namespace DS4Windows
{ {
switch (control) switch (control)
{ {
case DS4Controls.LXNeg: result = cState.LX < 127 - 55; break; case DS4Controls.LXNeg: result = cState.LX < 128 - 55; break;
case DS4Controls.LYNeg: result = cState.LY < 127 - 55; break; case DS4Controls.LYNeg: result = cState.LY < 128 - 55; break;
case DS4Controls.RXNeg: result = cState.RX < 127 - 55; break; case DS4Controls.RXNeg: result = cState.RX < 128 - 55; break;
case DS4Controls.RYNeg: result = cState.RY < 127 - 55; break; case DS4Controls.RYNeg: result = cState.RY < 128 - 55; break;
case DS4Controls.LXPos: result = cState.LX > 127 + 55; break; case DS4Controls.LXPos: result = cState.LX > 128 + 55; break;
case DS4Controls.LYPos: result = cState.LY > 127 + 55; break; case DS4Controls.LYPos: result = cState.LY > 128 + 55; break;
case DS4Controls.RXPos: result = cState.RX > 127 + 55; break; case DS4Controls.RXPos: result = cState.RX > 128 + 55; break;
case DS4Controls.RYPos: result = cState.RY > 127 + 55; break; case DS4Controls.RYPos: result = cState.RY > 128 + 55; break;
default: break; default: break;
} }
} }
@ -3130,49 +3134,49 @@ namespace DS4Windows
case DS4Controls.LXNeg: case DS4Controls.LXNeg:
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LX < 127 && (angle >= 112.5 && angle <= 247.5); result = cState.LX < 128 && (angle >= 112.5 && angle <= 247.5);
break; break;
} }
case DS4Controls.LYNeg: case DS4Controls.LYNeg:
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LY < 127 && (angle >= 22.5 && angle <= 157.5); result = cState.LY < 128 && (angle >= 22.5 && angle <= 157.5);
break; break;
} }
case DS4Controls.RXNeg: case DS4Controls.RXNeg:
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RX < 127 && (angle >= 112.5 && angle <= 247.5); result = cState.RX < 128 && (angle >= 112.5 && angle <= 247.5);
break; break;
} }
case DS4Controls.RYNeg: case DS4Controls.RYNeg:
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RY < 127 && (angle >= 22.5 && angle <= 157.5); result = cState.RY < 128 && (angle >= 22.5 && angle <= 157.5);
break; break;
} }
case DS4Controls.LXPos: case DS4Controls.LXPos:
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LX > 127 && (angle <= 67.5 || angle >= 292.5); result = cState.LX > 128 && (angle <= 67.5 || angle >= 292.5);
break; break;
} }
case DS4Controls.LYPos: case DS4Controls.LYPos:
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LY > 127 && (angle >= 202.5 && angle <= 337.5); result = cState.LY > 128 && (angle >= 202.5 && angle <= 337.5);
break; break;
} }
case DS4Controls.RXPos: case DS4Controls.RXPos:
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RX > 127 && (angle <= 67.5 || angle >= 292.5); result = cState.RX > 128 && (angle <= 67.5 || angle >= 292.5);
break; break;
} }
case DS4Controls.RYPos: case DS4Controls.RYPos:
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RY > 127 && (angle >= 202.5 && angle <= 337.5); result = cState.RY > 128 && (angle >= 202.5 && angle <= 337.5);
break; break;
} }
default: break; default: break;
@ -3260,11 +3264,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LX < 127 && (angle >= 112.5 && angle <= 247.5); result = cState.LX < 128 && (angle >= 112.5 && angle <= 247.5);
} }
else else
{ {
result = cState.LX < 127; result = cState.LX < 128;
} }
break; break;
@ -3274,11 +3278,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LY < 127 && (angle >= 22.5 && angle <= 157.5); result = cState.LY < 128 && (angle >= 22.5 && angle <= 157.5);
} }
else else
{ {
result = cState.LY < 127; result = cState.LY < 128;
} }
break; break;
@ -3288,11 +3292,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RX < 127 && (angle >= 112.5 && angle <= 247.5); result = cState.RX < 128 && (angle >= 112.5 && angle <= 247.5);
} }
else else
{ {
result = cState.RX < 127; result = cState.RX < 128;
} }
break; break;
@ -3302,11 +3306,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RY < 127 && (angle >= 22.5 && angle <= 157.5); result = cState.RY < 128 && (angle >= 22.5 && angle <= 157.5);
} }
else else
{ {
result = cState.RY < 127; result = cState.RY < 128;
} }
break; break;
@ -3316,11 +3320,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LX > 127 && (angle <= 67.5 || angle >= 292.5); result = cState.LX > 128 && (angle <= 67.5 || angle >= 292.5);
} }
else else
{ {
result = cState.LX > 127; result = cState.LX > 128;
} }
break; break;
@ -3330,11 +3334,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.LSAngle; double angle = cState.LSAngle;
result = cState.LY > 127 && (angle >= 202.5 && angle <= 337.5); result = cState.LY > 128 && (angle >= 202.5 && angle <= 337.5);
} }
else else
{ {
result = cState.LY > 127; result = cState.LY > 128;
} }
break; break;
@ -3344,11 +3348,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RX > 127 && (angle <= 67.5 || angle >= 292.5); result = cState.RX > 128 && (angle <= 67.5 || angle >= 292.5);
} }
else else
{ {
result = cState.RX > 127; result = cState.RX > 128;
} }
break; break;
@ -3358,11 +3362,11 @@ namespace DS4Windows
if (!analog) if (!analog)
{ {
double angle = cState.RSAngle; double angle = cState.RSAngle;
result = cState.RY > 127 && (angle >= 202.5 && angle <= 337.5); result = cState.RY > 128 && (angle >= 202.5 && angle <= 337.5);
} }
else else
{ {
result = cState.RY > 127; result = cState.RY > 128;
} }
break; break;
@ -3426,7 +3430,7 @@ namespace DS4Windows
public static bool getBoolAxisDirMapping(byte stateAxis, bool positive) public static bool getBoolAxisDirMapping(byte stateAxis, bool positive)
{ {
return positive ? stateAxis > 127 + 55 : stateAxis < 127 - 55; return positive ? stateAxis > 128 + 55 : stateAxis < 128 - 55;
} }
public static bool getBoolTriggerMapping(byte stateAxis) public static bool getBoolTriggerMapping(byte stateAxis)
@ -3473,11 +3477,11 @@ namespace DS4Windows
{ {
if (alt) if (alt)
{ {
result = (byte)(127.5f + fieldMap.triggers[controlNum] / 2f); result = (byte)(128.0f + fieldMap.triggers[controlNum] / 2.0078740157480315f);
} }
else else
{ {
result = (byte)(127.5f - fieldMap.triggers[controlNum] / 2f); result = (byte)(128.0f - fieldMap.triggers[controlNum] / 2.0078740157480315f);
} }
} }
else if (controlType == DS4StateFieldMapping.ControlType.Touch) else if (controlType == DS4StateFieldMapping.ControlType.Touch)
@ -3569,10 +3573,10 @@ namespace DS4Windows
switch (control) switch (control)
{ {
case DS4Controls.L1: result = (byte)(cState.L1 ? trueVal : falseVal); break; case DS4Controls.L1: result = (byte)(cState.L1 ? trueVal : falseVal); break;
case DS4Controls.L2: if (alt) result = (byte)(127.5f + cState.L2 / 2f); else result = (byte)(127.5f - cState.L2 / 2f); break; case DS4Controls.L2: if (alt) result = (byte)(128.0f + cState.L2 / 2.0078740157480315f); else result = (byte)(128.0f - cState.L2 / 2.0078740157480315f); break;
case DS4Controls.L3: result = (byte)(cState.L3 ? trueVal : falseVal); break; case DS4Controls.L3: result = (byte)(cState.L3 ? trueVal : falseVal); break;
case DS4Controls.R1: result = (byte)(cState.R1 ? trueVal : falseVal); break; case DS4Controls.R1: result = (byte)(cState.R1 ? trueVal : falseVal); break;
case DS4Controls.R2: if (alt) result = (byte)(127.5f + cState.R2 / 2f); else result = (byte)(127.5f - cState.R2 / 2f); break; case DS4Controls.R2: if (alt) result = (byte)(128.0f + cState.R2 / 2.0078740157480315f); else result = (byte)(128.0f - cState.R2 / 2.0078740157480315f); break;
case DS4Controls.R3: result = (byte)(cState.R3 ? trueVal : falseVal); break; case DS4Controls.R3: result = (byte)(cState.R3 ? trueVal : falseVal); break;
default: break; default: break;
} }

View File

@ -109,9 +109,9 @@ namespace DS4Windows
case 2: return s.Square; case 2: return s.Square;
case 3: return s.Triangle; case 3: return s.Triangle;
case 4: return s.L1; case 4: return s.L1;
case 5: return s.L2 > 127; case 5: return s.L2 > 128;
case 6: return s.R1; case 6: return s.R1;
case 7: return s.R2 > 127; case 7: return s.R2 > 128;
case 8: return s.DpadUp; case 8: return s.DpadUp;
case 9: return s.DpadDown; case 9: return s.DpadDown;
case 10: return s.DpadLeft; case 10: return s.DpadLeft;

View File

@ -48,7 +48,7 @@ namespace DS4Windows
L1 = L2Btn = L3 = R1 = R2Btn = R3 = false; L1 = L2Btn = L3 = R1 = R2Btn = R3 = false;
Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false; Share = Options = PS = Touch1 = Touch2 = TouchButton = TouchRight = TouchLeft = false;
Touch1Finger = Touch2Fingers = false; Touch1Finger = Touch2Fingers = false;
LX = RX = LY = RY = 127; LX = RX = LY = RY = 128;
L2 = R2 = 0; L2 = R2 = 0;
FrameCounter = 255; // only actually has 6 bits, so this is a null indicator FrameCounter = 255; // only actually has 6 bits, so this is a null indicator
TouchPacketCounter = 255; // 8 bits, no great junk value TouchPacketCounter = 255; // 8 bits, no great junk value
@ -183,14 +183,14 @@ namespace DS4Windows
public void calculateStickAngles() public void calculateStickAngles()
{ {
double lsangle = Math.Atan2(-(LY - 127), (LX - 127)); double lsangle = Math.Atan2(-(LY - 128), (LX - 128));
LSAngleRad = lsangle; LSAngleRad = lsangle;
lsangle = (lsangle >= 0 ? lsangle : (2 * Math.PI + lsangle)) * 180 / Math.PI; lsangle = (lsangle >= 0 ? lsangle : (2 * Math.PI + lsangle)) * 180 / Math.PI;
LSAngle = lsangle; LSAngle = lsangle;
LXUnit = Math.Abs(Math.Cos(LSAngleRad)); LXUnit = Math.Abs(Math.Cos(LSAngleRad));
LYUnit = Math.Abs(Math.Sin(LSAngleRad)); LYUnit = Math.Abs(Math.Sin(LSAngleRad));
double rsangle = Math.Atan2(-(RY - 127), (RX - 127)); double rsangle = Math.Atan2(-(RY - 128), (RX - 128));
RSAngleRad = rsangle; RSAngleRad = rsangle;
rsangle = (rsangle >= 0 ? rsangle : (2 * Math.PI + rsangle)) * 180 / Math.PI; rsangle = (rsangle >= 0 ? rsangle : (2 * Math.PI + rsangle)) * 180 / Math.PI;
RSAngle = rsangle; RSAngle = rsangle;
@ -201,17 +201,17 @@ namespace DS4Windows
public void rotateLSCoordinates(double rotation) public void rotateLSCoordinates(double rotation)
{ {
double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation); double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation);
double tempLX = LX - 127.5, tempLY = LY - 127.5; double tempLX = LX - 128.0, tempLY = LY - 128.0;
LX = (Byte)(Global.Clamp(-127.5, (tempLX * cosAngle - tempLY * sinAngle), 127.5) + 127.5); LX = (Byte)(Global.Clamp(-128.0, (tempLX * cosAngle - tempLY * sinAngle), 127.0) + 128.0);
LY = (Byte)(Global.Clamp(-127.5, (tempLX * sinAngle + tempLY * cosAngle), 127.5) + 127.5); LY = (Byte)(Global.Clamp(-128.0, (tempLX * sinAngle + tempLY * cosAngle), 127.0) + 128.0);
} }
public void rotateRSCoordinates(double rotation) public void rotateRSCoordinates(double rotation)
{ {
double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation); double sinAngle = Math.Sin(rotation), cosAngle = Math.Cos(rotation);
double tempRX = RX - 127.5, tempRY = RY - 127.5; double tempRX = RX - 128.0, tempRY = RY - 128.0;
RX = (Byte)(Global.Clamp(-127.5, (tempRX * cosAngle - tempRY * sinAngle), 127.5) + 127.5); RX = (Byte)(Global.Clamp(-128.0, (tempRX * cosAngle - tempRY * sinAngle), 127.0) + 128.0);
RY = (Byte)(Global.Clamp(-127.5, (tempRX * sinAngle + tempRY * cosAngle), 127.5) + 127.5); RY = (Byte)(Global.Clamp(-128.0, (tempRX * sinAngle + tempRY * cosAngle), 127.0) + 128.0);
} }
} }
} }