I'm reading a Metal tutorial on raywenderlich.com, where it introduces a pure Swift float4x4 helper class. 99% it's just wrapper around GLKit functions, except one function which really puzzles me:
static func makePerspectiveViewAngle(_ fovyRadians: Float, aspectRatio: Float, nearZ: Float, farZ: Float) -> 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
}
Why does it need to change q[2][2]
and q[3][2]
. Is this some incompatibility between Metal's and GLKit's coordinate system?
Is this a particular choice this tutorial made? If not, are there any other incompatibilities between GLKit and Metal mathematics?
Update: I found a nice illustration about Metal's clip space coordinate system from the WWDC 2016 Session: Adopting Metal I.