Use old routines for preset curves

This commit is contained in:
Travis Nickles 2019-07-25 14:54:39 -05:00
parent 13150015f0
commit 4ffda750f7
2 changed files with 384 additions and 34 deletions

View File

@ -911,10 +911,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))
@ -935,17 +1014,153 @@ 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)
dState.L2 = l2OutBezierCurveObj[device].arrayBezierLUT[dState.L2];
int l2OutCurveMode = getL2OutCurveMode(device);
if (l2OutCurveMode > 0 && dState.L2 != 0)
{
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)
dState.R2 = r2OutBezierCurveObj[device].arrayBezierLUT[dState.R2];
int r2OutCurveMode = getR2OutCurveMode(device);
if (r2OutCurveMode > 0 && dState.R2 != 0)
{
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];
}
}
bool sOff = /*tempBool =*/ isUsingSAforMouse(device);
if (sOff == false)
@ -1003,16 +1218,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;
}
}
}

View File

@ -461,6 +461,8 @@ namespace DS4Windows.Forms
cBSixaxisXOutputCurve.SelectedIndex = getSXOutCurveMode(device);
cBSixaxisZOutputCurve.SelectedIndex = getSZOutCurveMode(device);
CustomCurveChecker();
try
{
nUDL2.Value = Math.Round((decimal)L2ModInfo[device].deadZone / 255, 2);
@ -816,6 +818,11 @@ namespace DS4Windows.Forms
cBR2OutputCurve.SelectedIndex = 0;
cBSixaxisXOutputCurve.SelectedIndex = 0;
cBSixaxisZOutputCurve.SelectedIndex = 0;
tBCustomOutputCurve.Text = String.Empty;
lbCurveEditorURL.Text = $" - {lbCurveEditorURL.Text}";
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = false;
rBTPMouse.Checked = true;
rBSAControls.Checked = true;
ToggleRainbow(false);
@ -2859,12 +2866,13 @@ namespace DS4Windows.Forms
{
if (!loading)
{
bool customIdx = lsOutCurveComboBox.SelectedIndex == lsOutCurveComboBox.Items.Count - 1;
// This same handler is called when combobox label object is clicked. Update curve mode only when sender is ComboxBox with a new selection index
if(sender is ComboBox)
if (sender is ComboBox && customIdx)
setLsOutCurveMode(device, lsOutCurveComboBox.SelectedIndex);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = (lsOutCurveComboBox.SelectedIndex == lsOutCurveComboBox.Items.Count - 1);
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? lsOutBezierCurveObj[device].ToString() : lsOutBezierCurveObj[device].AsString);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (customIdx ? lsOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"LS - {lbCurveEditorURL.Text.Substring(5)}";
}
}
@ -2873,15 +2881,76 @@ namespace DS4Windows.Forms
{
if (!loading)
{
if (sender is ComboBox)
bool customIdx = rsOutCurveComboBox.SelectedIndex == rsOutCurveComboBox.Items.Count - 1;
if (sender is ComboBox && customIdx)
setRsOutCurveMode(device, rsOutCurveComboBox.SelectedIndex);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = (rsOutCurveComboBox.SelectedIndex == rsOutCurveComboBox.Items.Count - 1);
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? rsOutBezierCurveObj[device].ToString() : rsOutBezierCurveObj[device].AsString);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (customIdx ? rsOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"RS - {lbCurveEditorURL.Text.Substring(5)}";
}
}
private void CustomCurveChecker()
{
bool customIdx = lsOutCurveComboBox.SelectedIndex == lsOutCurveComboBox.Items.Count - 1;
if (customIdx)
{
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (customIdx ? lsOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"LS - {lbCurveEditorURL.Text.Substring(5)}";
goto end;
}
customIdx = rsOutCurveComboBox.SelectedIndex == rsOutCurveComboBox.Items.Count - 1;
if (customIdx)
{
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (customIdx ? rsOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"RS - {lbCurveEditorURL.Text.Substring(5)}";
goto end;
}
customIdx = cBL2OutputCurve.SelectedIndex == cBL2OutputCurve.Items.Count - 1;
if (customIdx)
{
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? l2OutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"L2 - {lbCurveEditorURL.Text.Substring(5)}";
goto end;
}
customIdx = cBR2OutputCurve.SelectedIndex == cBR2OutputCurve.Items.Count - 1;
if (customIdx)
{
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? r2OutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"R2 - {lbCurveEditorURL.Text.Substring(5)}";
goto end;
}
customIdx = cBSixaxisXOutputCurve.SelectedIndex == cBSixaxisXOutputCurve.Items.Count - 1;
if (customIdx)
{
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? sxOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"SX - {lbCurveEditorURL.Text.Substring(5)}";
goto end;
}
customIdx = cBSixaxisZOutputCurve.SelectedIndex == cBSixaxisZOutputCurve.Items.Count - 1;
if (customIdx)
{
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? szOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"SZ - {lbCurveEditorURL.Text.Substring(5)}";
goto end;
}
end:
return;
}
private void gyroTriggerBehavior_CheckedChanged(object sender, EventArgs e)
{
if (!loading)
@ -2987,11 +3056,12 @@ namespace DS4Windows.Forms
{
if (loading == false)
{
if (sender is ComboBox)
bool customIdx = cBL2OutputCurve.SelectedIndex == cBL2OutputCurve.Items.Count - 1;
if (sender is ComboBox && customIdx)
setL2OutCurveMode(device, cBL2OutputCurve.SelectedIndex);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = (cBL2OutputCurve.SelectedIndex == cBL2OutputCurve.Items.Count - 1);
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? l2OutBezierCurveObj[device].ToString() : l2OutBezierCurveObj[device].AsString);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? l2OutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"L2 - {lbCurveEditorURL.Text.Substring(5)}";
}
}
@ -3000,11 +3070,12 @@ namespace DS4Windows.Forms
{
if (loading == false)
{
if (sender is ComboBox)
bool customIdx = cBR2OutputCurve.SelectedIndex == cBR2OutputCurve.Items.Count - 1;
if (sender is ComboBox && customIdx)
setR2OutCurveMode(device, cBR2OutputCurve.SelectedIndex);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = (cBR2OutputCurve.SelectedIndex == cBR2OutputCurve.Items.Count - 1);
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? r2OutBezierCurveObj[device].ToString() : r2OutBezierCurveObj[device].AsString);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? r2OutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"R2 - {lbCurveEditorURL.Text.Substring(5)}";
}
}
@ -3013,11 +3084,12 @@ namespace DS4Windows.Forms
{
if (loading == false)
{
if (sender is ComboBox)
bool customIdx = cBSixaxisXOutputCurve.SelectedIndex == cBSixaxisXOutputCurve.Items.Count - 1;
if (sender is ComboBox && customIdx)
setSXOutCurveMode(device, cBSixaxisXOutputCurve.SelectedIndex);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = (cBSixaxisXOutputCurve.SelectedIndex == cBSixaxisXOutputCurve.Items.Count - 1);
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? sxOutBezierCurveObj[device].ToString() : sxOutBezierCurveObj[device].AsString);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? sxOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"SX - {lbCurveEditorURL.Text.Substring(5)}";
}
}
@ -3026,11 +3098,12 @@ namespace DS4Windows.Forms
{
if (loading == false)
{
if (sender is ComboBox)
bool customIdx = cBSixaxisZOutputCurve.SelectedIndex == cBSixaxisZOutputCurve.Items.Count - 1;
if (sender is ComboBox && customIdx)
setSZOutCurveMode(device, cBSixaxisZOutputCurve.SelectedIndex);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = (cBSixaxisZOutputCurve.SelectedIndex == cBSixaxisZOutputCurve.Items.Count - 1);
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? szOutBezierCurveObj[device].ToString() : szOutBezierCurveObj[device].AsString);
tBCustomOutputCurve.Enabled = lbCurveEditorURL.Enabled = customIdx;
tBCustomOutputCurve.Text = (tBCustomOutputCurve.Enabled ? szOutBezierCurveObj[device].ToString() : "");
lbCurveEditorURL.Text = $"SZ - {lbCurveEditorURL.Text.Substring(5)}";
}
}