fljot / Gestouch

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

freerotation behaviour #105

Closed bluelemonade closed 6 years ago

bluelemonade commented 6 years ago

hi pavel,

I have used your lib a few time, works great. in the past I used the gesture seperated, panning rotation, zoom. Now I have to freerotate elements.

when the user rotates an sprite and chages the distance between the fingers the scaling works while rotating. when the user rotates a bigger angle the sprite moves away from the touchpoints.

is there a simple trick to prevent this? or should I only scale when the rotation is smaller then a defined value?

regards.

const gesture:TransformGesture = event.target as TransformGesture;

            // trace (gesture.location);
            // trace (gesture.touchesCount);

            var matrix:Matrix = event.target.target.transform.matrix;

            var _x:Number = event.target.target.x;
            var _y:Number = event.target.target.y;

            // Panning
            if (doPanning != false){
                matrix.translate(gesture.offsetX, gesture.offsetY);
                event.target.target.transform.matrix = matrix;
            }

            if (gesture.scale != 1 || gesture.rotation != 0) {

                // Scale and rotation.
                var transformPoint:Point = matrix.transformPoint(event.target.target.globalToLocal(gesture.location));
                matrix.translate(-transformPoint.x, -transformPoint.y);
                matrix.rotate(gesture.rotation);

                // lastGestureRotate = gesture.rotation
                // lastGestureScale = gesture.scale;
                if ( doScaling == true ) matrix.scale(gesture.scale, gesture.scale);

                matrix.translate(transformPoint.x, transformPoint.y);
                event.target.target.transform.matrix = matrix;

                // nicht zu klein machen
                if (event.target.target.scaleX < 0.7) {
                    event.target.target.scaleX = 0.7;
                    event.target.target.scaleY = 0.7;
                    event.target.target.x = _x;
                    event.target.target.y = _y;
                } else if (event.target.target.scaleX > 1.1) {
                    event.target.target.scaleX = 1.1;
                    event.target.target.scaleY = 1.1;
                    event.target.target.x = _x;
                    event.target.target.y = _y;
                }
fljot commented 6 years ago

@bluelemonade I don't understand your problem :/ if you still need help, I could try to assist in voice via Telegram or Skype or Google Hangouts.

bluelemonade commented 6 years ago

hello,

you can find a capture of the issue: http://intern.bluelemon.de:8080/share.cgi?ssid=0lYDjOt ( NAS active between 8.00 and 21.00 MET)

you can see the comibation of scaling an rotating. when I change the rotation an change at the same time the scaling smaller then my minimal scaling, the sprite wanders out of the touch points. how can I avoid this.

regards

fljot commented 6 years ago

@bluelemonade well do not transform your object via those scaleX scaleY x and y convenience setters! If you do it this it transforms object relative to it's origin.

I think you should drop all code after // nicht zu klein machen and instead limit the scaling at matrix.scale() call. You don't want to apply too much up/down scale here. Perhaps something like

const pic = event.target.target as DisplayObject;
...
matrix.translate(-transformPoint.x, -transformPoint.y);
matrix.rotate(gesture.rotation);

if (doScaling) {
  const currPicScale = pic.scaleX;
  const minScaleToApply = 0.7 / currPicScale;
  const maxScaleToApply = 1.1 / currPicScale;
  const scaleToApply = Math.max(minScaleToApply, Math.min(gesture.scale, maxScaleToApply));
  matrix.scale(scaleToApply, scaleToApply);
}

matrix.translate(transformPoint.x, transformPoint.y);
pic.transform.matrix = matrix;
bluelemonade commented 6 years ago

oh, thank you, indeed its stupid to scale the object. thanks