我曾经将xFov
的{{1}}和yFov
的值设置为根据相机SCNCamera
和视图field of view
计算的值。在我的frame size
引擎实现中(使用AR
,而不是SceneKit
),该方法运行良好。在新的Xcode中,我看到警告,ARKit
和xFov
已过时,我应该改用yFov
和fieldOfView
。我想更新我的代码,但我不知道如何设置这些变量以使其完全对应于我以前拥有的变量。最接近的是将focalLength
设置为我以前用于xFov * 2的值-但它并不完全相同,对象实际上看起来要小一些。是否有某种方法可以计算这些新值,就像我将fieldOfView
设置为给定值一样?我现在拥有的是xFov and yFov
以前的这些值,因此我想从中计算出xFov and yFov
和fieldOfView
。
这就是我获得focalLength
和xFov
值的方式:
yFov
在水平的iPhone 6s上,这给了我
private func updateSceneInformation() {
guard let captureDevice = captureDevice, captureDevice.hasMediaType(AVMediaType.video) else { return }
let xFov: Double, yFov: Double
let cameraFieldOfView = Double(captureDevice.activeFormat.videoFieldOfView)
let videoDimentions = CMVideoFormatDescriptionGetDimensions(captureDevice.activeFormat.formatDescription)
let aspect = Double(videoDimentions.width) / Double(videoDimentions.height)
let videoSize: CGSize
if UIApplication.shared.statusBarOrientation.isPortrait {
yFov = cameraFieldOfView
xFov = yFov / aspect
videoSize = CGSize(videoDimensions: videoDimentions).rotated90Degrees
}
else {
xFov = cameraFieldOfView
yFov = xFov / aspect
videoSize = CGSize(videoDimensions: videoDimentions)
}
let aspectSize = videoSize.aspectFill(fitToSize: bounds.size)
let originPoint = CGPoint(x: (bounds.width - aspectSize.width) / 2, y: (bounds.height - aspectSize.height) / 2)
let sceneFrame = CGRect(origin: originPoint, size: aspectSize)
let fieldOfView = FOV(horizontal: xFov, vertical: yFov)
let newSceneInformation = SceneInformation(fieldOfView: fieldOfView, frame: sceneFrame, interfaceOrientation: UIApplication.shared.statusBarOrientation)
if sceneInformation != newSceneInformation {
sceneInformation = newSceneInformation
}
}
SceneInformation(fieldOfView: (58.63214874267578, 32.98058366775513), frame: (0.0, -0.09375, 667.0, 375.1875), interfaceOrientation: .landscapeRight)
是Frame
的框架。
这就是我之前应用这些值的方式(按预期工作)
SCNView