Re: Group CGAffineTransform Animations?
Re: Group CGAffineTransform Animations?
- Subject: Re: Group CGAffineTransform Animations?
- From: WT <email@hidden>
- Date: Wed, 17 Jun 2009 23:11:37 +0200
On Jun 17, 2009, at 10:40 PM, Erik Buck wrote:
Only a little bit of math is neccessary to use affine transforms. A
lot of math is needed for general 3D programming, but let's ignore
that for now.
My third grader was tought about associative and communitive math
operstions. Some matrix operations are associative and some are
communitive. That's why the order of operations matters.
To scale and rotate a square without moving the center of the
square, do the following:
A) translate to the center of the square making that position the
new origin for scaling and rotation.
B) Scale the coordinate system.
C) Rotate the coordinate system
D) Translate back to the original origin
F) Draw the square
It's not so hard typed in web-mail:
CGAffineTransform
TransformToScaleAndRotateAboutCenterOfSquare(NSRect someSquare)
{
CGAffineTransform transform = CGAffineTransformMakeTranslation(
NSMidX(someSquare), NSMidY(someSquare));
transform = CGAffineTransformScale (transform, 2.0f, 2.0f);
transform = CGAffineTransformRotate(transform, DEGS_TO_RADS(90));
transform = CGAffineTransformTranslate(transform, -
NSMidX(someSquare), -NSMidY(someSquare));
return transform;
}
You're absolutely correct in general, but - if I'm not mistaken -
CGAffineTransform rotations and scalings already do their thing with
respect to the center of the view they're being applied to. In fact, I
tested that before writing my solution to the OP's problem. And that
is indeed the source of the problem. Rotations and scalings, as
implemented by CGAffineTransform, are with respect to the view's
center but translations are with respect to the view's origin.
Therefore, if you scale while you translate, the view's origin changes
and the translation is no longer being applied with the correct offset.
To be honest, I'm a bit surprised that CGAffineTransform rotations and
scalings are already defined with respect to the center of the view.
There's still a part of my brain that thinks that that isn't true, but
my tests indicated otherwise.
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden