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