360-градусная фотография прокручивается вне поля зрения вместо просмотра изнутри - PullRequest
0 голосов
/ 09 апреля 2019

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))
    }
...