Last active
August 21, 2018 14:58
-
-
Save aclima93/cce1b50ad5f51111af019adbe1af91f8 to your computer and use it in GitHub Desktop.
ARKit & CoreLocation + POI + AR Interaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sceneLocationView: SceneLocationView! | |
var pois: [PointOfInterest]! | |
var locationAnnotationNode2POI: [LocationTextAnnotationNode: PointOfInterest]! | |
var selectedPOI: PointOfInterest? | |
func setupARScene() { | |
// create AR scene | |
sceneLocationView = SceneLocationView() | |
view.addSubview(sceneLocationView) | |
// add tap gesture recognizer to AR scene's view | |
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleARObjectTap(gestureRecognizer:))) | |
sceneLocationView.addGestureRecognizer(tapGestureRecognizer) | |
} | |
@objc | |
func handleARObjectTap(gestureRecognizer: UITapGestureRecognizer) { | |
guard gestureRecognizer.view != nil else { return } | |
if gestureRecognizer.state == .ended { | |
// Look for an object directly under the touch location | |
let location: CGPoint = gestureRecognizer.location(in: sceneLocationView) | |
let hits = sceneLocationView.hitTest(location, options: nil) | |
if !hits.isEmpty { | |
// select the first match | |
if let tappedNode = hits.first?.node.parent as? LocationTextAnnotationNode { | |
if let poi = locationAnnotationNode2POI?[tappedNode] { | |
self.selectedPOI = poi | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment