Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func viewDidLoad() {
- super.viewDidLoad()
- view.addSubview(sceneView)
- view.addSubview(infoLabel)
- //1
- let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
- tapRecognizer.numberOfTapsRequired = 1
- sceneView.addGestureRecognizer(tapRecognizer)
- }
- // MARK: Gesture handlers
- @objc func handleTap(sender: UITapGestureRecognizer) {
- //2
- let tapLocation = sender.location(in: sceneView)
- //3
- let hitTestResults = sceneView.hitTest(tapLocation, types: .featurePoint)
- if let result = hitTestResults.first {
- //4
- let position = SCNVector3.positionFrom(matrix: result.worldTransform)
- //5
- let sphere = SphereNode(position: position)
- //6
- sceneView.scene.rootNode.addChildNode(sphere)
- let lastNode = nodes.last
- nodes.append(sphere)
- if lastNode != nil {
- //7
- let distance = lastNode!.position.distance(to: sphere.position)
- infoLabel.text = String(format: "Distance: %.2f meters", distance)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement