Detect SCNNode with camera only

时间:2017-12-18 05:30:10

标签: swift scenekit augmented-reality arkit

Let's say I draw a circle in the middle of my screen, to use it as a target. If I point this circle to a node, how is it possible for ARKit to detect it?

For now I'm using the tap method

 @IBAction func tapHandler(_ sender: UITapGestureRecognizer) {
    let viewTouchLocation:CGPoint = sender.location(in: sceneView)
    guard let result = sceneView.hitTest(viewTouchLocation, options: nil).first else {
        return
    }
    // ...etc
}

which works really well, but it would be so much better to detect a node just by pointing the camera at it.

1 个答案:

答案 0 :(得分:4)

let screenRect = UIScreen.main.bounds
let screenWidth = screenRect.size.width
let screenHeight = screenRect.size.height

let location = CGPoint(x:screenWidth/2,y:screenHeight/2)

use location in hittest