Skip to content

Add pitch to report movement #20

@fajdof

Description

@fajdof

Hi @scihant ,

To find a specific position on an image, in addition to the rotation angle I also need the pitch of the phone. So I calculated the pitch using quaternions:

let quaternion = motionData.attitude.quaternion 
let pitch = CGFloat(atan2(2*(quaternion.x*quaternion.w + quaternion.y*quaternion.z), 1 - 2*pow(quaternion.x, 2) - 2*pow(quaternion.z, 2)))

And added a new parameter to report movement:

open func reportMovement(_ rotationAngle: CGFloat, _ fieldOfViewAngle: CGFloat, _ pitch: CGFloat, callHandler: Bool = true)

I have a custom class and delegate to report the movement to my view controller:

@objc public protocol CTPanoramaRotationDelegate {
    func updatedRotation(rotationAngle: CGFloat, fieldOfViewAngle: CGFloat, pitch: CGFloat)
}

class CTCustomPanoramaView: CTPanoramaView {
    
    var delegate: CTPanoramaRotationDelegate?
    
    override func reportMovement(_ rotationAngle: CGFloat, _ fieldOfViewAngle: CGFloat, _ pitch: CGFloat, callHandler: Bool = true) {
        compass?.updateUI(rotationAngle: rotationAngle, fieldOfViewAngle: fieldOfViewAngle)
        delegate?.updatedRotation(rotationAngle: rotationAngle, fieldOfViewAngle: fieldOfViewAngle, pitch: pitch)
        if callHandler {
            movementHandler?(rotationAngle, fieldOfViewAngle)
        }
    }
}

Do you think it's useful to integrate pitch into the report movement function in the library? Or maybe there is some better approach that I'm missing? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions