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



John,

I reckon I'm completely misunderstanding how perspective is applied.

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.

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.

Is this thinking correct? or have I missed the boat?

--
Regards,
Neil Clayton,  http://shinywhitebox.com







On 19/03/2008, at 10:09 AM, John Harper wrote:

CG points implicitly have a zero Z component, so the m34 component of the matrix has no effect. The full expansion to map a homogeneous 3D point 'p' to the point 'q' with the matrix applied is:

 q->x = p->x * t->m11 + p->y * t->m21 + p->z * t->m31 + p->w * t->m41;
 q->y = p->x * t->m12 + p->y * t->m22 + p->z * t->m32 + p->w * t->m42;
 q->z = p->x * t->m13 + p->y * t->m23 + p->z * t->m33 + p->w * t->m43;
 q->w = p->x * t->m14 + p->y * t->m24 + p->z * t->m34 + p->w * t->m44;

	John

On Mar 18, 2008, at 2:03 PM, Neil Clayton wrote:

Thanks John,

That's useful except that I do want to take into account the perspective as applied by the sublayerTransform of a superlayer (field m34 in the transform). Any idea where I might turn in order to learn about how to do this?

--
Regards,
Neil Clayton,  http://shinywhitebox.com


On 19/03/2008, at 4:17 AM, John Harper wrote:

Hi,

You can use a function like this to apply a CATransform3D to a CGPoint:

void
pointApplyTransform (CGPoint *p, const CATransform3D *t)
{
double px = p->x, py = p->y, w;
w  = px * t->m14 + py * t->m24 + t->m44;
p->x = (px * t->m11 + py * t->m21 + t->m41) / w;
p->y = (px * t->m12 + py * t->m22 + t->m42) / w;
}

the Z component of the transformed point is ignored, and the X and Y components are correctly divided by W (unless W is <= 0),

	John


On Mar 18, 2008, at 2:45 AM, Neil Clayton wrote:

Hello.

I'm wanting to draw a polygon around a layer. I want the polygon to be 1 pixel wide regardless of the transformations applied to the layer. As such a border/borderWidth solution won't work because it'll be scaled if the layer is scaled. So I've computed the scaled and rotated coordinates of said layer by walking up the layer tree and applying the affine transforms top-down to each of the four points making up the original rectangle of the layer. This gives me what I want - until I do rotation with sublayerTransforms.

In an ideal world I'd like to know if there is also a way to apply a CATransform3D to a point.

For example, in order to compute the translation, scale and rotation(z) of a given point from the original rectangle I need do only:

point = CGPointApplyAffineTransform(point, [layer affineTransform]);

However there doesn't seem to be an equivalent function for CATransform3D transforms.

Any suggestions? I've spent the entire day reading about perspective transformations and projections (lots of matrix math). I'm happy (as happy as someone that's not done this stuff for many years can be) to go down this path if it's absolutely required, but was wondering if anyone knew of a simpler way (rather than reinventing the wheel) of applying the same (or close enough - similar) math that CA/OpenGL is applying to the sublayerTransform a matrix.

To be clear, I'm talking specifically about computing the final value of a point in a layer given that I've set the m34 field of the sublayerTransform in order to achieve a perspective effect (ala: CovertFlow).

--
Regards,
Neil Clayton,  http://shinywhitebox.com







_______________________________________________
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




_______________________________________________ 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>)



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.