我一直在阅读大量关于如何通过在屏幕上拖动对象来移动对象的StackOverflow答案.有些人使用针对.featurePoints的命中测试,有些人使用手势翻译或只是跟踪对象的lastPosition.但老实说..没有人按照每个人的期望它的方式工作.
对.featurePoints进行测试只会使对象四处跳跃,因为拖动手指时不会总是碰到一个特征点.我不明白为什么每个人都在暗示这一点.
像这样的解决方案:使用SceneKit在ARKit中拖动SCNNode
但是物体并没有真正跟随你的手指,并且你走了几步或改变物体或相机的角度的那一刻......并尝试移动物体.. x,z都是倒置的......并且完全有意义要做到这一点.
我真的想要像Apple Demo一样移动对象,但我看看Apple的代码......并且非常奇怪且过于复杂我甚至无法理解.他们移动物体如此美化的技术甚至不像每个人在网上提出的那样接近. https://developer.apple.com/documentation/arkit/handling_3d_interaction_and_ui_controls_in_augmented_reality
必须有一个更简单的方法来做到这一点.
我正在玩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)
} …Run Code Online (Sandbox Code Playgroud)