[2/2] [try3] dinput: Fix direction computation code
Vincent Pelletier
plr.vincent at gmail.com
Fri Jan 23 20:39:31 CST 2009
Le Saturday 24 January 2009 01:57:32 Vincent Pelletier, vous avez écrit :
> My bad: on Windows, left == x > 0, right == x < 0.
> Fixed in attached patch.
My bad, 2nd:
DIEP_DIRECTION doesn not require rgdwAxes to be set, causing NULL dereference
in the new code checking axis mapping. This patch solves the problem by
storing mapping (reduced to a flag, as advised by Daniel Remenak: we only
support 2 axes at most for now) when it gets set, and it must be set for the
effect to be uploadable - so it will be initialised.
--
Vincent Pelletier
-------------- next part --------------
From 2bab906a8ea812e3f88b8460e94f63ec3583ab87 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <plr.vincent at gmail.com>
Date: Sat, 24 Jan 2009 03:23:40 +0100
Subject: Fix direction computation code when effect is defined in DIEFF_CARTESIAN mode.
- use atan2 to generate -PI..+PI angle (removes the need to care about divide-by-zero, fixes all "forward" directions not being available)
- remap axes according to effect setting (it was taken for granted that order was [DIJOFS_X,DIJOFS_Y])
Use a flag to know if first axis is X (peff->rgdwAxes can be null when DIEP_DIRECTION is provided).
---
dlls/dinput/effect_linuxinput.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/dlls/dinput/effect_linuxinput.c b/dlls/dinput/effect_linuxinput.c
index f57f1be..225960d 100644
--- a/dlls/dinput/effect_linuxinput.c
+++ b/dlls/dinput/effect_linuxinput.c
@@ -56,6 +56,7 @@ struct LinuxInputEffectImpl
struct ff_effect effect; /* Effect data */
int gain; /* Effect gain */
int state; /* Effect state */
+ int first_axis_is_x;
int* fd; /* Parent device */
struct list *entry; /* Entry into the parent's list of effects */
};
@@ -552,6 +553,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
@@ -576,15 +578,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 */
--
1.5.6.5
More information about the wine-patches
mailing list