【问题标题】:How to find orientation of a real-world surface in ARKit如何在 ARKit 中找到真实世界表面的方向
【发布时间】:2018-03-09 13:15:26
【问题描述】:

一旦我有了ARHitTestResult,我该如何查找有关其方向的信息。例如,一旦我使用 hit-test 找到一堵墙,我怎么知道它的方向?

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

【问题讨论】:

    标签: ios swift arkit


    【解决方案1】:

    一旦您拥有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)
    
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-03
      • 2017-12-28
      • 2018-01-29
      • 2020-11-07
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多