Code:
void getEulerFromQuat(osg::Quat q, double& heading, double& attitude, double& 
bank) 
{
        double limit = 0.499999;
        double sqx = q.x()*q.x();
        double sqy = q.y()*q.y();
        double sqz = q.z()*q.z();
        double t = q.x()*q.y() + q.z()*q.w();

        if (t>limit) // gimbal lock?
        {
                heading = 2 * atan2(q.x(),q.w());
                attitude = osg::PI_2;
                bank = 0;
        }
        else if (t<-limit) 
        {
                heading = -2 * atan2(q.x(),q.w());
                attitude = - osg::PI_2;
                bank = 0; 
        }
        else
        { 
                heading = atan2(2*q.y()*q.w()-2*q.x()*q.z() , 1 - 2*sqy - 
2*sqz); 
                attitude = asin(2*t);
                bank = atan2(2*q.x()*q.w()-2*q.y()*q.z() , 1 - 2*sqx - 2*sqz);
        } 
} 



------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43903#43903





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to