jOan,

        Attached is a function i wrote to do this.  It may work for you. 
No guarantees.

Martins

On Thu, 24 Aug 2006, jOan wrote:

> Hello,
> 
> Is it possible to get the rotation on each axe (x,y,z) from a osg::Quat ?
> 
> 
osg::Vec3d getHPRfromQuat(osg::Quat quat){



        // From: http://guardian.curtin.edu.au/cga/faq/angles.html

        // Except OSG exchanges pitch & roll from what is listed on that page



        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 );



}

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to