360度照片滚动出视野,而不是从内部观看

时间:2019-04-08 22:02:02

标签: ios swift scenekit core-motion

panoramic view

我尝试创建一个360度全景照片查看器,但它会滚动到视线之外,并且可以从外部查看球体,而不是从内部查看球体。

我可以知道怎么了吗?这是完整的代码:

    guard  let imagePath = Bundle.main.path(forResource: "Hellbrunn25", ofType: "jpg") else {

        fatalError("Failed to find path for panoramic file.")
    }

    guard let image = UIImage(contentsOfFile: imagePath) else {

        fatalError("Failed to load panoramic image")
    }

    // Set the scene
    let scene = SCNScene()
    sceneView.scene = scene
    sceneView.showsStatistics = true
    sceneView.allowsCameraControl = true

    // Create node, containing a sphere, using the panoramic image as a texture
    let sphere = SCNSphere(radius: 20.0)
    sphere.firstMaterial!.isDoubleSided = true
    sphere.firstMaterial!.diffuse.contents = image

    let sphereNode = SCNNode(geometry: sphere)
    sphereNode.position = SCNVector3Make(0, 0, 0)
    scene.rootNode.addChildNode(sphereNode)

    // Camera
    cameraNode.camera = SCNCamera()
    cameraNode.position = SCNVector3Make(0, 0, 0)
    scene.rootNode.addChildNode(cameraNode)

    // Check that we will be able to monitor device motion
    guard motionManager.isDeviceMotionAvailable else {

        fatalError("Device motion is not available")
    }


    // Action
    motionManager.deviceMotionUpdateInterval = 1.0 / 60.0
    motionManager.startDeviceMotionUpdates(to: OperationQueue.main) {
        [weak self](deviceMotion, error) in

        guard let data = deviceMotion else {
            return
        }

        let attitude: CMAttitude = data.attitude
        self?.cameraNode.eulerAngles = SCNVector3Make(Float(attitude.roll - M_PI/2.0), Float(attitude.yaw), Float(attitude.pitch))
    }

0 个答案:

没有答案