我有ARHitTestResult
后,如何查找有关其方向的信息。例如,一旦我使用命中测试找到墙,我怎么知道它的方向?
worldTransform
矩阵似乎包含方向信息,但我发现无法提取它。
答案 0 :(得分:0)
获得ARHitTestResult
后,您将获得matrix_float_4x4
。
通过访问第3列,您可以获得位置信息。
然后可以将其转换为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)
}