[2/2] [try2] dinput: Fix direction computation code

Vincent Pelletier plr.vincent at gmail.com
Fri Jan 23 18:57:32 CST 2009


Le Saturday 24 January 2009 01:38:40 Vincent Pelletier, vous avez écrit :
> Comparison of values generated:
> - Lower left: x=-1, y=-1, upper right: x=1, y=1

My bad: on Windows, left == x > 0, right == x < 0.
Fixed in attached patch.

-- 
Vincent Pelletier
-------------- next part --------------
From 3970c17834487228924344e536a3d83ee56012b4 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <plr.vincent at gmail.com>
Date: Sat, 24 Jan 2009 01:08:41 +0100
Subject: Fix effect direction computation code when effect are configured 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])

---
 dlls/dinput/effect_linuxinput.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/dlls/dinput/effect_linuxinput.c b/dlls/dinput/effect_linuxinput.c
index f57f1be..62e10aa 100644
--- a/dlls/dinput/effect_linuxinput.c
+++ b/dlls/dinput/effect_linuxinput.c
@@ -576,15 +576,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 (peff->rgdwAxes[0] == DIJOFS_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