mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-24 15:41:49 +01:00
Make sure remainder is used for mouse movement. Minor changes to mouse movement routine.
This commit is contained in:
parent
c0152f58c9
commit
9de2f436e5
@ -784,8 +784,10 @@ namespace DS4Windows
|
|||||||
MappedState.LY = 127;
|
MappedState.LY = 127;
|
||||||
MappedState.RX = 127;
|
MappedState.RX = 127;
|
||||||
MappedState.RY = 127;
|
MappedState.RY = 127;
|
||||||
int MouseDeltaX = 0;
|
double tempMouseDeltaX = 0.0;
|
||||||
int MouseDeltaY = 0;
|
double tempMouseDeltaY = 0.0;
|
||||||
|
int mouseDeltaX = 0;
|
||||||
|
int mouseDeltaY = 0;
|
||||||
|
|
||||||
SyntheticState deviceState = Mapping.deviceState[device];
|
SyntheticState deviceState = Mapping.deviceState[device];
|
||||||
if (getProfileActionCount(device) > 0 || !string.IsNullOrEmpty(tempprofilename[device]))
|
if (getProfileActionCount(device) > 0 || !string.IsNullOrEmpty(tempprofilename[device]))
|
||||||
@ -987,31 +989,31 @@ namespace DS4Windows
|
|||||||
switch (xboxControl)
|
switch (xboxControl)
|
||||||
{
|
{
|
||||||
case X360Controls.MouseUp:
|
case X360Controls.MouseUp:
|
||||||
if (MouseDeltaY == 0)
|
if (tempMouseDeltaY == 0)
|
||||||
{
|
{
|
||||||
MouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 0);
|
tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 0);
|
||||||
MouseDeltaY = -Math.Abs((MouseDeltaY == -2147483648 ? 0 : MouseDeltaY));
|
tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case X360Controls.MouseDown:
|
case X360Controls.MouseDown:
|
||||||
if (MouseDeltaY == 0)
|
if (tempMouseDeltaY == 0)
|
||||||
{
|
{
|
||||||
MouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 1);
|
tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 1);
|
||||||
MouseDeltaY = Math.Abs((MouseDeltaY == -2147483648 ? 0 : MouseDeltaY));
|
tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case X360Controls.MouseLeft:
|
case X360Controls.MouseLeft:
|
||||||
if (MouseDeltaX == 0)
|
if (tempMouseDeltaX == 0)
|
||||||
{
|
{
|
||||||
MouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 2);
|
tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 2);
|
||||||
MouseDeltaX = -Math.Abs((MouseDeltaX == -2147483648 ? 0 : MouseDeltaX));
|
tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case X360Controls.MouseRight:
|
case X360Controls.MouseRight:
|
||||||
if (MouseDeltaX == 0)
|
if (tempMouseDeltaX == 0)
|
||||||
{
|
{
|
||||||
MouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 3);
|
tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 3);
|
||||||
MouseDeltaX = Math.Abs((MouseDeltaX == -2147483648 ? 0 : MouseDeltaX));
|
tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1306,9 +1308,11 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MouseDeltaX != 0 || MouseDeltaY != 0)
|
calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY,
|
||||||
|
out mouseDeltaX, out mouseDeltaY);
|
||||||
|
if (mouseDeltaX != 0 || mouseDeltaY != 0)
|
||||||
{
|
{
|
||||||
InputMethods.MoveCursorBy(MouseDeltaX, MouseDeltaY);
|
InputMethods.MoveCursorBy(mouseDeltaX, mouseDeltaY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2075,16 +2079,15 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, int mnum)
|
private static double getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, int mnum)
|
||||||
{
|
{
|
||||||
int controlnum = DS4ControltoInt(control);
|
int controlnum = DS4ControltoInt(control);
|
||||||
double SXD = SXDeadzone[device];
|
|
||||||
double SZD = SZDeadzone[device];
|
|
||||||
int deadzoneL = 3;
|
int deadzoneL = 3;
|
||||||
int deadzoneR = 3;
|
int deadzoneR = 3;
|
||||||
if (LSDeadzone[device] >= 3)
|
if (getLSDeadzone(device) >= 3)
|
||||||
deadzoneL = 0;
|
deadzoneL = 0;
|
||||||
if (RSDeadzone[device] >= 3)
|
if (getRSDeadzone(device) >= 3)
|
||||||
deadzoneR = 0;
|
deadzoneR = 0;
|
||||||
|
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
@ -2098,56 +2101,71 @@ namespace DS4Windows
|
|||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
case DS4Controls.LXNeg:
|
case DS4Controls.LXNeg:
|
||||||
if (cState.LX - 127.5f < -deadzoneL)
|
if (cState.LX < 127.5f - deadzoneL)
|
||||||
value = -(cState.LX - 127.5f) / 2550d * speed;
|
value = -(cState.LX - 127.5f - deadzoneL) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.LXPos:
|
case DS4Controls.LXPos:
|
||||||
if (cState.LX - 127.5f > deadzoneL)
|
if (cState.LX > 127.5f + deadzoneL)
|
||||||
value = (cState.LX - 127.5f) / 2550d * speed;
|
value = (cState.LX - 127.5f + deadzoneL) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.RXNeg:
|
case DS4Controls.RXNeg:
|
||||||
if (cState.RX - 127.5f < -deadzoneR)
|
if (cState.RX < 127.5f - deadzoneR)
|
||||||
value = -(cState.RX - 127.5f) / 2550d * speed;
|
value = -(cState.RX - 127.5f - deadzoneR) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.RXPos:
|
case DS4Controls.RXPos:
|
||||||
if (cState.RX - 127.5f > deadzoneR)
|
if (cState.RX > 127.5f + deadzoneR)
|
||||||
value = (cState.RX - 127.5f) / 2550d * speed;
|
value = (cState.RX - 127.5f + deadzoneR) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.LYNeg:
|
case DS4Controls.LYNeg:
|
||||||
if (cState.LY - 127.5f < -deadzoneL)
|
if (cState.LY < 127.5f - deadzoneL)
|
||||||
value = -(cState.LY - 127.5f) / 2550d * speed;
|
value = -(cState.LY - 127.5f - deadzoneL) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.LYPos:
|
case DS4Controls.LYPos:
|
||||||
if (cState.LY - 127.5f > deadzoneL)
|
if (cState.LY > 127.5f + deadzoneL)
|
||||||
value = (cState.LY - 127.5f) / 2550d * speed;
|
value = (cState.LY - 127.5f + deadzoneL) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.RYNeg:
|
case DS4Controls.RYNeg:
|
||||||
if (cState.RY - 127.5f < -deadzoneR)
|
if (cState.RY < 127 - deadzoneR)
|
||||||
value = -(cState.RY - 127.5f) / 2550d * speed;
|
value = -(cState.RY - 127.5f - deadzoneR) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
case DS4Controls.RYPos:
|
case DS4Controls.RYPos:
|
||||||
if (cState.RY - 127.5f > deadzoneR)
|
if (cState.RY > 127 + deadzoneR)
|
||||||
value = (cState.RY - 127.5f) / 2550d * speed;
|
value = (cState.RY - 127.5f + deadzoneR) / 2550d * speed;
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
||||||
{
|
{
|
||||||
|
double SXD = getSXDeadzone(device);
|
||||||
|
double SZD = getSZDeadzone(device);
|
||||||
|
|
||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
case DS4Controls.GyroXPos:
|
case DS4Controls.GyroXPos:
|
||||||
value = (byte)(eState.GyroX > SXD * 10 ? Math.Pow(root + speed / divide, eState.GyroX) : 0);
|
{
|
||||||
|
int gyroX = eState.GyroX;
|
||||||
|
value = (byte)(gyroX > SXD * 10 ? Math.Pow(root + speed / divide, gyroX) : 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DS4Controls.GyroXNeg:
|
case DS4Controls.GyroXNeg:
|
||||||
value = (byte)(eState.GyroX < -SXD * 10 ? Math.Pow(root + speed / divide, -eState.GyroX) : 0);
|
{
|
||||||
|
int gyroX = eState.GyroX;
|
||||||
|
value = (byte)(gyroX < -SXD * 10 ? Math.Pow(root + speed / divide, -gyroX) : 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DS4Controls.GyroZPos:
|
case DS4Controls.GyroZPos:
|
||||||
value = (byte)(eState.GyroZ > SZD * 10 ? Math.Pow(root + speed / divide, eState.GyroZ) : 0);
|
{
|
||||||
|
int gyroZ = eState.GyroZ;
|
||||||
|
value = (byte)(gyroZ > SZD * 10 ? Math.Pow(root + speed / divide, gyroZ) : 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DS4Controls.GyroZNeg:
|
case DS4Controls.GyroZNeg:
|
||||||
value = (byte)(eState.GyroZ < -SZD * 10 ? Math.Pow(root + speed / divide, -eState.GyroZ) : 0);
|
{
|
||||||
|
int gyroZ = eState.GyroZ;
|
||||||
|
value = (byte)(gyroZ < -SZD * 10 ? Math.Pow(root + speed / divide, -gyroZ) : 0);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -2198,12 +2216,6 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LXChanged = (Math.Abs(127 - cState.LX) < deadzoneL);
|
|
||||||
bool LYChanged = (Math.Abs(127 - cState.LY) < deadzoneL);
|
|
||||||
bool RXChanged = (Math.Abs(127 - cState.RX) < deadzoneR);
|
|
||||||
bool RYChanged = (Math.Abs(127 - cState.RY) < deadzoneR);
|
|
||||||
|
|
||||||
bool contains = control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos;
|
|
||||||
if (MouseAccel[device])
|
if (MouseAccel[device])
|
||||||
{
|
{
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
@ -2223,22 +2235,36 @@ namespace DS4Windows
|
|||||||
value *= 1 + (double)Math.Min(20000, (mouseaccel)) / 10000d;
|
value *= 1 + (double)Math.Min(20000, (mouseaccel)) / 10000d;
|
||||||
prevmouseaccel = mouseaccel;
|
prevmouseaccel = mouseaccel;
|
||||||
}
|
}
|
||||||
int intValue;
|
|
||||||
if (mnum > 1)
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void calculateFinalMouseMovement(ref double rawMouseX, ref double rawMouseY,
|
||||||
|
out int mouseX, out int mouseY)
|
||||||
|
{
|
||||||
|
if ((rawMouseX > 0.0 && horizontalRemainder > 0.0) || (rawMouseX < 0.0 && horizontalRemainder < 0.0))
|
||||||
{
|
{
|
||||||
if ((value > 0.0 && horizontalRemainder > 0.0) || (value < 0.0 && horizontalRemainder < 0.0))
|
rawMouseX += horizontalRemainder;
|
||||||
value += horizontalRemainder;
|
|
||||||
intValue = (int)value;
|
|
||||||
horizontalRemainder = value - intValue;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((value > 0.0 && verticalRemainder > 0.0) || (value < 0.0 && verticalRemainder < 0.0))
|
horizontalRemainder = 0.0;
|
||||||
value += verticalRemainder;
|
|
||||||
intValue = (int)value;
|
|
||||||
verticalRemainder = value - intValue;
|
|
||||||
}
|
}
|
||||||
return intValue;
|
|
||||||
|
mouseX = (int)rawMouseX;
|
||||||
|
horizontalRemainder = rawMouseX - mouseX;
|
||||||
|
|
||||||
|
if ((rawMouseY > 0.0 && verticalRemainder > 0.0) || (rawMouseY < 0.0 && verticalRemainder < 0.0))
|
||||||
|
{
|
||||||
|
rawMouseY += verticalRemainder;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
verticalRemainder = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mouseY = (int)rawMouseY;
|
||||||
|
verticalRemainder = rawMouseY - mouseY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool compare(byte b1, byte b2)
|
public static bool compare(byte b1, byte b2)
|
||||||
@ -2328,16 +2354,38 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
||||||
{
|
{
|
||||||
double SXD = SXDeadzone[device];
|
double SXD = getSXDeadzone(device);
|
||||||
double SZD = SZDeadzone[device];
|
double SZD = getSZDeadzone(device);
|
||||||
bool sOff = UseSAforMouse[device];
|
bool sOff = isUsingSAforMouse(device);
|
||||||
|
double sxsens = getSXSens(device);
|
||||||
|
double szsens = getSZSens(device);
|
||||||
|
|
||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
case DS4Controls.GyroXPos: result = (byte)(!sOff && SXSens[device] * eState.GyroX > SXD * 10 ? Math.Min(255, SXSens[device] * eState.GyroX * 2) : 0); break;
|
case DS4Controls.GyroXPos:
|
||||||
case DS4Controls.GyroXNeg: result = (byte)(!sOff && SXSens[device] * eState.GyroX < -SXD * 10 ? Math.Min(255, SXSens[device] * -eState.GyroX * 2) : 0); break;
|
{
|
||||||
case DS4Controls.GyroZPos: result = (byte)(!sOff && SZSens[device] * eState.GyroZ > SZD * 10 ? Math.Min(255, SZSens[device] * eState.GyroZ * 2) : 0); break;
|
int gyroX = eState.GyroX;
|
||||||
case DS4Controls.GyroZNeg: result = (byte)(!sOff && SZSens[device] * eState.GyroZ < -SZD * 10 ? Math.Min(255, SZSens[device] * -eState.GyroZ * 2) : 0); break;
|
result = (byte)(!sOff && sxsens * gyroX > SXD * 10 ? Math.Min(255, sxsens * gyroX * 2) : 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DS4Controls.GyroXNeg:
|
||||||
|
{
|
||||||
|
int gyroX = eState.GyroX;
|
||||||
|
result = (byte)(!sOff && sxsens * gyroX < -SXD * 10 ? Math.Min(255, sxsens * -gyroX * 2) : 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DS4Controls.GyroZPos:
|
||||||
|
{
|
||||||
|
int gyroZ = eState.GyroZ;
|
||||||
|
result = (byte)(!sOff && szsens * gyroZ > SZD * 10 ? Math.Min(255, szsens * gyroZ * 2) : 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DS4Controls.GyroZNeg:
|
||||||
|
{
|
||||||
|
int gyroZ = eState.GyroZ;
|
||||||
|
result = (byte)(!sOff && szsens * gyroZ < -SZD * 10 ? Math.Min(255, szsens * -gyroZ * 2) : 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2433,7 +2481,7 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
||||||
{
|
{
|
||||||
bool sOff = UseSAforMouse[device];
|
bool sOff = isUsingSAforMouse(device);
|
||||||
|
|
||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
@ -2541,9 +2589,9 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
|
||||||
{
|
{
|
||||||
double SXD = SXDeadzone[device];
|
double SXD = getSXDeadzone(device);
|
||||||
double SZD = SZDeadzone[device];
|
double SZD = getSZDeadzone(device);
|
||||||
bool sOff = UseSAforMouse[device];
|
bool sOff = isUsingSAforMouse(device);
|
||||||
|
|
||||||
switch (control)
|
switch (control)
|
||||||
{
|
{
|
||||||
|
@ -334,6 +334,10 @@ namespace DS4Windows
|
|||||||
return m_Config.useTPforControls[index];
|
return m_Config.useTPforControls[index];
|
||||||
}
|
}
|
||||||
public static bool[] UseSAforMouse => m_Config.useSAforMouse;
|
public static bool[] UseSAforMouse => m_Config.useSAforMouse;
|
||||||
|
public static bool isUsingSAforMouse(int index)
|
||||||
|
{
|
||||||
|
return m_Config.useSAforMouse[index];
|
||||||
|
}
|
||||||
public static string[] SATriggers => m_Config.sATriggers;
|
public static string[] SATriggers => m_Config.sATriggers;
|
||||||
public static int[] GyroSensitivity => m_Config.gyroSensitivity;
|
public static int[] GyroSensitivity => m_Config.gyroSensitivity;
|
||||||
public static int[] GyroInvert => m_Config.gyroInvert;
|
public static int[] GyroInvert => m_Config.gyroInvert;
|
||||||
@ -370,7 +374,15 @@ namespace DS4Windows
|
|||||||
return m_Config.r2Deadzone[index];
|
return m_Config.r2Deadzone[index];
|
||||||
}
|
}
|
||||||
public static double[] SXDeadzone => m_Config.SXDeadzone;
|
public static double[] SXDeadzone => m_Config.SXDeadzone;
|
||||||
|
public static double getSXDeadzone(int index)
|
||||||
|
{
|
||||||
|
return m_Config.SXDeadzone[index];
|
||||||
|
}
|
||||||
public static double[] SZDeadzone => m_Config.SZDeadzone;
|
public static double[] SZDeadzone => m_Config.SZDeadzone;
|
||||||
|
public static double getSZDeadzone(int index)
|
||||||
|
{
|
||||||
|
return m_Config.SZDeadzone[index];
|
||||||
|
}
|
||||||
public static int[] LSDeadzone => m_Config.LSDeadzone;
|
public static int[] LSDeadzone => m_Config.LSDeadzone;
|
||||||
public static int getLSDeadzone(int index)
|
public static int getLSDeadzone(int index)
|
||||||
{
|
{
|
||||||
@ -422,7 +434,15 @@ namespace DS4Windows
|
|||||||
return m_Config.r2Sens[index];
|
return m_Config.r2Sens[index];
|
||||||
}
|
}
|
||||||
public static double[] SXSens => m_Config.SXSens;
|
public static double[] SXSens => m_Config.SXSens;
|
||||||
|
public static double getSXSens(int index)
|
||||||
|
{
|
||||||
|
return m_Config.SXSens[index];
|
||||||
|
}
|
||||||
public static double[] SZSens => m_Config.SZSens;
|
public static double[] SZSens => m_Config.SZSens;
|
||||||
|
public static double getSZSens(int index)
|
||||||
|
{
|
||||||
|
return m_Config.SZSens[index];
|
||||||
|
}
|
||||||
public static double[] LSSens => m_Config.LSSens;
|
public static double[] LSSens => m_Config.LSSens;
|
||||||
public static double getLSSens(int index)
|
public static double getLSSens(int index)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user