SCNCamera xFov,yFov由fieldOfView和focusLength替换

时间:2018-07-15 18:35:26

标签: swift scenekit augmented-reality fieldofview

我曾经将xFov的{​​{1}}和yFov的值设置为根据相机SCNCamera和视图field of view计算的值。在我的frame size引擎实现中(使用AR,而不是SceneKit),该方法运行良好。在新的Xcode中,我看到警告,ARKitxFov已过时,我应该改用yFovfieldOfView。我想更新我的代码,但我不知道如何设置这些变量以使其完全对应于我以前拥有的变量。最接近的是将focalLength设置为我以前用于xFov * 2的值-但它并不完全相同,对象实际上看起来要小一些。是否有某种方法可以计算这些新值,就像我将fieldOfView设置为给定值一样?我现在拥有的是xFov and yFov以前的这些值,因此我想从中计算出xFov and yFovfieldOfView

这就是我获得focalLengthxFov值的方式:

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

0 个答案:

没有答案