2017-12-18 219 views
0

比方說,我在屏幕中間畫了一個圓圈,將它用作目標。如果我將這個圓圈指向節點,那麼ARKit如何檢測它?只用攝像頭檢測SCNNode

現在我使用的是自來水方法

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

它的作品真的很好,但它會好得多隻是指向它的攝像頭檢測到一個節點。

回答

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

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

使用位置則hitTest

+0

好了,所以我只需要每次觸發則hitTest攝像機移動。任何想法它可能是什麼事件? – Mencls

+0

func渲染器(_渲染器:SCNSceneRenderer,updateAtTime時間:TimeInterval)。它被稱爲每一幀。 –

+0

工程很好,代碼非常簡單。謝啦。 – Mencls