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 - win32 version of haptic can't store negative cartesian coordinates
Summary: win32 version of haptic can't store negative cartesian coordinates
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-23 21:31 UTC by Joe
Modified: 2009-11-27 11:30 UTC (History)
0 users

See Also:


Attachments
Proposed fix for the problem (436 bytes, patch)
2009-11-26 21:44 UTC, Joe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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!