This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest…
… to test/testgesture
- Loading branch information
Showing
10 changed files
with
464 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
=========================================================================== | ||
Dollar Gestures | ||
=========================================================================== | ||
SDL Provides an implementation of the $1 gesture recognition system. This allows for recording, saving, loading, and performing single stroke gestures. | ||
|
||
Gestures can be performed with any number of fingers (the centroid of the fingers must follow the path of the gesture), but the number of fingers must be constant (a finger cannot go down in the middle of a gesture). The path of a gesture is considered the path from the time when the final finger went down, to the first time any finger comes up. | ||
|
||
Dollar gestures are assigned an Id based on a hash function. This is guaranteed to remain constant for a given gesture. There is a (small) chance that two different gestures will be assigned the same ID. In this simply re-recording on of the gestures should result in a different ID. | ||
|
||
Recording: | ||
---------- | ||
To begin recording on a touch device call: | ||
SDL_RecordGesture(SDL_TouchID touchId), where touchId is the id of the touch device you wish to record on, or -1 to record on all connected devices. | ||
|
||
Recording terminates as soon as a finger comes up. Recording is acknowledged by an SDL_DOLLARRECORD event. | ||
A SDL_DOLLARRECORD event is a dgesture with the following fields: | ||
|
||
event.dgesture.touchId - the Id of the touch used to record the gesture. | ||
event.dgesture.gestureId - the unique id of the recoreded gesture. | ||
|
||
|
||
|
||
Performing: | ||
----------- | ||
As long as there is a dollar gesture assigned to a touch, every finger-up event will also cause an SDL_DOLLARGESTURE event with the following fields: | ||
|
||
event.dgesture.touchId - the Id of the touch which performed the gesture. | ||
event.dgesture.gestureId - the unique id of the closest gesture to the performed stroke. | ||
event.dgesture.error - the difference between the gesture template and the actual performed gesture. Lower error is a better match. | ||
event.dgesture.numFingers - the number of fingers used to draw the stroke. | ||
|
||
Most programs will want to define an appropriate error threshold and check to be sure taht the error of a gesture is not abnormally high (an indicator that no gesture was performed). | ||
|
||
|
||
|
||
Saving: | ||
------- | ||
To save a template, call SDL_SaveDollarTemplate(gestureId, src) where gestureId is the id of the gesture you want to save, and src is an SDL_RWops pointer to the file where the gesture will be stored. | ||
|
||
To save all currently loaded templatesm, call SDL_SaveAllDollarTemplates(src) where source is an SDL_RWops pointer to the file where the gesture will be stored. | ||
|
||
Both functions return the number of gestures sucessfully saved. | ||
|
||
|
||
Loading: | ||
-------- | ||
To load templates from a file, call SDL_LoadDollarTemplates(touchId,src) where touchId is the id of the touch to load to (or -1 to load to all touch devices), and src is an SDL_RWops pointer to a gesture save file. | ||
|
||
SDL_LoadDollarTemplates returns the number of templates sucessfully loaded. | ||
|
||
|
||
|
||
=========================================================================== | ||
Multi Gestures | ||
=========================================================================== | ||
SDL provides simple support to pinch/rotate/swipe gestures. | ||
Every time a finger is moved an SDL_MULTIGESTURE event is sent with the following fields: | ||
|
||
event.mgesture.touchId - the Id of the touch on which the gesture was performed. | ||
event.mgesture.x - the normalized x cooridinate of the gesture. (0..1) | ||
event.mgesture.y - the normalized y cooridinate of the gesture. (0..1) | ||
event.mgesture.dTheta - the amount that the fingers rotated during this motion. | ||
event.mgesture.dDist - the amount that the fingers pinched during this motion. | ||
event.mgesture.numFingers - the number of fingers used in the gesture. | ||
|
||
|
||
=========================================================================== | ||
Notes | ||
=========================================================================== | ||
For a complete example see test/testgesture.c | ||
|
||
Please direct questions/comments to: | ||
jim.tla+sdl_touch@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
=========================================================================== | ||
Events | ||
=========================================================================== | ||
SDL_FINGERDOWN: | ||
Sent when a finger (or stylus) is placed on a touch device. | ||
Fields: | ||
event.tfinger.touchId - the Id of the touch device. | ||
event.tfinger.fingerId - the Id of the finger which just went down. | ||
event.tfinger.x - the x coordinate of the touch (0..touch.xres) | ||
event.tfinger.y - the y coordinate of the touch (0..touch.yres) | ||
event.tfinger.pressure - the pressure of the touch (0..touch.pressureres) | ||
|
||
SDL_FINGERMOTION: | ||
Sent when a finger (or stylus) is moved on the touch device. | ||
Fields: | ||
Same as FINGERDOWN but with additional: | ||
event.tfginer.dx - chagne in x coordinate during this motion event. | ||
event.tfginer.dy - chagne in y coordinate during this motion event. | ||
|
||
SDL_FINGERMOTION: | ||
Sent when a finger (or stylus) is lifted from the touch device. | ||
Fields: | ||
Same as FINGERDOWN. | ||
|
||
|
||
=========================================================================== | ||
Functions | ||
=========================================================================== | ||
SDL provides the ability to access the underlying Touch and Finger structures. | ||
These structures should _never_ be modified. | ||
|
||
The following functions are included from SDL_Touch.h | ||
|
||
To get a SDL_Touch device call SDL_GetTouch(touchId). | ||
This returns an SDL_Touch*. | ||
IMPORTANT: If the touch has been removed, or there is no touch with the given ID, SDL_GetTouch will return null. Be sure to check for this! | ||
|
||
An SDL_Touch has the following fields: | ||
>pressure_max, pressure_min, x_max, x_min, y_max, y_min | ||
Which give, respectively, the maximum and minumum values that the touch digitizer can return for pressure, x coordiniate, and y coordinate AS REPORTED BY THE OPERATING SYSTEM. | ||
On Mac/iPhone systems _max will always be 0, and _min will always be 1. | ||
|
||
>xres,yres,pressures: | ||
The resolution at which x,y, and pressure values are reported. Currently these will always be equal to 2^15, but this may not always be the case. | ||
|
||
>native_xres,native_yres,native_pressureres: | ||
The native resolution of the touch device AS REPORTED BY THE OPERATING SYSTEM. | ||
On Mac/iPhone systems these will always be 1. | ||
|
||
>num_fingers: | ||
The number of fingers currently down on the device. | ||
|
||
>fingers: | ||
An array of pointers to the fingers which are on the device. | ||
|
||
|
||
The most common reason to get a touch device is to normalize inputs. This would look something like: | ||
|
||
SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); | ||
if(inTouch == NULL) continue; | ||
|
||
float x = ((float)event.tfinger.x)/inTouch->xres; | ||
float y = ((float)event.tfinger.y)/inTouch->yres; | ||
|
||
|
||
To get an SDL_Finger, call SDL_GetFinger(touch,fingerId), where touch is a pointer to an SDL_Touch device, and fingerId is the id of the requested finger. | ||
This returns an SDL_Finger*, or null if the finger does not exist, or has been removed. | ||
An SDL_Finger is guaranteed to be persistent for the duration of a touch, but it will be de-allocated as soon as the finger is removed. This occurs when the SDL_FINGERUP event is _added_ to the event queue, and thus BEFORE the FINGERUP event is seen. | ||
As a result, be very careful to check for null return values. | ||
|
||
An SDL_Finger has the following fields: | ||
>x,y,pressure: | ||
The current coordinates of the touch. | ||
>xdelta,ydelta: | ||
The change in position resulting from the last finger motion. | ||
>last_x, last_y, last_pressure: | ||
The previous coordinates of the touch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.