This is how I do it... not sure if it is best, but it works for me:
Everyone feel free to poke holes at this, as I'd like to know what is best. ;)
The context of this code is for flight dynamics and the class natively works
with m_QuatToUse. It only extracts frame size delta's in a form of yaw pitch
and roll, but everything is preserved in quats.
osg::Vec3d ComputeAngularDistance(const osg::Vec3d &lookDir,const osg::Vec3d
&UpDir)
{
osg::Vec3d ret(0.0,0.0,0.0);
////////////////////////////////////////////////////////////////////////////////////////////////
//Default 0,1,0 Yaw,Pitch,Roll
//Look up negative, down positive
//Look left negative right positive
//printf("\r %f %f %f camera
",lookDir[0],lookDir[1],lookDir[2]);
osg::Vec3d CurrentOrientation(m_QuatToUse.conj()*lookDir);
//printf("\r %f %f %f ship
",CurrentOrientation[0],CurrentOrientation[1],CurrentOrientation[2]);
ret[0]=atan2(CurrentOrientation[0],CurrentOrientation[1]); //Angle in radians
if (CurrentOrientation[1]>0.0)
ret[1]=atan2(CurrentOrientation[2],CurrentOrientation[1]); //Angle in radians
else
ret[1]=atan2(CurrentOrientation[2],-(CurrentOrientation[1])); //Angle in
radians
osg::Vec3d RollOrientation(m_QuatToUse.conj()*UpDir);
//printf("\r %f %f %f ship
",RollOrientation[0],RollOrientation[1],RollOrientation[2]);
ret[2]=atan2(RollOrientation[0],RollOrientation[2]); //Angle in radians
//printf("\r %f degrees ",RAD_2_DEG(RollOffset));
return ret;
}
----- Original Message -----
From: "Christian Sam" <[email protected]>
To: <[email protected]>
Sent: Wednesday, June 03, 2009 6:59 AM
Subject: [osg-users] get the x-axis angle of a rotation
> Hi,
>
> i have a manipulator which stores the rotation in a quaternion. i would like
> to extract the angle of the, in matrix-words, x-axis of that rotation.
> (think of a firstperson-view - i would like to extract the angle which
> defines how much i look up/down)
>
> is there an easy way to get this done?
>
>
> Thanks in advance,
> Christian
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=13417#13417
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> _______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org