fljot / Gestouch

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

ZoomGesture: infinity scaleX/scaleY when touching and clicking #76

Open rdoi opened 9 years ago

rdoi commented 9 years ago

This is a very specific situation when using a device that have both mouse and touch capabilities (Win8).

If you click down with the mouse (keep pressed) and then touch and pan around with the finger somewhere else, a ZoomGesture is detected with a serie of scaleX and scaleY with 0 and "Infinity" values.

Not sure what should be the best behavior in this case, but I think "Infinity" value should not happen.

Here is a quick code:

package {
    import org.gestouch.core.Gestouch;
    import org.gestouch.events.GestureEvent;
    import org.gestouch.gestures.ZoomGesture;
    import org.gestouch.input.NativeInputAdapter;

    import flash.display.Sprite;
    import flash.events.Event;

    public class ZoomTester extends Sprite {
        private var zoomGesture : ZoomGesture ;

        public function ZoomTester() {
            addEventListener(Event.ADDED_TO_STAGE, onStage);    
        }

        private function onStage(event : Event) : void {
            Gestouch.inputAdapter = new NativeInputAdapter(this.stage, true, true);

            const s:Sprite= new Sprite();
            s.graphics.beginFill(0x00ffff);
            s.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            addChild(s);

            zoomGesture= new ZoomGesture(this);
            zoomGesture.addEventListener(GestureEvent.GESTURE_CHANGED, onZoom);
        }

        private function onZoom(event : GestureEvent) : void {
            trace("Zoom:", zoomGesture.scaleX, zoomGesture.scaleY);
        }

    }
}
fljot commented 9 years ago

@rdoi totally shouldn't.

I've added some logging (check out recent commits in develop). You can compile against source code (but you will need to add conditional compilation flag CONFIG::GestouchDebug true) or build debug swc first: Maven: mvn clean package -Dprofile=debug

or Ant: ant compile.swc.debug

check out the logs and we'll see what kind of problem between touch and mouse events you have.

rdoi commented 9 years ago

Well, I am not sure if I've expressed myself correctly.

There is a problem in the zoom gesture recognition when a mouse and touch happens at same time, in which the reported scale (offset) returns an "Infinity" value.

Its probably because the OS (Windows) "moves" the mouse cursor to where a touch happens. Its true also when you are still pressing down the mouse button, and touch the screen somewhere else.

So, when the 2nd real touch is recognized, the first touch (the mousedown) position is reported in the same place than the 2nd touch.

And if you try to calculate the distance between these 2 points you get a 0, hence returning a "Infinity" if you use it as divisor.

ZoomGesture.onTouchMove: around #117

   if (lockAspectRatio)
            {
                _scaleX *= currTransformVector.length / _transformVector.length; // <-- HERE
                _scaleY = _scaleX;
            }
 // (...)
fljot commented 9 years ago

@rdoi yeah, I understood you. But as we didn't have any real information about how OS delivers input information to the Flash runtime, I added logging. With it we can see exactly what is the input (events, ids and positions). No point to speculate, just try it =)