一旦我有了一个ARHitTestResult,我该如何去寻找关于它的方向的信息。例如,一旦我使用命中测试来查找墙,我如何知道它的方向?
矩阵似乎包含了方向信息,但我找不到提取它的方法。

最佳答案

一旦你有一个ARHitTestResult你将得到一个matrix_float_4x4
通过访问第三列,您可以获得位置信息。
然后可以将其转换为SCNVector3以便您可以定位SCNNode等,例如:

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    guard let touchLocation = touches.first?.location(in: augmentedRealityView),
    let hitTestResult = augmentedRealityView?.hitTest(touchLocation, types: .featurePoint),
    let resultPosition = hitTestResult.first?.worldTransform
    else { return }

    let matrixColumn = resultPosition.columns.3
    let worldVector = SCNVector3(matrixColumn.x, matrixColumn.y, matrixColumn.z)

    print("""
             X = \(matrixColumn.x)
             Y = \(matrixColumn.y)
             Z = \(matrixColumn.z)
        """)

    let sphereNode = SCNNode()
    let sphereGeometry = SCNSphere(radius: 0.1)
    sphereGeometry.firstMaterial?.diffuse.contents = UIColor.cyan
    sphereNode.position = worldVector
    sphereNode.geometry = sphereGeometry
    augmentedRealityView?.scene.rootNode.addChildNode(sphereNode)

}

07-24 19:04