ARKit:再现Project Point功能

ARKit: Reproducing the Project Point function

我正在尝试重现 ARCamera 的项目点功能,但由于某些原因,这些值没有正确匹配。我正在使用 ARCamera 的投影矩阵和视图矩阵并应用基本的 CG 透视变换数学 (PV) * p,但 NDC 值与 ARCamera 的投影点函数给出的像素值不匹配。有任何想法吗?我忘记了什么吗?

更多细节:

基本上,我尝试通过单击按钮获取 ARFrame,然后尝试复制 https://developer.apple.com/documentation/arkit/arcamera/2923538-projectpoint. I'm attempting to do this with https://developer.apple.com/documentation/arkit/arcamera/2887458-projectionmatrix and https://developer.apple.com/documentation/arkit/arcamera/2921672-viewmatrix 的功能,确保两个部分的所有输入都匹配。 CG尺寸用于将坐标从NDCspace转换为图像space.

编辑:找到解决方案,查看下面的评论。

原来是projection_matrix sometimes does not correctly find the device orientation. The correct approach is to use projectionMatrix(for:viewportSize:zNear:zFar:)的问题。