I have a bit of confusion regarding the matrix row/column order of the CATransform3D struct. The struct defines a matrix like this:
[m11 m12 m13 m14]
[m21 m22 m23 m24]
[m31 m32 m33 m34]
[m41 m42 m43 m44]
At first, it would seem that the values define rows (so that [m11 m12 m13 m14] forms the first row), but when you create a translation matrix by (tx, ty, tz), the matrix will look like this:
[ 1 0 0 0]
[ 0 1 0 0]
[ 0 0 1 0]
[tx ty tz 1]
My confusion comes from the fact that this is not a valid translation matrix; multiplying it with a 4-elements column-vector will not translate the point.
My guess is that the CATransform3D struct stores the values in column-order, so that the values [m11 m12 m13 m14] form the first column (and not the first row).
Can anyone confirm?
Yes,
CATransform3D
is in column major order because that is how OpenGL(ES) wants it. Core Animation uses GL in the background for it's rendering. If you want proof, check out theman
page forglMultMatrix
:This really should be more clear in the docs for
CALayer
.