Added Clamping to Joystick Values
Added Clamp function to general.c Now clamps all final joystick values to be from 0 - 32767 (2^15 - 1). Output from the 3ds was giving a strange range on the values, even though the code expected it to be in the range -128 to 128. Was more like -146 to 146 on the c-stick, and -170 to 170 on the circle pad. This may remove some of the resolution of the sticks, but increase compatability with programs.
This commit is contained in:
parent
63268cd32e
commit
f5bc0146d7
4 changed files with 36 additions and 22 deletions
Binary file not shown.
|
@ -3,3 +3,5 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void error(const char *functionName);
|
||||
|
||||
int clamp(int val, int min, int max);
|
||||
|
|
|
@ -16,3 +16,15 @@ void error(const char *functionName) {
|
|||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int clamp (int val, int min, int max) {
|
||||
if (val < min) {
|
||||
return min;
|
||||
}
|
||||
|
||||
if (val > max) {
|
||||
return max;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -216,13 +216,13 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
|
|||
SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32);
|
||||
}
|
||||
else if(settings.circlePad == joystick1) {
|
||||
joyX = (circlePad.x + 128) * 128;
|
||||
joyY = (128 - circlePad.y) * 128;
|
||||
joyX = clamp((circlePad.x + 128) * 128, 0, 32767);
|
||||
joyY = clamp((128 - circlePad.y) * 128, 0, 32767);
|
||||
}
|
||||
|
||||
else if(settings.circlePad == joystick2) {
|
||||
joyRX = (circlePad.x + 128) * 128;
|
||||
joyRY = (128 - circlePad.y) * 128;
|
||||
joyRX = clamp((circlePad.x + 128) * 128, 0, 32767);
|
||||
joyRY = clamp((128 - circlePad.y) * 128, 0, 32767);
|
||||
}
|
||||
|
||||
if(settings.cStick == mouse) {
|
||||
|
@ -235,13 +235,13 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
|
|||
}
|
||||
|
||||
else if(settings.cStick == joystick1) {
|
||||
joyX = (cStick.x + 128) * 128;
|
||||
joyY = (128 - cStick.y) * 128;
|
||||
joyX = clamp((cStick.x + 128) * 128, 0, 32767);
|
||||
joyY = clamp((128 - cStick.y) * 128, 0, 32767);
|
||||
}
|
||||
|
||||
else if(settings.cStick == joystick2) {
|
||||
joyRX = (cStick.x + 128) * 128;
|
||||
joyRY = (128 - cStick.y) * 128;
|
||||
joyRX = clamp((cStick.x + 128) * 128, 0, 32767);
|
||||
joyRY = clamp((128 - cStick.y) * 128, 0, 32767);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue