views:

558

answers:

2

I've seen in some document from apple that the matrix behind a CALayer's transform property has fields like m14, m21, m22 and so on. I also remember that I saw a table that explains those fields, about one or two months ago. I had a hard time trying to find it. Anybody knows a source?

+1  A: 

UIView perspective transform

Straight from the docs:

Transform

Defines the standard transform matrix used throughout Core Animation.

struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGFloat m31, m32, m33, m34; CGFloat m41, m42, m43, m44; }; typedef struct CATransform3D CATransform3D;

Fields

m11

The entry at position 1,1 in the matrix. m12

The entry at position 1,2 in the matrix. m13

The entry at position 1,3 in the matrix. m14

The entry at position 1,4 in the matrix. m21

The entry at position 2,1 in the matrix. m22

The entry at position 2,2 in the matrix. m23

The entry at position 2,3 in the matrix. m24

The entry at position 2,4 in the matrix. m31

The entry at position 3,1 in the matrix. m32

The entry at position 3,2 in the matrix. m33

The entry at position 3,3 in the matrix. m34

The entry at position 3,4 in the matrix. m41

The entry at position 4,1 in the matrix. m42

The entry at position 4,2 in the matrix. m43

The entry at position 4,3 in the matrix. m44

The entry at position 4,4 in the matrix.

Discussion

The transform matrix is used to rotate, scale, translate, skew, and project the layer content. Functions are provided for creating, concatenating, and modifying CATransform3D data. Availability

* Available in Mac OS X v10.5 and later.

Declared In CATransform3D.h

slf
Yep, that's what I mean. But this is not really an explanation of the fields. I know one of all of them is the rotation.z, another is for y, and so on.
HelloMoon
@IRTFM, there are no specific fields for rotation, etc. It sounds like you may want to read up on the basics of how affine transformation matrices work, e.g. http://en.wikipedia.org/wiki/Transformation_matrix
Daniel Dickison
+4  A: 

That struct looks like this:

struct CATransform3D
{
    CGFloat m11, m12, m13, m14;
    CGFloat m21, m22, m23, m24;
    CGFloat m31, m32, m33, m34;
    CGFloat m41, m42, m43, m44;
};
typedef struct CATransform3D CATransform3D;

This is simply a standard 4x4 transform matrix used to transform 4-vectors. It can be used to represent any number of linear transforms. See this wikipedia article on this type of matrix. Most of those elements can't really be interpreted independantly, but some can. For example m14, m24, and m34 represent a translation in 3-space. So for example if you multiply a point by this matrix:

[ 1  0  0  1 ]
[ 0  1  0  2 ]
[ 0  0  1  3 ]
[ 0  0  0  1 ]

Then it will translate that point by 1 toward +X, 2 units toward +Y, and 3 toward +Z. Hopefully that's clear. Note that the point must be represented as a 4 vector with the 4th element being 1, so the point (0, 1, 2) would be represented by [ 0 1 2 1 ]. Another example is a scaling transform:

[ 2  0  0  0 ]
[ 0  2  0  0 ]
[ 0  0  2  0 ]
[ 0  0  0  1 ]

It will double all of the coordinates of your point, so (1, 2, 3) will become (2, 4, 6). Other transforms, like rotations and perspective projections are more difficult to recognize on sight.

Here is more info on transforms from Apple. A bunch of utility transforms are provided by Apple for generating these matrices, see this link. They don't actually discuss the math behind CATransform3DMakeRotation, but this link from OpenGl does.

Gabe