[resend] dinput: Fix effect direction conversion from DIEFF_CARTESIAN coordinates

Vincent Pelletier plr.vincent at gmail.com
Mon Feb 2 16:52:34 CST 2009


Tested with FFConst.exe from directx sdk, november 2008 version.

-- 
Vincent Pelletier
-------------- next part --------------
From 3952930642ac77432f23eaf3ff45984216ad2bb7 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <plr.vincent at gmail.com>
Date: Mon, 2 Feb 2009 23:36:07 +0100
Subject: dinput: Fix effect direction conversion from DIEFF_CARTESIAN coordinates.

---
 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 b309af9..3c86a34 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 */
-- 
1.5.6.5



More information about the wine-patches mailing list