使用ARKit与地面保持距离

时间:2017-07-01 03:56:08

标签: ios swift augmented-reality arkit

我已经开始尝试使用ARKit了,我遇到了一个问题。我找不到一个教程,展示如何将对象放在最近的表面上。

假设我使用的是包含扁平对象的.scn文件。我知道如何把它放在相机的位置,但我怎样才能到达最近的表面。

Such as in this image, where it detects how far away the table is.

很抱歉,如果这听起来像是代码请求,但我不知道从哪里开始,我们将非常感谢任何指导

1 个答案:

答案 0 :(得分:14)

您可以使用可能返回包含距离和变换等信息的结果的hitTesthttps://developer.apple.com/documentation/arkit/arhittestresult

for result in sceneView.hitTest(CGPoint(x: 0.5, y: 0.5), types: [.existingPlaneUsingExtent, .featurePoint]) {
  print(result.distance, result.worldTransform)
}