CATransform3D row/column order

发布于 2022-09-06 08:43:17 字数 878 浏览 18 评论 0

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眸 2022-09-13 08:43:17

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 the man page for glMultMatrix:

PARAMETERS

m Points to 16 consecutive values that are used as the elements of a 4 x 4 column-major matrix.16 consecutive values that are used as the elements of a 4 x 4 column-major matrix.

This really should be more clear in the docs for CALayer.

廻憶裏菂餘溫 2022-09-13 08:43:17

Your initial interpretation was correct; CATransform3D does define the matrix below:

[m11 m12 m13 m14]
[m21 m22 m23 m24]
[m31 m32 m33 m34]
[m41 m42 m43 m44]

And yes, although it may be confusing (if you are used to pre-multiplying transform matrices), this yields the translation matrix:

[ 1  0  0  0]
[ 0  1  0  0]
[ 0  0  1  0]
[tx ty tz  1]

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文