GLKit与金属透视矩阵的区别 [英] GLKit vs. Metal perspective matrix difference
问题描述
我正在阅读金属教程在raywenderlich.com上,其中引入了纯Swift Swift 4x4 助手类. 99%的内容只是GLKit函数的包装,除了一个确实令我困惑的函数:
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
}
为什么需要更改q[2][2]
和q[3][2]
.这是Metal和GLKit的坐标系之间的不兼容吗?
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?
这是本教程做出的特定选择吗?如果不是,那么GLKit和Metal数学之间是否还有其他不兼容之处?
Is this a particular choice this tutorial made? If not, are there any other incompatibilities between GLKit and Metal mathematics?
更新:我在WWDC 2016会议:采用Metal I中找到了有关Metal的剪辑空间坐标系的漂亮插图.
Update: I found a nice illustration about Metal's clip space coordinate system from the WWDC 2016 Session: Adopting Metal I.