diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index bbcf2d0..4cb4c45 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -912,10 +912,89 @@ namespace DS4Windows dState.LY = (byte)(tempY * capY + 128.0); } - if (getLsOutCurveMode(device) > 0) + int lsOutCurveMode = getLsOutCurveMode(device); + if (lsOutCurveMode > 0 && (dState.LX != 128 || dState.LY != 128)) { - dState.LX = lsOutBezierCurveObj[device].arrayBezierLUT[dState.LX]; - dState.LY = lsOutBezierCurveObj[device].arrayBezierLUT[dState.LY]; + double capX = dState.LX >= 128 ? 127.0 : 128.0; + 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 signY = tempY >= 0.0 ? 1.0 : -1.0; + + if (lsOutCurveMode == 1) + { + double absX = Math.Abs(tempX); + double absY = Math.Abs(tempY); + double outputX = 0.0; + double outputY = 0.0; + + if (absX <= 0.4) + { + outputX = 0.55 * absX; + } + else if (absX <= 0.75) + { + outputX = absX - 0.18; + } + else if (absX > 0.75) + { + outputX = (absX * 1.72) - 0.72; + } + + if (absY <= 0.4) + { + outputY = 0.55 * absY; + } + else if (absY <= 0.75) + { + outputY = absY - 0.18; + } + else if (absY > 0.75) + { + outputY = (absY * 1.72) - 0.72; + } + + dState.LX = (byte)(outputX * signX * capX + 128.0); + dState.LY = (byte)(outputY * signY * capY + 128.0); + } + else if (lsOutCurveMode == 2) + { + double outputX = tempX * tempX; + double outputY = tempY * tempY; + dState.LX = (byte)(outputX * signX * capX + 128.0); + dState.LY = (byte)(outputY * signY * capY + 128.0); + } + else if (lsOutCurveMode == 3) + { + double outputX = tempX * tempX * tempX; + double outputY = tempY * tempY * tempY; + dState.LX = (byte)(outputX * capX + 128.0); + dState.LY = (byte)(outputY * capY + 128.0); + } + else if (lsOutCurveMode == 4) + { + double absX = Math.Abs(tempX); + double absY = Math.Abs(tempY); + double outputX = absX * (absX - 2.0); + double outputY = absY * (absY - 2.0); + dState.LX = (byte)(-1.0 * outputX * signX * capX + 128.0); + dState.LY = (byte)(-1.0 * outputY * signY * capY + 128.0); + } + else if (lsOutCurveMode == 5) + { + double innerX = Math.Abs(tempX) - 1.0; + double innerY = Math.Abs(tempY) - 1.0; + double outputX = innerX * innerX * innerX + 1.0; + double outputY = innerY * innerY * innerY + 1.0; + dState.LX = (byte)(1.0 * outputX * signX * capX + 128.0); + dState.LY = (byte)(1.0 * outputY * signY * capY + 128.0); + } + else if (lsOutCurveMode == 6) + { + dState.LX = lsOutBezierCurveObj[device].arrayBezierLUT[dState.LX]; + dState.LY = lsOutBezierCurveObj[device].arrayBezierLUT[dState.LY]; + } } if (squStk.rsMode && (dState.RX != 128 || dState.RY != 128)) @@ -936,20 +1015,151 @@ namespace DS4Windows dState.RY = (byte)(tempY * capY + 128.0); } - if (getRsOutCurveMode(device) > 0) + int rsOutCurveMode = getRsOutCurveMode(device); + if (rsOutCurveMode > 0 && (dState.RX != 128 || dState.RY != 128)) { - dState.RX = rsOutBezierCurveObj[device].arrayBezierLUT[dState.RX]; - dState.RY = rsOutBezierCurveObj[device].arrayBezierLUT[dState.RY]; + double capX = dState.RX >= 128 ? 127.0 : 128.0; + 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 signY = tempY >= 0.0 ? 1.0 : -1.0; + + if (rsOutCurveMode == 1) + { + double absX = Math.Abs(tempX); + double absY = Math.Abs(tempY); + double outputX = 0.0; + double outputY = 0.0; + + if (absX <= 0.4) + { + outputX = 0.55 * absX; + } + else if (absX <= 0.75) + { + outputX = absX - 0.18; + } + else if (absX > 0.75) + { + outputX = (absX * 1.72) - 0.72; + } + + if (absY <= 0.4) + { + outputY = 0.55 * absY; + } + else if (absY <= 0.75) + { + outputY = absY - 0.18; + } + else if (absY > 0.75) + { + outputY = (absY * 1.72) - 0.72; + } + + dState.RX = (byte)(outputX * signX * capX + 128.0); + dState.RY = (byte)(outputY * signY * capY + 128.0); + } + else if (rsOutCurveMode == 2) + { + double outputX = tempX * tempX; + double outputY = tempY * tempY; + dState.RX = (byte)(outputX * signX * capX + 128.0); + dState.RY = (byte)(outputY * signY * capY + 128.0); + } + else if (rsOutCurveMode == 3) + { + double outputX = tempX * tempX * tempX; + double outputY = tempY * tempY * tempY; + dState.RX = (byte)(outputX * capX + 128.0); + dState.RY = (byte)(outputY * capY + 128.0); + } + else if (rsOutCurveMode == 4) + { + double absX = Math.Abs(tempX); + double absY = Math.Abs(tempY); + double outputX = absX * (absX - 2.0); + double outputY = absY * (absY - 2.0); + dState.RX = (byte)(-1.0 * outputX * signX * capX + 128.0); + dState.RY = (byte)(-1.0 * outputY * signY * capY + 128.0); + } + else if (rsOutCurveMode == 5) + { + double innerX = Math.Abs(tempX) - 1.0; + double innerY = Math.Abs(tempY) - 1.0; + double outputX = innerX * innerX * innerX + 1.0; + double outputY = innerY * innerY * innerY + 1.0; + dState.RX = (byte)(1.0 * outputX * signX * capX + 128.0); + dState.RY = (byte)(1.0 * outputY * signY * capY + 128.0); + } + else if (rsOutCurveMode == 6) + { + dState.RX = rsOutBezierCurveObj[device].arrayBezierLUT[dState.RX]; + dState.RY = rsOutBezierCurveObj[device].arrayBezierLUT[dState.RY]; + } } - if (getL2OutCurveMode(device) > 0) + int l2OutCurveMode = getL2OutCurveMode(device); + if (l2OutCurveMode > 0 && dState.L2 != 0) { - dState.L2 = l2OutBezierCurveObj[device].arrayBezierLUT[dState.L2]; + double temp = dState.L2 / 255.0; + if (l2OutCurveMode == 1) + { + double output = temp * temp; + dState.L2 = (byte)(output * 255.0); + } + else if (l2OutCurveMode == 2) + { + double output = temp * temp * temp; + dState.L2 = (byte)(output * 255.0); + } + else if (l2OutCurveMode == 3) + { + double output = temp * (temp - 2.0); + dState.L2 = (byte)(-1.0 * output * 255.0); + } + else if (l2OutCurveMode == 4) + { + double inner = Math.Abs(temp) - 1.0; + double output = inner * inner * inner + 1.0; + dState.L2 = (byte)(-1.0 * output * 255.0); + } + else if (l2OutCurveMode == 5) + { + dState.L2 = l2OutBezierCurveObj[device].arrayBezierLUT[dState.L2]; + } } - if (getR2OutCurveMode(device) > 0) + int r2OutCurveMode = getR2OutCurveMode(device); + if (r2OutCurveMode > 0 && dState.R2 != 0) { - dState.R2 = r2OutBezierCurveObj[device].arrayBezierLUT[dState.R2]; + double temp = dState.R2 / 255.0; + if (r2OutCurveMode == 1) + { + double output = temp * temp; + dState.R2 = (byte)(output * 255.0); + } + else if (r2OutCurveMode == 2) + { + double output = temp * temp * temp; + dState.R2 = (byte)(output * 255.0); + } + else if (r2OutCurveMode == 3) + { + double output = temp * (temp - 2.0); + dState.R2 = (byte)(-1.0 * output * 255.0); + } + else if (r2OutCurveMode == 4) + { + double inner = Math.Abs(temp) - 1.0; + double output = inner * inner * inner + 1.0; + dState.R2 = (byte)(-1.0 * output * 255.0); + } + else if (r2OutCurveMode == 5) + { + dState.R2 = r2OutBezierCurveObj[device].arrayBezierLUT[dState.R2]; + } } @@ -1009,16 +1219,78 @@ namespace DS4Windows (int)Math.Min(128d, szsens * 128d * (absz / 128d)); } - if (getSXOutCurveMode(device) > 0) + int sxOutCurveMode = getSXOutCurveMode(device); + if (sxOutCurveMode > 0) { - int signSA = Math.Sign(dState.Motion.outputAccelX); - dState.Motion.outputAccelX = sxOutBezierCurveObj[device].arrayBezierLUT[Math.Min(Math.Abs(dState.Motion.outputAccelX), 128)] * signSA; + double temp = dState.Motion.outputAccelX / 128.0; + double sign = Math.Sign(temp); + if (sxOutCurveMode == 1) + { + double output = temp * temp; + result = (int)(output * sign * 128.0); + dState.Motion.outputAccelX = result; + } + else if (sxOutCurveMode == 2) + { + double output = temp * temp * temp; + result = (int)(output * 128.0); + dState.Motion.outputAccelX = result; + } + else if (sxOutCurveMode == 3) + { + double abs = Math.Abs(temp); + double output = abs * (abs - 2.0); + dState.Motion.outputAccelX = (byte)(-1.0 * output * + sign * 128.0); + } + else if (sxOutCurveMode == 4) + { + double inner = Math.Abs(temp) - 1.0; + double output = inner * inner * inner + 1.0; + dState.Motion.outputAccelX = (byte)(-1.0 * output * 255.0); + } + else if (sxOutCurveMode == 5) + { + int signSA = Math.Sign(dState.Motion.outputAccelX); + dState.Motion.outputAccelX = sxOutBezierCurveObj[device].arrayBezierLUT[Math.Min(Math.Abs(dState.Motion.outputAccelX), 128)] * signSA; + } } - if (getSZOutCurveMode(device) > 0) + int szOutCurveMode = getSZOutCurveMode(device); + if (szOutCurveMode > 0 && dState.Motion.outputAccelZ != 0) { - int signSA = Math.Sign(dState.Motion.outputAccelZ); - dState.Motion.outputAccelZ = szOutBezierCurveObj[device].arrayBezierLUT[Math.Min(Math.Abs(dState.Motion.outputAccelZ), 128)] * signSA; + double temp = dState.Motion.outputAccelZ / 128.0; + double sign = Math.Sign(temp); + if (szOutCurveMode == 1) + { + double output = temp * temp; + result = (int)(output * sign * 128.0); + dState.Motion.outputAccelZ = result; + } + else if (szOutCurveMode == 2) + { + double output = temp * temp * temp; + result = (int)(output * 128.0); + dState.Motion.outputAccelZ = result; + } + else if (szOutCurveMode == 3) + { + double abs = Math.Abs(temp); + double output = abs * (abs - 2.0); + dState.Motion.outputAccelZ = (byte)(-1.0 * output * + sign * 128.0); + } + else if (szOutCurveMode == 4) + { + double inner = Math.Abs(temp) - 1.0; + double output = inner * inner * inner + 1.0; + dState.Motion.outputAccelZ = (byte)(-1.0 * output * 255.0); + } + else if (szOutCurveMode == 5) + { + int signSA = Math.Sign(dState.Motion.outputAccelZ); + dState.Motion.outputAccelZ = szOutBezierCurveObj[device].arrayBezierLUT[Math.Min(Math.Abs(dState.Motion.outputAccelZ), 128)] * signSA; + } } }