scihant / CTPanoramaView

A library that displays spherical or cylindrical panoramas with touch or motion based controls.
MIT License
1.04k stars 89 forks source link

startAngle not working when controlMethod = motion #36

Open ali991 opened 5 years ago

ali991 commented 5 years ago

when setting controlMethod = motion , despite any value we put on our startAngle, our camera node keeps the same angle,

ali991 commented 5 years ago

If controlMethod = touch everything is correct

nayooti commented 3 years ago

related to #31

PeHk commented 3 years ago

Do we have any updates on this case? I need it too, I am not sure how to implement such a case ..

nayooti commented 3 years ago

Do we have any updates on this case? I need it too, I am not sure how to implement such a case ..

Here is what I did a while ago:

class PanoramaController: UIViewController {

       lazy var loctionManager: CLLocationManager = {
        let locationManager = CLLocationManager()
        locationManager.delegate = self
        return locationManager
    }()

    private lazy var panoramaView: CTPanoramaView = {
        let view = CTPanoramaView()
        view.compass = compassView // create CTPieSlideView somewhere in this ViewController if needed
        return view
    }()

    var northAngle: Float? {
        didSet {
            if let newValue = northAngle, oldValue == nil {
                // this will only set once
               //  print("set start angle to: \(newValue)")
                panoramaView.startAngle = newValue // -.pi / 2
                panoramaView.controlMethod = .motion
            }
        }
    }
}

/* 
use location manager delegate to find and set north and calibrate panorama view 
*/

extension PanoramaController: CLLocationManagerDelegate {
    func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {

        // calculate + reset north
        let heading = newHeading.magneticHeading
        let normalisedHeading = Double((Int(heading) - 270 + 360) % 360)
        let radian = normalisedHeading * .pi / 180
        let radianPi = radian / .pi
        // center image (image is centered at -0.5 * pi)
        let imageCenter = 3.5 * .pi
        let centeredRadian = imageCenter - radian
        self.northAngle = Float(centeredRadian)  // Float(imageOffset)
        manager.stopUpdatingHeading()
    }
}

Hope I could help.

PeHk commented 3 years ago
lazy var loctionManager: CLLocationManager = {
        let locationManager = CLLocationManager()
        locationManager.delegate = self
        return locationManager
    }()

I've added your code to my app, I am able to get the print out of the new value (I must added a locationManager.startUpdatingHeading() in viewDidLoad()), but there is no change on the panorama view at all. Can you please check if you are not using the old version of the Pod? Basically, in the CTPanoramaView class, there is no such option to set offset to spherical panorama, it really does nothing at all. Even I've tried to rewrite the code, there is SCNVector4 and I am not really sure how to tell this vector to move a bit... It always mess up all the panorama stuff.

nayooti commented 3 years ago

I don't have much time. If I recall correctly I took the CTPanoramaView from a PR that has been closed without being merged. In my scenario I needed motion and touch support at the same time. I think it is the PR mentioned here: #46.

PeHk commented 3 years ago

I don't have much time. If I recall correctly I took the CTPanoramaView from a PR that has been closed without being merged. In my scenario I needed motion and touch support at the same time. I think it is the PR mentioned here: #46.

Great, I was able to get both motion and touch support from the PR, but still, for spherical panorama, there is no chance of getting the offset based on device heading :(

PeHk commented 3 years ago

@nayooti sorry for bothering you again. Can you share the code from the CTPanoramaView as well? I think I've just missing some little stuff to be able to make it work. I am not sure how to add a offset to the X axis only... It will be very very helpful and kind. Thanks!

nayooti commented 3 years ago

@nayooti sorry for bothering you again. Can you share the code from the CTPanoramaView as well? I think I've just missing some little stuff to be able to make it work. I am not sure how to add a offset to the X axis only... It will be very very helpful and kind. Thanks!

You should have find an invitation for a project that includes sample code.

PeHk commented 3 years ago

@nayooti sorry for bothering you again. Can you share the code from the CTPanoramaView as well? I think I've just missing some little stuff to be able to make it work. I am not sure how to add a offset to the X axis only... It will be very very helpful and kind. Thanks!

You should have find an invitation for a project that includes sample code.

Yes thank you!!