我有一个SCNView
,启用了allowsCameraControl
属性。我想在相机改变时观察相机方向(通过用户手势),我该怎么做?
答案 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)
}
希望这能让你开始......