From 7e7970830fe5e8902a84a580ca66a853926b10f6 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Mon, 2 Feb 2009 23:36:07 +0100 Subject: [PATCH] dinput: Fix effect direction conversion from DIEFF_CARTESIAN coordinates. --- dlls/dinput/effect_linuxinput.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dlls/dinput/effect_linuxinput.c b/dlls/dinput/effect_linuxinput.c index b309af9e805..3c86a34489d 100644 --- a/dlls/dinput/effect_linuxinput.c +++ b/dlls/dinput/effect_linuxinput.c @@ -55,6 +55,7 @@ struct LinuxInputEffectImpl struct ff_effect effect; /* Effect data */ int gain; /* Effect gain */ + int first_axis_is_x; int* fd; /* Parent device */ struct list *entry; /* Entry into the parent's list of effects */ }; @@ -548,6 +549,7 @@ static HRESULT WINAPI LinuxInputEffectImpl_SetParameters( return DIERR_INVALIDPARAM; else if (peff->cAxes < 1) return DIERR_INCOMPLETEEFFECT; + This->first_axis_is_x = peff->rgdwAxes[0] == DIJOFS_X; } /* some of this may look funky, but it's 'cause the linux driver and directx have @@ -572,15 +574,15 @@ static HRESULT WINAPI LinuxInputEffectImpl_SetParameters( } } else { /* two axes */ if (peff->dwFlags & DIEFF_CARTESIAN) { - /* avoid divide-by-zero */ - if (peff->rglDirection[1] == 0) { - if (peff->rglDirection[0] >= 0) - This->effect.direction = 0x4000; - else if (peff->rglDirection[0] < 0) - This->effect.direction = 0xC000; + LONG x, y; + if (This->first_axis_is_x) { + x = peff->rglDirection[0]; + y = peff->rglDirection[1]; } else { - This->effect.direction = (int)(atan(peff->rglDirection[0] / peff->rglDirection[1]) * 0x7FFF / (3 * M_PI)); + 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 */ -- 2.11.4.GIT