Mam prosty SCNNode w ARKit i próbuję przeciągnąć go wszędzie tam, gdzie przesunąłem palcem w telefonie. Oto mój kod.Przeciąganie SCNNode w ARKit przy użyciu SceneKit
@objc func pan(recognizer :UIGestureRecognizer) {
guard let currentFrame = self.sceneView.session.currentFrame else {
return
}
var translation = matrix_identity_float4x4
translation.columns.3.z = -1.5
let sceneView = recognizer.view as! ARSCNView
let touchLocation = recognizer.location(in: sceneView)
let hitTestResult = sceneView.hitTest(touchLocation, options: [:])
if !hitTestResult.isEmpty {
print("hit result")
guard let hitResult = hitTestResult.first else {
return
}
let node = hitResult.node
node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation)
}
}
Problem polega na tym, że przeciągnięcie jest bardzo powolne i nie jest płynne.
Spójrz na to pytanie: https: // stackoverflow .pl/questions/6672677/how-to-use-uipangesturerecognizer-to-move-object-iphone-ipad. Powinieneś poprawnie pracować ze stanami gestów pan. –
Czy to działa dla ciebie? – mergesort
Zastanawiam się, czy udało ci się wymyślić coś z John Doe. –