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 892

Summary: win32 version of haptic can't store negative cartesian coordinates
Product: SDL Reporter: Joe <lossanaght>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: Windows (All)   
Attachments: Proposed fix for the problem

Description Joe 2009-11-23 21:31:10 UTC
If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
367	 *  (X axis, Y axis and Z axis (with 3 axes)).  ::SDL_HAPTIC_CARTESIAN uses
368	 *  the first three \c dir parameters.  The cardinal directions would be:
369	 *   - North:  0,-1, 0
370	 *   - East:  -1, 0, 0
371	 *   - South:  0, 1, 0
372	 *   - West:   1, 0, 0

typedef struct SDL_HapticDirection
{
    Uint8 type;         /**< The type of encoding. */
    Uint16 dir[3];      /**< The encoded direction. */ 
} SDL_HapticDirection;

An unsigned int can't store negative values and I don't see an alternate way to encode them in the docs or source. The best I have been able to come up with is using a negative magnitude for the effect but this will only get me 2 of the 4 quadrants in the plane for 2d effects. I looked at the win32 and linux implementations and I believe is is safe to use signed ints in the direction struct. I am unfamiliar with the darwin haptics API so I don't know if it is safe.

414    Sint16 dir[3];      /**< The encoded direction. */
Comment 1 Joe 2009-11-23 21:55:02 UTC
Just about as soon as I hit submit I realized that an Sint16 has a max positive value of 32767, which conflicts with the way polar coords are defined in the header. Widening to Sint32 seems to be a quick fix, as opposed to shifting polar to a -18000 to 18000 format or setting the origin in cartesian coords to 32767.
Comment 2 Joe 2009-11-26 21:44:46 UTC
Created attachment 451 [details]
Proposed fix for the problem

I have been using this patch in windows in cartesian mode and it is working properly. I believe it's safe for the linux api basd on source code but not actually tested just yet. I don't have access to an OSX system so I don't have a way to test that platform.
Comment 3 Sam Lantinga 2009-11-27 11:30:16 UTC
This fix looks good to me, and by the API docs the values clearly have to be signed. :)

Thanks!