gpt4 book ai didi

ios - 如何在 ARKit 中找到真实世界表面的方向

转载 作者:行者123 更新时间:2023-11-28 07:53:05 25 4
gpt4 key购买 nike

一旦我有了 ARHitTestResult,我该如何去寻找关于它的方向的信息。例如,一旦我使用 HitTest 找到一面墙,我如何知道它的方向?

worldTransform 矩阵似乎包含方向信息,但我找不到提取它的方法。

最佳答案

一旦你有了一个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)

}

关于ios - 如何在 ARKit 中找到真实世界表面的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49186201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com