CTPanoramaView
CTPanoramaView copied to clipboard
Add pitch to report movement
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.
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.
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?