Row / Column Order CATransform3D

I have a bit of confusion regarding the row / column order of the matrix structure of CATransform3D. The structure defines such a matrix:

[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 the rows (so that [m11 m12 m13 m14] forms the first row), but when you create the translation matrix (tx, ty, tz), the matrix will look like this: 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 by a 4-element vector column will not translate a point.

I assume that the CATransform3D structure stores values โ€‹โ€‹in column order, so that the values โ€‹โ€‹of [m11 m12 m13 m14] form the first column (not the first row).

Can anyone confirm?

+4
source share
2 answers

Yes, CATransform3D is in the main order in the column, because that is what OpenGL (ES) wants. Core Animation uses GL in the background to render it. If you need proof, check the man page for glMultMatrix :

OPTIONS

m Indicates 16 consecutive values โ€‹โ€‹that are used as 4 x 4 column matrix elements. 16 consecutive values โ€‹โ€‹that are used as 4 x 4 column matrix elements.

It really should be clearer in the docs for CALayer .

+4
source

Your initial interpretation was correct; CATransform3D defines the matrix below:

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

And yes, although this can be misleading (if you are used to pre-multiplying the transformation matrices), this gives 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 Basic Animation Programming Guide .

This is a valid transformation matrix if you post-multiply your conversion matrices, which Apple does in Core Animation (see Figure 1-7 in the same manual, although be careful that there are no transpose operations in the equation).

+2
source

Source: https://habr.com/ru/post/1338676/


All Articles