Rémi Bernon : dinput: Fix DIEFF_CARTESIAN to DIEFF_SPHERICAL conversion.

Alexandre Julliard julliard at winehq.org
Wed Nov 10 15:34:48 CST 2021


Module: wine
Branch: master
Commit: 0697d1caf1b33e3921015490002a4a94ff54b4dc
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0697d1caf1b33e3921015490002a4a94ff54b4dc

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Wed Nov 10 10:52:28 2021 +0100

dinput: Fix DIEFF_CARTESIAN to DIEFF_SPHERICAL conversion.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/joystick_hid.c | 10 ++++++++--
 dlls/dinput8/tests/hid.c   |  3 ---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index a9716b20ab5..5a3c46e2d9a 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -2019,13 +2019,19 @@ static BOOL get_parameters_object_ofs( struct hid_joystick *impl, struct hid_val
 
 static void convert_directions_to_spherical( const DIEFFECT *in, DIEFFECT *out )
 {
-    DWORD i, direction_flags = DIEFF_CARTESIAN | DIEFF_POLAR | DIEFF_SPHERICAL;
+    DWORD i, j, direction_flags = DIEFF_CARTESIAN | DIEFF_POLAR | DIEFF_SPHERICAL;
+    double tmp;
 
     switch (in->dwFlags & direction_flags)
     {
     case DIEFF_CARTESIAN:
         for (i = 1; i < in->cAxes; ++i)
-            out->rglDirection[i - 1] = atan2( in->rglDirection[i], in->rglDirection[0] );
+        {
+            tmp = in->rglDirection[0];
+            for (j = 1; j < i; ++j) tmp = sqrt( tmp * tmp + in->rglDirection[j] * in->rglDirection[j] );
+            tmp = atan2( in->rglDirection[i], tmp );
+            out->rglDirection[i - 1] = tmp * 18000 / M_PI;
+        }
         out->rglDirection[in->cAxes - 1] = 0;
         out->cAxes = in->cAxes;
         break;
diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c
index 5f89f13146a..66e8c7c0b0d 100644
--- a/dlls/dinput8/tests/hid.c
+++ b/dlls/dinput8/tests/hid.c
@@ -6085,7 +6085,6 @@ static void test_periodic_effect( IDirectInputDevice8W *device, HANDLE file, DWO
         }
         else
         {
-            todo_wine
             ok( desc.rglDirection[0] == 6343, "got rglDirection[0] %d expected %d\n",
                 desc.rglDirection[0], 6343 );
             if (i == 2)
@@ -6097,7 +6096,6 @@ static void test_periodic_effect( IDirectInputDevice8W *device, HANDLE file, DWO
             }
             else
             {
-                todo_wine
                 ok( desc.rglDirection[1] == 5330, "got rglDirection[1] %d expected %d\n",
                     desc.rglDirection[1], 5330 );
                 ok( desc.rglDirection[2] == 0, "got rglDirection[2] %d expected %d\n",
@@ -6141,7 +6139,6 @@ static void test_periodic_effect( IDirectInputDevice8W *device, HANDLE file, DWO
         {
             ok( hr == DI_OK, "GetParameters returned %#x\n", hr );
             ok( desc.cAxes == i, "got cAxes %u expected 2\n", desc.cAxes );
-            todo_wine
             ok( desc.rglDirection[0] == 15343, "got rglDirection[0] %d expected %d\n",
                 desc.rglDirection[0], 15343 );
             ok( desc.rglDirection[1] == 0, "got rglDirection[1] %d expected %d\n", desc.rglDirection[1], 0 );




More information about the wine-cvs mailing list