admin管理员组文章数量:1122832
I’m new to ARKit and I’ve been stuck on this problem for days. I want to create an AR app like Ikea, where I can place an object in the environment and move it around. When I use the pan gesture recognizer to drag the object, it moves fine, but it always starts from its original position.
So, I thought I’d save the last position every time I move the object, but that didn’t work. Now, the object keeps moving back to its origin position and it sticks and flickers. I can’t move it anymore!
here is my code:
@objc private func handleMovement(_ gesture: UIPanGestureRecognizer, selectedNode: SCNNode) {
let touchLocation = gesture.location(in: sceneView)
let hitTestResults = sceneView.hitTest(touchLocation, types: .existingPlaneUsingExtent)
if let lastPosition, let planeHitResult = hitTestResults.first {
selectedNode.position = SCNVector3(
x: planeHitResult.worldTransform.columns.3.x,
y: planeHitResult.worldTransform.columns.3.y,
z: planeHitResult.worldTransform.columns.3.z)
let deltaX = selectedNode.position.x - lastPosition.x
let deltaY = selectedNode.position.y - lastPosition.y
let deltaZ = selectedNode.position.z - lastPosition.z
selectedNode.position.x += deltaX
selectedNode.position.y += deltaY
selectedNode.position.z += deltaZ
} else {
if let planeHitResult = hitTestResults.first {
selectedNode.position = SCNVector3(
x: planeHitResult.worldTransform.columns.3.x,
y: occlusionPlaneVerticalOffset,
z: planeHitResult.worldTransform.columns.3.z)
lastPosition = selectedNode.position
}
}
}
Could you please point out where I’m going wrong?
本文标签: swiftCan39t drag the SCNNode on the scene smoothlyStack Overflow
版权声明:本文标题:swift - Can't drag the SCNNode on the scene smoothly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736282937a1926804.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论