We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2701 - Haptic coding bugs and fixes for Windows and Mac OS: wrong handling of negative periodic magnitude
Summary: Haptic coding bugs and fixes for Windows and Mac OS: wrong handling of negati...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: haptic (show other bugs)
Version: HG 2.1
Hardware: x86_64 All
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-23 20:59 UTC by Elias Vanderstuyft
Modified: 2014-09-17 18:52 UTC (History)
1 user (show)

See Also:


Attachments
Fix some typos about angle units in the Haptic API doc (1.13 KB, patch)
2014-08-23 21:01 UTC, Elias Vanderstuyft
Details | Diff
A negative periodic magnitude doesn't exist in Windows' and MacOS' FF APIs (3.54 KB, patch)
2014-08-23 21:04 UTC, Elias Vanderstuyft
Details | Diff
Effect0_Sine.png (18.48 KB, image/png)
2014-08-23 21:06 UTC, Elias Vanderstuyft
Details
Effect1_SawtoothUp.png (23.79 KB, image/png)
2014-08-23 21:06 UTC, Elias Vanderstuyft
Details
Effect2_Constant.png (21.20 KB, image/png)
2014-08-23 21:07 UTC, Elias Vanderstuyft
Details
Effect7_Ramp.png (15.71 KB, image/png)
2014-08-23 21:07 UTC, Elias Vanderstuyft
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Elias Vanderstuyft 2014-08-23 20:59:44 UTC
This is something funny, a feature of the Linux FF API that doesn't exist in Windows' and MacOS' FF APIs:
    a negative periodic magnitude.
The periodic magnitude parameter of the SDL Haptic API is based on the Linux FF API, so it means they are not directly compatible:
    'dwMagnitude' is a 'DWORD', which is unsigned.

First I fixed some typos about angle units in the Haptic API doc (first patch: "vanilla-rev1.diff").

Then I created a patch to solve the problem by adding 180 degrees phase shift when the magnitude is negative (second patch: "rev1-rev2.diff").
WARNING: this patch is UNTESTED (as is the compilation), since I don't have the necessary access to a Windows or MacOS machine. Please verify this patch before applying it!

Both patches are based on yesterday's hg snapshot: SDL-2.0.3-9108

In the second patch you can see I also edited "testhaptic.c" to test the patch's changes:
To a user, the direction of the force of "Effect0 - Sine" should remain the same before and after this patch, since a negative magnitude combined with a 180 degrees phase shift will cancel out and become a positive magnitude combined with a zero degrees phase shift.

Finally, I included some images to graphically visualize exactly how the force output of "testhaptic" should be:
    "Effect0_Sine.png"
    "Effect1_SawtoothUp.png"
    "Effect2_Constant.png"
    "Effect7_Ramp.png"
I should note here that the forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 1 Elias Vanderstuyft 2014-08-23 21:01:13 UTC
Created attachment 1841 [details]
Fix some typos about angle units in the Haptic API doc
Comment 2 Elias Vanderstuyft 2014-08-23 21:04:42 UTC
Created attachment 1842 [details]
A negative periodic magnitude doesn't exist in Windows' and MacOS' FF APIs

The periodic magnitude parameter of the SDL Haptic API is based on the Linux FF API, so it means they are not directly compatible:
    'dwMagnitude' is a 'DWORD', which is unsigned.

WARNING: this patch is UNTESTED (as is the compilation)
Comment 3 Elias Vanderstuyft 2014-08-23 21:06:26 UTC
Created attachment 1843 [details]
Effect0_Sine.png

testhaptic.c: effect[0]: Sine

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 4 Elias Vanderstuyft 2014-08-23 21:06:55 UTC
Created attachment 1844 [details]
Effect1_SawtoothUp.png

testhaptic.c: effect[1]: SawtoothUp

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 5 Elias Vanderstuyft 2014-08-23 21:07:20 UTC
Created attachment 1845 [details]
Effect2_Constant.png

testhaptic.c: effect[2]: Constant

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 6 Elias Vanderstuyft 2014-08-23 21:07:45 UTC
Created attachment 1846 [details]
Effect7_Ramp.png

testhaptic.c: effect[7]: Ramp

The forces and directions are defined in the Linux FF sense: the direction in which the force is applied by the joystick; *not* the direction where the force comes from!
Comment 7 Ryan C. Gordon 2014-09-17 18:52:17 UTC
These patches are in revision control now, thanks!

    https://hg.libsdl.org/SDL/rev/dbef1f283c3f
    https://hg.libsdl.org/SDL/rev/6bf589c8d549

--ryan.