[PATCH 3/4] dinput: Simplify cartesian and fix polar direction calculations
Bruno Jesus
00cpxxx at gmail.com
Wed Aug 24 20:55:58 CDT 2016
Based on formulas by Elias Vanderstuyft.
Manually tested on the 360 directions using joyffeed.exe (cartesian) and fedit.exe (polar) from directx 2004 sdk.
From/to (cartesian):
This->effect.direction = (int)((3 * M_PI / 2 - atan2(y, x)) * -0x7FFF / M_PI);
This->effect.direction = (unsigned int)((M_PI / 2 + atan2(y, x)) * 0x8000 / M_PI);
From/to (polar):
This->effect.direction = (int)(((double)peff->rglDirection[0] - 90) / 35999) * 0x7FFF;
This->effect.direction = (unsigned int)(((double)peff->rglDirection[0] / 18000) * 0x8000);
Signed-off-by: Bruno Jesus <00cpxxx at gmail.com>
---
dlls/dinput/effect_linuxinput.c | 43 +++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/dlls/dinput/effect_linuxinput.c b/dlls/dinput/effect_linuxinput.c
index 1b60d47..b4e7b06 100644
--- a/dlls/dinput/effect_linuxinput.c
+++ b/dlls/dinput/effect_linuxinput.c
@@ -519,23 +519,32 @@ static HRESULT WINAPI LinuxInputEffectImpl_SetParameters(
/* one-axis effects must use cartesian coords */
return DIERR_INVALIDPARAM;
}
- } else { /* two axes */
- if (peff->dwFlags & DIEFF_CARTESIAN) {
- LONG x, y;
- if (This->first_axis_is_x) {
- x = peff->rglDirection[0];
- y = peff->rglDirection[1];
- } else {
- x = peff->rglDirection[1];
- y = peff->rglDirection[0];
- }
- This->effect.direction = (int)((3 * M_PI / 2 - atan2(y, x)) * -0x7FFF / M_PI);
- } else {
- /* Polar and spherical are the same for 2 axes */
- /* Precision is important here, so we do double math with exact constants */
- This->effect.direction = (int)(((double)peff->rglDirection[0] - 90) / 35999) * 0x7FFF;
- }
- }
+ }
+ /* two axes */
+ else
+ {
+ if (peff->dwFlags & DIEFF_CARTESIAN)
+ {
+ LONG x, y;
+ if (This->first_axis_is_x)
+ {
+ x = peff->rglDirection[0];
+ y = peff->rglDirection[1];
+ }
+ else
+ {
+ x = peff->rglDirection[1];
+ y = peff->rglDirection[0];
+ }
+ This->effect.direction = (unsigned int)((M_PI / 2 + atan2(y, x)) * 0x8000 / M_PI);
+ }
+ else
+ {
+ /* Polar and spherical are the same for 2 axes */
+ /* Precision is important here, so we do double math with exact constants */
+ This->effect.direction = (unsigned int)(((double)peff->rglDirection[0] / 18000) * 0x8000);
+ }
+ }
}
if (dwFlags & DIEP_DURATION)
--
2.9.3
More information about the wine-patches
mailing list