我同意@Rickster的观点
Apple Code
提供了一个更可靠的示例,但是,我有这个示例,它似乎工作顺利(当您使用PlaneDetection时,情况更为严重(因为特征点更为零散):
我没有利用
touchesBegan
但只需在
touchesMoved
而是:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
//1. Get The Current Touch Point
guard let currentTouchPoint = touches.first?.location(in: self.augmentedRealityView),
//2. Get The Next Feature Point Etc
let hitTest = augmentedRealityView.hitTest(currentTouchPoint, types: .existingPlane).first else { return }
//3. Convert To World Coordinates
let worldTransform = hitTest.worldTransform
//4. Set The New Position
let newPosition = SCNVector3(worldTransform.columns.3.x, worldTransform.columns.3.y, worldTransform.columns.3.z)
//5. Apply To The Node
nodeToDrag.simdPosition = float3(newPosition.x, newPosition.y, newPosition.z)
}
我可能完全走错了路(如果是这样的话,我很想得到反馈)。
不管怎样,我希望这可能会有帮助。。。您可以在此处看到它的快速视频:
Dragging SCNNode