title: Why does a CALayer's transform3D's m34 need to be modified before applying the rotate transform?
body: <p>The following code can make a <strong><em>perspective</em></strong> rotation transform for a layer:</p>
  
  <pre><code>CATransform3D transform3DFoo = CATransform3DIdentity;
  
  transform3DFoo.m34 = -1.0 / 1000;
  
  transform3DFoo = CATransform3DRotate(transform3DFoo, M_PI / 4, 1, 0, 0);
  </code></pre>
  
  <p>However, if the two lines are reversed:</p>
  
  <pre><code>CATransform3D transform3DFoo = CATransform3DIdentity;
  
  transform3DFoo = CATransform3DRotate(transform3DFoo, M_PI / 4, 1, 0, 0);
  
  transform3DFoo.m34 = -1.0 / 1000;
  </code></pre>
  
  <p>then the perspective is gone.  Now it is orthographic (no perspective).  Does someone who is familiar with perspective know why the reason?</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>// First Identity and then transform3DFoo.m34 = -1.0 / 1000; is done
  
  1.00000     0.00000     0.00000     0.00000 
  0.00000     1.00000     0.00000     0.00000 
  0.00000     0.00000     1.00000    -0.00100 
  0.00000     0.00000     0.00000     1.00000 
  
  // and then CATransform3DRotate(transform3DFoo, M_PI / 4, 1, 0, 0);
  
  1.00000     0.00000     0.00000     0.00000 
  0.00000     0.70711     0.70711    -0.00071 
  0.00000    -0.70711     0.70711    -0.00071 
  0.00000     0.00000     0.00000     1.00000 
  
  // Now start with Identity and only the Rotate statement is done:
  
  1.00000     0.00000     0.00000     0.00000 
  0.00000     0.70711     0.70711     0.00000 
  0.00000    -0.70711     0.70711     0.00000 
  0.00000     0.00000     0.00000     1.00000 
  
  // and then transform3DFoo.m34 = -1.0 / 1000; is done
  
  1.00000     0.00000     0.00000     0.00000 
  0.00000     0.70711     0.70711     0.00000 
  0.00000    -0.70711     0.70711    -0.00100 
  0.00000     0.00000     0.00000     1.00000 
  </code></pre>
  
  <p>(the tag of "OpenGL" is added because it probably is the same principle in OpenGL)</p>