【问题标题】:How to prevent SceneKit changing Camera FOV / Position on device rotation?如何防止 SceneKit 在设备旋转时更改相机 FOV / 位置?
【发布时间】:2019-10-30 04:14:29
【问题描述】:

没有处理旋转或改变任何东西的代码,当我的设备从纵向旋转到横向时,加载并居中于 SceneKit 视图中的模型会改变透视、缩放和拉伸。

ViewController 有一个 SceneKit 视图,它固定在父视图的顶部、底部和侧面。经证实,即使在旋转时也能坚持。

所需设备为 iPhone SE 至 12.9 iPad Pro。

在 iPad 上,这种视觉问题大大减少,但在 iPhone 上,扭曲、缩放和透视变化非常明显。

我不知道如何嵌入照片,否则我会向您展示,但如果模型在纵向 iPhone 上是正面和中心且 1 英寸 x 1 英寸正方形,当您旋转到横向时,它会在 0.5 英寸处变为 0.25 英寸垂直水平的。

这是设置场景的代码。

        let scene = SCNScene()
        let shipScene = SCNScene(named: "merchant.scn")

        guard let shipNode = shipScene?.rootNode.childNode(withName: "merchant", recursively: true)
        else
        {
            fatalError("ShipModel is not found!")
        }

        self.shipNode = shipNode
        self.shipNode?.position = SCNVector3(x:0, y:0, z:0)
        scene.rootNode.addChildNode(self.shipNode!)

        let lightNode = SCNNode()
        lightNode.light = SCNLight()
        lightNode.light?.type = .omni
        lightNode.position = SCNVector3(x:0, y:2, z:10)

        let cameraNode = SCNNode()
        self.cameraNode = cameraNode
        self.cameraNode?.camera = SCNCamera()
        self.cameraNode?.position = SCNVector3(x:0, y:0, z:8)
        self.cameraNode?.addChildNode(lightNode)

        scene.rootNode.addChildNode(self.cameraNode!)
        self.sceneKitView?.scene = scene
        self.sceneKitView?.showsStatistics = false
        self.sceneKitView?.backgroundColor = #colorLiteral(red: 0.08822073042, green: 0.08822073042, blue: 0.08822073042, alpha: 1)
        self.sceneKitView?.allowsCameraControl = false

课堂上没有发生任何其他事情,但拉伸、缩小和透视变化发生在设备旋转时。

它们在 iPhone 上更差,但在 iPad 上大大降低。

【问题讨论】:

    标签: camera rotation scenekit fieldofview


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-30
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2015-10-31
      相关资源
      最近更新 更多