[osg-users] How to get Camera Heading Pitch Roll
Julien Valentin
julienvalentin51 at gmail.com
Sun May 22 13:37:07 PDT 2016
Why getHPRfromQuat(osg::Quat (cam->getProjectionMatrix())) wouldn't work?
karcios wrote:
> Hi,
>
> How to get Heading, Pitch Roll angles when camera is set by setViewMatrixAsLookAt?
>
> I've got two camera modes:
> 1) Camera is set by global position and HPR
>
> Code:
> osg::Matrix worldMatrix;
> ellipsoid->computeLocalToWorldTransformFromLatLongHeight(longitude, latitude, height, worldMatrix);
>
> osg::Vec3 yawAxis( 0.f, 0.f, 1.f );
> osg::Vec3 pitchAxis( 1.f, 0.f, 0.f );
> osg::Vec3 rollAxis( 0.f, 1.f, 0.f );
>
> //roll,pitch, yaw
> osg::Matrix rotationMat = osg::Matrix::rotate(roll, rollAxis)// Roll
> * osg::Matrix::rotate(pitch, pitchAxis)// Pitch
> * osg::Matrix::rotate( yaw, yawAxis);// Yaw
>
> camera>setViewMatrix(osg::Matrix::inverse(rotationMat * worldMatrix));
>
>
>
>
> 2) Camera is set by global eyepos, globalcenter and up vector
>
> Code:
> ECEFpnt (position in global) is calcualted from lot, lan, alt
> osg::Vec3f upVec = ellipsoid->computeLocalUpVector(ECEFpnt.x(), ECEFpnt.y(), ECEFpnt.z());
>
> camera->setViewMatrixAsLookAt(ECEFpnt, groundPosECEF, upVec);
>
> osg::Matrix camMat = camera->getViewMatrix();
>
> osg::Vec3d trans;
> osg::Quat camQuat;
> osg::Vec3d scale;
> osg::Quat so;
>
> camMat.decompose(trans, camQuat, scale, so);
> and
> camQuat... ???
>
>
>
>
> How to get camera Heading Pitch Roll in this case?!?!?
>
> From rotation Quat -> HPR I will later use
>
> Code:
> osg::Vec3d getHPRfromQuat(osg::Quat quat)
> {
> double qx = quat.x();
> double qy = quat.y();
> double qz = quat.z();
> double qw = quat.w();
>
> double sqx = qx * qx;
> double sqy = qy * qy;
> double sqz = qz * qz;
> double sqw = qw * qw;
>
> double term1 = 2*(qx*qy+qw*qz);
> double term2 = sqw+sqx-sqy-sqz;
> double term3 = -2*(qx*qz-qw*qy);
> double term4 = 2*(qw*qx+qy*qz);
> double term5 = sqw - sqx - sqy + sqz;
>
> double heading = atan2(term1, term2);
> double pitch = atan2(term4, term5);
> double roll = asin(term3);
>
> return osg::Vec3d( heading, pitch, roll );
> }
>
>
> but first I need to do something with this Quat...
>
> Any Help? :)
>
> Thank you!
>
> Cheers,
> Wojtek
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67190#67190
More information about the osg-users
mailing list