Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pitch to report movement #20

Open
fajdof opened this issue Mar 15, 2018 · 2 comments
Open

Add pitch to report movement #20

fajdof opened this issue Mar 15, 2018 · 2 comments

Comments

@fajdof
Copy link
Contributor

fajdof commented Mar 15, 2018

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.

@scihant
Copy link
Owner

scihant commented Mar 20, 2018

Hi @fajdof

Sorry for the late response.

I think that the definition of "useful" depends on the task at hand. Since you needed it, others might need it too. But if the method is gonna supply the heading and the pitch, maybe it would also make sense to supply the roll for completeness, which makes me think that maybe the method should simply report the motionData.attitude.quaternion so that users can compute whatever they need.

@fajdof
Copy link
Contributor Author

fajdof commented Mar 22, 2018

Hi @scihant,

Sounds good to me. Only, the report movement function is also called in handlePan function and there is no quaternion there so it should probably be optional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants