【发布时间】:2018-01-11 08:01:41
【问题描述】:
我正在使用 XCode 9 上的 AR 入门应用程序,其中锚点是在点击的场景中创建的:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let sceneView = self.view as? ARSKView else {
return
}
// Create anchor using the camera’s current position
if let currentFrame = sceneView.session.currentFrame {
// Create a transform with a translation of 0.2 meters in front
// of the camera
var translation = matrix_identity_float4x4
translation.columns.3.z = -0.2
let transform = simd_mul(currentFrame.camera.transform, translation)
// Add a new anchor to the session
let anchor = ARAnchor(transform: transform)
sceneView.session.add(anchor: anchor)
}
}
无论我在哪里点击,这总是会导致在屏幕中间创建锚点,这是有道理的,因为我们正在获取当前的相机变换并仅对其应用 z 轴上的平移。
我希望将锚点放置在我用手指实际点击的位置。我可以使用touches.first?.location(in: sceneView) 获取水龙头的位置,即仅以点为单位距屏幕左上角的距离,但我不确定如何将这些 2D pt 坐标应用于以米为单位的锚点变换,也不知道哪个它们适用的轴。
【问题讨论】:
标签: ios sprite-kit transform arkit