fljot / Gestouch

Gestouch: multitouch gesture recognition library for Flash (ActionScript) development.
MIT License
356 stars 84 forks source link

Gesture Location Coordinate Plane #25

Closed sidesixmedia closed 12 years ago

sidesixmedia commented 12 years ago

It seems like the Gesture.location parameter is always returned as a point in the global coordinate space rather than in the Gesture.target space. Is this intentional or am I misusing the interface somehow?

This makes Starling integration more complicated, especially because the contentScaleFactor is not taken into account when reporting the touch location. That means in order to use the Gesture.location value the developer must:

  1. Translate it from Global to the Gesture.target
  2. Divide the X and Y values by the Starling contentScaleFactor (if applicable)
  3. Translate the X and Y values depending on if the Gesture.target resides at (0,0)

I realize these aren't necessarily the responsibility of the GesTouch engine, but it would be great to see a more straightforward way to benefit from the Gesture.location value.

Excellent work by the way!

fljot commented 12 years ago

Yes, it's in global (screen) coordinate space. Since I migrated from flash.display.DisplayObject to more abstract targets I'm also trying to get rid of unnecessary dependencies such as globalToLocal and localToGlobal (where possible). Location initially is calculated in global coordinate space, so just let it stay like this. Once you need to transform you can always do that. Also I bet you mostly need it it target.parent space, right?

So regarding Starling... Doesn't globalToLocal() takes contentScaleFactor into account? Well anyhow, you could write some utility method that does all this calculations (you don't need these calculations often, so it's not a performance issue, right?). Also note that Starling's "global" is not really a "screen global coordinate space" (that's why I have this utility https://github.com/fljot/Gestouch/blob/master/src/org/gestouch/extensions/starling/StarlingUtils.as ), so you might also need to include this into your calculations.

And thank you.

sidesixmedia commented 12 years ago

Thanks, fljot. I didn't notice the StarlingUtils extension, but that will definitely come in handy. I realized my "Step 3" was due to an error in my own script, not Gestouch or Starling, so scratch that off the list too.

We've rolled our own gesture support before since the default Flash "swipe" recognition is so bad, but GesTouch takes things well beyond that.

Keep up the good work.