gpt4 book ai didi

swift - 如何在 ARkit 中获取场景的真实中心坐标

转载 作者:行者123 更新时间:2023-11-30 10:54:22 25 4
gpt4 key购买 nike

在ARKit中,如果我有一个ARSCNView,如何获取当前场景的真实中心坐标?我使用 Swift 作为编程语言。

最佳答案

您可以通过使用这样的手势来获取触摸点

// 1.
@objc func tapped(recognizer :UIGestureRecognizer) {
// Get exact position where touch happened on screen of iPhone (2D coordinate)
let touchPosition = recognizer.location(in: sceneView)

// 2.
// Conduct a hit test based on a feature point that ARKit detected to find out what 3D point this 2D coordinate relates to
let hitTestResult = sceneView.hitTest(touchPosition, types: .featurePoint)

// 3.
if !hitTestResult.isEmpty {
guard let hitResult = hitTestResult.first else {
return
}
print(hitResult.worldTransform.columns.3)
}
}

你可以获得点位置

让positionOfObjectToAdd=SCNVector3(hitResult.worldTransform.columns.3.x,hitResult.wor

ldTransform.columns.3.y、hitResult.worldTransform.columns.3.z)

关于swift - 如何在 ARkit 中获取场景的真实中心坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54122614/

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