mirror of
https://github.com/AppleWin/AppleWin.git
synced 2024-05-28 17:41:37 +00:00
Joystick: Stylistic improvements to code (#429)
This commit is contained in:
parent
cac30b31ed
commit
f8d238f2b0
|
@ -729,13 +729,16 @@ void JoyResetPosition(ULONG nExecutedCycles)
|
||||||
if (isJoystick[joyNum])
|
if (isJoystick[joyNum])
|
||||||
{
|
{
|
||||||
// Convert to unit circle, centred at (0,0)
|
// Convert to unit circle, centred at (0,0)
|
||||||
const double x[2] = { ((double)xpos[joyNum]) / (0.5 * 255) - 1.0, ((double)ypos[joyNum]) / (0.5 * 255) - 1.0};
|
const double scalar = 0.5 * 255.0;
|
||||||
double axis = x[pdl & 1];
|
const double offset = 1.0;
|
||||||
|
const double x = ((double)xpos[joyNum]) / scalar - offset;
|
||||||
|
const double y = ((double)ypos[joyNum]) / scalar - offset;
|
||||||
|
double axis = !(pdl & 1) ? x : y;
|
||||||
|
|
||||||
if (x[0] * x[1] != 0.0)
|
if (x * y != 0.0)
|
||||||
{
|
{
|
||||||
// rescale the circle to the square
|
// rescale the circle to the square
|
||||||
const double ratio2 = (x[1] * x[1]) / (x[0] * x[0]);
|
const double ratio2 = (y * y) / (x * x);
|
||||||
const double c = min(ratio2, 1.0 / ratio2);
|
const double c = min(ratio2, 1.0 / ratio2);
|
||||||
const double coeff = sqrt(1.0 + c);
|
const double coeff = sqrt(1.0 + c);
|
||||||
axis *= coeff;
|
axis *= coeff;
|
||||||
|
@ -744,7 +747,7 @@ void JoyResetPosition(ULONG nExecutedCycles)
|
||||||
if (axis < -1.0) axis = -1.0;
|
if (axis < -1.0) axis = -1.0;
|
||||||
else if (axis > 1.0) axis = 1.0;
|
else if (axis > 1.0) axis = 1.0;
|
||||||
|
|
||||||
pdlPos = static_cast<int>((axis + 1.0) * 0.5 * 255);
|
pdlPos = static_cast<int>((axis + offset) * scalar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is from KEGS. It helps games like Championship Lode Runner, Boulderdash & Learning with Leeper(GH#1128)
|
// This is from KEGS. It helps games like Championship Lode Runner, Boulderdash & Learning with Leeper(GH#1128)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user