Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. view.addSubview(sceneView)
  4. view.addSubview(infoLabel)
  5. //1
  6. let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
  7. tapRecognizer.numberOfTapsRequired = 1
  8. sceneView.addGestureRecognizer(tapRecognizer)
  9. }
  10.  
  11. // MARK: Gesture handlers
  12. @objc func handleTap(sender: UITapGestureRecognizer) {
  13. //2
  14. let tapLocation = sender.location(in: sceneView)
  15. //3
  16. let hitTestResults = sceneView.hitTest(tapLocation, types: .featurePoint)
  17. if let result = hitTestResults.first {
  18. //4
  19. let position = SCNVector3.positionFrom(matrix: result.worldTransform)
  20. //5
  21. let sphere = SphereNode(position: position)
  22. //6
  23. sceneView.scene.rootNode.addChildNode(sphere)
  24. let lastNode = nodes.last
  25. nodes.append(sphere)
  26. if lastNode != nil {
  27. //7
  28. let distance = lastNode!.position.distance(to: sphere.position)
  29. infoLabel.text = String(format: "Distance: %.2f meters", distance)
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement