title: GLKit vs. Metal perspective matrix difference
body: <p>I'm reading a Metal <a href="https://www.raywenderlich.com/137398/ios-metal-tutorial-swift-part-5-switching-metalkit" rel="nofollow noreferrer">tutorial</a> on raywenderlich.com, where it introduces a pure Swift float4x4 <a href="https://koenig-media.raywenderlich.com/uploads/2016/09/Metal_5_swift3_resources.zip" rel="nofollow noreferrer">helper class</a>. 99% it's just wrapper around GLKit functions, except one function which really puzzles me:</p>
  
  <pre><code>  static func makePerspectiveViewAngle(_ fovyRadians: Float, aspectRatio: Float, nearZ: Float, farZ: Float) -&gt; float4x4 {
      var q = unsafeBitCast(GLKMatrix4MakePerspective(fovyRadians, aspectRatio, nearZ, farZ), to: float4x4.self)
      let zs = farZ / (nearZ - farZ)
      q[2][2] = zs
      q[3][2] = zs * nearZ
      return q
    }
  </code></pre>
  
  <p>Why does it need to change <code>q[2][2]</code> and <code>q[3][2]</code>. Is this some incompatibility between Metal's and GLKit's coordinate system?</p>
  
  <p>Is this a particular choice this tutorial made? If not, are there any other incompatibilities between GLKit and Metal mathematics?</p>
  
  <hr>
  
  <p><strong>Update</strong>: I found a nice illustration about Metal's clip space coordinate system from the WWDC 2016 Session: Adopting Metal I.</p>
  
  <p><a href="https://i.stack.imgur.com/RsPOX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RsPOX.jpg" alt="clip-space"></a></p>