Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freerotation behaviour #105

Closed
bluelemonade opened this issue Jul 18, 2018 · 4 comments
Closed

freerotation behaviour #105

bluelemonade opened this issue Jul 18, 2018 · 4 comments

Comments

@bluelemonade
Copy link

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
Copy link
Owner

fljot commented Jul 31, 2018

@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
Copy link
Author

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
Copy link
Owner

fljot commented Aug 6, 2018

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants