CATransform3D row/column order
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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
.Your initial interpretation was correct;
CATransform3D
does define the matrix below:And yes, although it may be confusing (if you are used to pre-multiplying transform matrices), this yields the translation matrix:
See Figure 1-8 in the "Core Animation Programming Guide".
This is a valid transformation matrix if you post-multiply your transform matrices, which is what Apple does in Core Animation (see Figure 1-7 in the same guide, although beware the equation is missing transpose operations).