我可以观察SCNView的相机变换吗?

时间:2018-03-31 16:41:54

标签: ios scenekit

我有一个SCNView,启用了allowsCameraControl属性。我想在相机改变时观察相机方向(通过用户手势),我该怎么做?

1 个答案:

答案 0 :(得分:1)

allowsCameraControl设置为true时,SceneKit会将相机添加为rootNode的子级。

因此,要从相机访问信息,您可以在以下delegate回调中执行以下操作:

 func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {

    //1. Get The Camera From The ARSCNScene
    if let currentPointOfView = augmentedRealityView?.pointOfView{

        let pitch = currentPointOfView.eulerAngles.x
        let yaw =   currentPointOfView.eulerAngles.y
        let roll =  currentPointOfView.eulerAngles.z

        print("""
            Pitch = \(degreesFrom(pitch))
            Yaw = \(degreesFrom(yaw))
            Roll = \(degreesFrom(roll))
            """)

    }
}

/// Convert Radians To Degrees
///
/// - Parameter radian: Float
/// - Returns: Float
func degreesFrom( _ radian: Float) -> Float{

   return radian * Float(180.0 / Double.pi)

}

其中Pitch,Yaw&滚动参考以下内容: enter image description here

希望这能让你开始......