mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-23 09:49:16 +01:00
Take current stick direction into account for mouse offset
This commit is contained in:
parent
ab9c3abe05
commit
1fc77c5537
@ -141,7 +141,9 @@ namespace DS4Windows
|
|||||||
public static int prevmouseaccel = 0;
|
public static int prevmouseaccel = 0;
|
||||||
private static double horizontalRemainder = 0.0, verticalRemainder = 0.0;
|
private static double horizontalRemainder = 0.0, verticalRemainder = 0.0;
|
||||||
private const int MOUSESPEEDFACTOR = 40;
|
private const int MOUSESPEEDFACTOR = 40;
|
||||||
private const double MOUSESTICKOFFSET = 0.025;
|
private const double MOUSESTICKOFFSET = 0.03;
|
||||||
|
private static double tempMouseOffsetX = 0.0;
|
||||||
|
private static double tempMouseOffsetY = 0.0;
|
||||||
|
|
||||||
public static void Commit(int device)
|
public static void Commit(int device)
|
||||||
{
|
{
|
||||||
@ -2339,7 +2341,10 @@ namespace DS4Windows
|
|||||||
if (cState.LX < 127 - deadzoneL)
|
if (cState.LX < 127 - deadzoneL)
|
||||||
{
|
{
|
||||||
double diff = -(cState.LX - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
|
double diff = -(cState.LX - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = MOUSESTICKOFFSET;
|
||||||
|
tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = -(cState.LX - 127 - deadzoneL) / 2550d * speed;
|
//value = -(cState.LX - 127 - deadzoneL) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2351,7 +2356,10 @@ namespace DS4Windows
|
|||||||
if (cState.LX > 127 + deadzoneL)
|
if (cState.LX > 127 + deadzoneL)
|
||||||
{
|
{
|
||||||
double diff = (cState.LX - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
|
double diff = (cState.LX - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = (cState.LX - 127 + deadzoneL) / 2550d * speed;
|
//value = (cState.LX - 127 + deadzoneL) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2363,7 +2371,10 @@ namespace DS4Windows
|
|||||||
if (cState.RX < 127 - deadzoneR)
|
if (cState.RX < 127 - deadzoneR)
|
||||||
{
|
{
|
||||||
double diff = -(cState.RX - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
|
double diff = -(cState.RX - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = -(cState.RX - 127 - deadzoneR) / 2550d * speed;
|
//value = -(cState.RX - 127 - deadzoneR) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2375,7 +2386,10 @@ namespace DS4Windows
|
|||||||
if (cState.RX > 127 + deadzoneR)
|
if (cState.RX > 127 + deadzoneR)
|
||||||
{
|
{
|
||||||
double diff = (cState.RX - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
|
double diff = (cState.RX - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = (cState.RX - 127 + deadzoneR) / 2550d * speed;
|
//value = (cState.RX - 127 + deadzoneR) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2387,7 +2401,10 @@ namespace DS4Windows
|
|||||||
if (cState.LY < 127 - deadzoneL)
|
if (cState.LY < 127 - deadzoneL)
|
||||||
{
|
{
|
||||||
double diff = -(cState.LY - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
|
double diff = -(cState.LY - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = -(cState.LY - 127 - deadzoneL) / 2550d * speed;
|
//value = -(cState.LY - 127 - deadzoneL) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2399,7 +2416,10 @@ namespace DS4Windows
|
|||||||
if (cState.LY > 127 + deadzoneL)
|
if (cState.LY > 127 + deadzoneL)
|
||||||
{
|
{
|
||||||
double diff = (cState.LY - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
|
double diff = (cState.LY - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = (cState.LY - 127 + deadzoneL) / 2550d * speed;
|
//value = (cState.LY - 127 + deadzoneL) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2411,7 +2431,10 @@ namespace DS4Windows
|
|||||||
if (cState.RY < 127 - deadzoneR)
|
if (cState.RY < 127 - deadzoneR)
|
||||||
{
|
{
|
||||||
double diff = -(cState.RY - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
|
double diff = -(cState.RY - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = -(cState.RY - 127 - deadzoneR) / 2550d * speed;
|
//value = -(cState.RY - 127 - deadzoneR) / 2550d * speed;
|
||||||
}
|
}
|
||||||
@ -2423,7 +2446,10 @@ namespace DS4Windows
|
|||||||
if (cState.RY > 127 + deadzoneR)
|
if (cState.RY > 127 + deadzoneR)
|
||||||
{
|
{
|
||||||
double diff = (cState.RY - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
|
double diff = (cState.RY - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
|
||||||
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - MOUSESTICKOFFSET) * diff + MOUSESTICKOFFSET;
|
tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = MOUSESTICKOFFSET;
|
||||||
|
//tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
|
||||||
|
value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
|
||||||
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
//value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
|
||||||
//value = (cState.RY - 127 + deadzoneR) / 2550d * speed;
|
//value = (cState.RY - 127 + deadzoneR) / 2550d * speed;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,12 @@ namespace DS4Windows
|
|||||||
public byte Battery; // 0 for charging, 10/20/30/40/50/60/70/80/90/100 for percentage of full
|
public byte Battery; // 0 for charging, 10/20/30/40/50/60/70/80/90/100 for percentage of full
|
||||||
public double LSAngle; // Calculated bearing of the LS X,Y coordinates
|
public double LSAngle; // Calculated bearing of the LS X,Y coordinates
|
||||||
public double RSAngle; // Calculated bearing of the RS X,Y coordinates
|
public double RSAngle; // Calculated bearing of the RS X,Y coordinates
|
||||||
|
public double LSAngleRad; // Calculated bearing of the LS X,Y coordinates (in radians)
|
||||||
|
public double RSAngleRad; // Calculated bearing of the RS X,Y coordinates (in radians)
|
||||||
|
public double LXUnit;
|
||||||
|
public double LYUnit;
|
||||||
|
public double RXUnit;
|
||||||
|
public double RYUnit;
|
||||||
public static readonly int DEFAULT_AXISDIR_VALUE = 127;
|
public static readonly int DEFAULT_AXISDIR_VALUE = 127;
|
||||||
|
|
||||||
public DS4State()
|
public DS4State()
|
||||||
@ -30,7 +36,13 @@ namespace DS4Windows
|
|||||||
TouchPacketCounter = 255; // 8 bits, no great junk value
|
TouchPacketCounter = 255; // 8 bits, no great junk value
|
||||||
Battery = 0;
|
Battery = 0;
|
||||||
LSAngle = 0.0;
|
LSAngle = 0.0;
|
||||||
|
LSAngleRad = 0.0;
|
||||||
RSAngle = 0.0;
|
RSAngle = 0.0;
|
||||||
|
RSAngleRad = 0.0;
|
||||||
|
LXUnit = 0.0;
|
||||||
|
LYUnit = 0.0;
|
||||||
|
RXUnit = 0.0;
|
||||||
|
RYUnit = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DS4State(DS4State state)
|
public DS4State(DS4State state)
|
||||||
@ -68,7 +80,13 @@ namespace DS4Windows
|
|||||||
FrameCounter = state.FrameCounter;
|
FrameCounter = state.FrameCounter;
|
||||||
Battery = state.Battery;
|
Battery = state.Battery;
|
||||||
LSAngle = state.LSAngle;
|
LSAngle = state.LSAngle;
|
||||||
|
LSAngleRad = state.LSAngleRad;
|
||||||
RSAngle = state.RSAngle;
|
RSAngle = state.RSAngle;
|
||||||
|
RSAngleRad = state.RSAngleRad;
|
||||||
|
LXUnit = state.LXUnit;
|
||||||
|
LYUnit = state.LYUnit;
|
||||||
|
RXUnit = state.RXUnit;
|
||||||
|
RYUnit = state.RYUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DS4State Clone()
|
public DS4State Clone()
|
||||||
@ -111,18 +129,30 @@ namespace DS4Windows
|
|||||||
state.FrameCounter = FrameCounter;
|
state.FrameCounter = FrameCounter;
|
||||||
state.Battery = Battery;
|
state.Battery = Battery;
|
||||||
state.LSAngle = LSAngle;
|
state.LSAngle = LSAngle;
|
||||||
|
state.LSAngleRad = LSAngleRad;
|
||||||
state.RSAngle = RSAngle;
|
state.RSAngle = RSAngle;
|
||||||
|
state.RSAngleRad = RSAngleRad;
|
||||||
|
state.LXUnit = LXUnit;
|
||||||
|
state.LYUnit = LYUnit;
|
||||||
|
state.RXUnit = RXUnit;
|
||||||
|
state.RYUnit = RYUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateStickAngles()
|
public void calculateStickAngles()
|
||||||
{
|
{
|
||||||
double lsangle = Math.Atan2((LX - 127), -(LY - 127));
|
double lsangle = Math.Atan2((LX - 127), -(LY - 127));
|
||||||
|
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));
|
||||||
|
LYUnit = Math.Abs(Math.Sin(LSAngleRad));
|
||||||
|
|
||||||
double rsangle = Math.Atan2((RX - 127), -(RY - 127));
|
double rsangle = Math.Atan2((RX - 127), -(RY - 127));
|
||||||
|
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;
|
||||||
|
RXUnit = Math.Abs(Math.Cos(RSAngleRad));
|
||||||
|
RYUnit = Math.Abs(Math.Sin(LSAngleRad));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user