作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一旦我有了 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/
我是一名优秀的程序员,十分优秀!