Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That struct looks like this:</p> <pre><code>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; </code></pre> <p>This is simply a 4x4 transform matrix used to transform 4-vectors. It can be used to represent any number of linear transforms. See <a href="http://en.wikipedia.org/wiki/Transformation_matrix" rel="noreferrer">this</a> wikipedia article on this type of matrix. Most of those elements can't really be interpreted independantly, but some can. For example m41, m42, and m43 represent a translation in 3-space. So for example if you multiply a point by this matrix:</p> <pre><code>[ 1 0 0 0 ] [ 0 1 0 0 ] [ 0 0 1 0 ] [ 1 2 3 1 ] </code></pre> <p>Then it will translate that point by 1 toward +X, 2 units toward +Y, and 3 toward +Z. </p> <pre><code> [ 1 0 0 0 ] [ x y z 1 ] x [ 0 1 0 0 ] = [ x+1 y+2 z+3 1 ] [ 0 0 1 0 ] [ 1 2 3 1 ] </code></pre> <p>Note that the point must be represented as a 4 vector with the 4th element being 1. Also note that this vector is actually a matrix itself and the format of this matrix differs from the one described in the wikipedia article on transform matrices. This is because a point is usually represented by a single column, 4 row matrix, however, Apple represents them as 4 column, single row matrices. This means that any transform matrix you see in the wikipedia article needs to be transposed before using it on the iPhone for it to work correctly. </p> <p>Another example is a scaling transform:</p> <pre><code>[ 2 0 0 0 ] [ 0 2 0 0 ] [ 0 0 2 0 ] [ 0 0 0 1 ] </code></pre> <p>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.</p> <p>Here is more info on <a href="http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html" rel="noreferrer">transforms</a> from Apple. A bunch of utility transforms are provided by Apple for generating these matrices, see <a href="http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Reference/CoreAnimation_functions/Reference/reference.html" rel="noreferrer">this link</a>. They don't actually discuss the math behind CATransform3DMakeRotation, but <a href="http://www.fastgraph.com/makegames/3drotation/" rel="noreferrer">this link</a> does.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload