Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Working out the four points of a sublayerTransform




On Mar 18, 2008, at 2:41 PM, Neil Clayton wrote:
I thought that the points in the layer would all have a z of 0 since it's 2d, but that then the perspective transform would give them "depth" based on m34 and the rotation of the sublayer, which would then have to be mapped to an x,y point in 2d space.

yes, that's correct. We compute a single matrix to map 2D points from the child layer into the parent. The points in the parent are 3D, but then have their Z component set to zero to project them into the parent's plane.


The matrix is computed something like this:

m = translate (-ax, -ay, 0) * transform
* translate (position.x, position.y, zPosition) * sublayerTransform' */


where ax and ay are the anchor position of the child:

	ax = bounds.size.origin.x + bounds.size.width * anchorPoint.x
	ay = bounds.size.origin.y + bounds.size.height * anchorPoint.y

and sublayerTransform' is the parent's sublayerTransform property adjusted for its anchor position:

sublayerTransform' = translate (-ax, -ay, 0) * sublayerTransform * translate (ax, ay, 0)

where ax and ay are similar to above, except for the parent layer.


BTW: The way I'm applying this at present is to combine the matrices of all layers like so:


l1.transform * l1.sublayerTransform * l2.transform * l2.sublayerTransform * l3.transform

And then for each of the 4 original points of l3 (centered around the middle of the rect) applying the transform.

You can't concatenate the matrices like that. Since each layer is effectively a plane in 3D space, you need to project the point into that plane every time. All that means is that you have to apply the mapping from each child to its parent layer separately, setting the Z component of the result to zero before mapping that 2D point into the next superlayer.


	John


_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartz-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden
References: 
 >Working out the four points of a sublayerTransform (From: Neil Clayton <email@hidden>)
 >Re: Working out the four points of a sublayerTransform (From: John Harper <email@hidden>)
 >Re: Working out the four points of a sublayerTransform (From: Neil Clayton <email@hidden>)
 >Re: Working out the four points of a sublayerTransform (From: John Harper <email@hidden>)
 >Re: Working out the four points of a sublayerTransform (From: Neil Clayton <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.