On 23/01/2013, at 5:41 PM, Graham Cox <graham....@bigpond.com> wrote:

> To create a transform that supposedly will transform from the superlayer TO 
> the layer, and I then invert it to go back the other way. It works in the 
> simple case, but a rotation transform upsets things. I've tried pretty much 
> every combination of ordering different things in constructing the transform 
> but this is the "best" result I get. Still wrong though. Funny, every time I 
> think I have transforms figured out something turns up to show me I don't.



Boiling down my problem to its bare essentials, why are these two bits of code 
not equivalent?


        CGPoint anch = layer.anchorPoint;
        CGRect  br = layer.bounds;
        CGPoint pos = layer.position;
        
        CGContextTranslateCTM( ctx, pos.x, pos.y );
        CGContextConcatCTM( ctx, layer.transform );
        CGContextTranslateCTM(ctx, -(br.origin.x + anch.x * br.size.width), 
-(br.origin.y + anch.y * br.size.height));

The above works correctly, but below, which I thought should do the same, does 
not, if the layer.transform property is not the identity matrix:


        CGPoint anch = layer.anchorPoint;
        CGRect  br = layer.bounds;
        CGPoint pos = layer.position;

        
        CGAffineTransform tfm = CGAffineTransformMakeTranslation( pos.x, pos.y 
);
        tfm = CGAffineTransformConcat( tfm, layer.transform );
        tfm = CGAffineTransformTranslate( tfm, -(br.origin.x + anch.x * 
br.size.width), -(br.origin.y + anch.y * br.size.height));
        
        CGContextConcatCTM( ctx, tfm );

In the second case I've tried every combination of ordering the different 
statements that build the transform, and the sign of the translations, but 
nothing I have tried makes the second code work identically to the first. I'm 
missing something obvious but I'm not grokking it. I need the second case to 
work because it is needed in other situations where I have no context - e.g. 
just performing transformation calculations between a layer and its superlayer.

Please someone help, this is driving me bats.

--Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to