Re: Group CGAffineTransform Animations?
Re: Group CGAffineTransform Animations?
- Subject: Re: Group CGAffineTransform Animations?
- From: Chunk 1978 <email@hidden>
- Date: Wed, 17 Jun 2009 10:21:55 -0400
alright... so i've been "playing" with this for a while now, and it's
quite baffling... with grouping CAAffineTransform, i can't seem to
understand the matrix math, and therefore have no real control over
the transforming object, namely the translation point.
premiss: a red cube, 50 width x 50 height, located at {0,0}. i want
to scale the cute 2 times it's width and height, move it to the center
of the screen, and rotate it 90º
-=-=-=-
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
CGRect screen = [[UIScreen mainScreen] bounds];
CGPoint centerPoint = {CGRectGetMidX(screen), CGRectGetMidY(screen)};
CGAffineTransform transform = CGAffineTransformMakeScale(2, 2);
transform = CGAffineTransformTranslate(transform, centerPoint.x,
centerPoint.y);
transform = CGAffineTransformRotate(transform, kDegreesToRadian(90));
square.transform = transform;
[UIView commitAnimations];
-=-=-=-
so, because of this matrix multiplication (that is way over my head,
i'm not a math person), the above code moves the cube all the way the
the bottom right of the screen (but not to the very bottom right,
which confuses me). however, if i don't scale the cube, leaving it at
CGAffineTransformMakeScale(1, 1), the translation works and the cube
goes to the center of the screen (but of course not i have no
scale)...
if the above code moved the cube to the very bottom right, i would
just assume that the Translate is being multiplied by the Scale, and
go with that, but it's not that simple, and it's kinda making me
crazy... is there a formula i can use? or does multiplying
CGAffineTransform matrices generally warrant no control?
On Wed, Jun 17, 2009 at 6:45 AM, Chunk 1978<email@hidden> wrote:
> i see how you write looks cleaner, is easier to follow. but i now
> have first hand experience with the matrix multiplications with
> unexpected results as your code has different results than mine.
> CGAffineTransformTranslate lands in a different space. interesting :)
>
> On Wed, Jun 17, 2009 at 6:26 AM, Jean-Daniel
> Dupas<email@hidden> wrote:
>> Concatenation is just a matrix multiplication:
>>
>> http://developer.apple.com/documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html#//apple_ref/doc/uid/TP30001066-CH204-CJBECIAD
>>
>> So yes, you can do that.
>>
>> It's just a matter of taste, but I would write it like that instead:
>>
>> CGAffineTransform transform = CGAffineTransformMakeScale(1.5, 1.5);
>> transform = CGAffineTransformRotate(transform, 3.14);
>> transform = CGAffineTransformTranslate(transform, 100, 50);
>>
>> square.transform = transform;
>>
>>
>> Le 17 juin 09 à 11:37, Chunk 1978 a écrit :
>>
>>> CGAffineTransformConcat() only allow for 2 arguments. so in the case
>>> where i have 3 transforms, i had to concatenate the first 2 to make
>>> "Group1", and then concatenate that with the final transform:
>>>
>>> -=-=-=-
>>> //Animation Block
>>> [UIView beginAnimations:nil context:NULL];
>>> [UIView setAnimationDuration:.5];
>>> [UIView setAnimationDelegate:self];
>>> [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
>>>
>>> CGAffineTransform enlarge = CGAffineTransformMakeScale(1.5, 1.5);
>>> CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14);
>>>
>>> CGAffineTransform group1 = CGAffineTransformConcat(enlarge,
>>> rotate);
>>> CGAffineTransform move = CGAffineTransformMakeTranslation(100, 50);
>>>
>>> square.transform = CGAffineTransformConcat(group1, move);
>>>
>>> [UIView commitAnimations];
>>> -=-=-=-
>>>
>>> it seems to work find, but is this the most ideal way of doing this?
>>>
>>>
>>>
>>>
>>> On Wed, Jun 17, 2009 at 5:21 AM, Chunk 1978<email@hidden> wrote:
>>>>
>>>> thanks! :)
>>>>
>>>> On Wed, Jun 17, 2009 at 5:05 AM, Jean-Daniel
>>>> Dupas<email@hidden> wrote:
>>>>>
>>>>> Le 17 juin 09 à 10:53, Chunk 1978 a écrit :
>>>>>
>>>>>> is have this animation block with both Enlarge and Rotate, but only
>>>>>> one work properly (the last one listed). what is the proper way to
>>>>>> group the two transforms together:
>>>>>>
>>>>>> -=-=-=-
>>>>>> //Animation Block
>>>>>> [UIView beginAnimations:nil context:NULL];
>>>>>> [UIView setAnimationDuration:1.0];
>>>>>> [UIView setAnimationDelegate:self];
>>>>>> [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
>>>>>>
>>>>>> CGAffineTransform enlarge = CGAffineTransformMakeScale(1.5, 1.5);
>>>>>> CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14 /
>>>>>> 2);
>>>>>>
>>>>>> square.transform = enlarge;
>>>>>> square.transform = rotate;
>>>>>>
>>>>>> [UIView commitAnimations];
>>>>>> -=-=-=-
>>>>>
>>>>>
>>>>> You should concat your transformations, not make two.
>>>>>
>>>>> CGAffineTransform trans = CGAffineTransformMakeScale(1.5, 1.5);
>>>>> trans = CGAffineTransformRotate(trans, 3.14 / 2);
>>>>>
>>>>> or in your sample above:
>>>>> square.transform = CGAffineTransformConcat(enlarge, rotate);
>>>>>
>>>>>
>>>>
>>> _______________________________________________
>>>
>>> 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
>>>
>>
>>
>
_______________________________________________
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