Thanks for the quick response. Assuming that we want to plug this hole in OpenSG2, where should I add this? Quaternion or Matrix class?
-Allen Antonio Bleile wrote: >Hi Allen, > >had the same problem, no there's no such functions in OpenSG (AFAIK). I >found some routines on the internet >http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToMa >trix/index.htm > >Below two methods that do the matrix to euler axis rotation >and inverse.... You just have to pass from the quaternion to >the matrix which OpenSG already provides. > >Cheers, > > Toni > >P.S.: All angles in degrees. > > >OSG::Matrix eulerToMatrix( double rotX, double rotY, double rotZ ) >{ > // ripped from > >//http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerTo >Matrix/index.htm > double ch = cos(M_PI*rotX/180.0); > double sh = sin(M_PI*rotX/180.0); > double ca = cos(M_PI*rotY/180.0); > double sa = sin(M_PI*rotY/180.0); > double cb = cos(M_PI*rotZ/180.0); > double sb = sin(M_PI*rotZ/180.0); > > Matrix rot; > rot[0][0] = ch * ca; > rot[0][1] = sh*sb - ch*sa*cb; > rot[0][2] = ch*sa*sb + sh*cb; > rot[1][0] = sa; > rot[1][1] = ca*cb; > rot[1][2] = -ca*sb; > rot[2][0] = -sh*ca; > rot[2][1] = sh*sa*cb + ch*sb; > rot[2][2] = -sh*sa*sb + ch*cb; > > return rot; >} > > >void matrixToEuler( OSG::Matrix m, double &rotX, double &rotY, double &rotZ >) >{ > Vec3f translation, scaleFactor, rotAxis; > Quaternion osgrotation, scaleOrientation; > > // remove the scale part of the matrix, > // else the calculus below won't work correctly > > m.getTransform( translation, osgrotation, scaleFactor, >scaleOrientation ); > > scaleFactor[0] = 1.0; > scaleFactor[1] = 1.0; > scaleFactor[2] = 1.0; > > m.setTransform( translation, osgrotation, scaleFactor); > > // ripped from > >//http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerTo >Matrix/index.htm > > if (m[1][0] > 0.99998) { // singularity at north pole > rotX = atan2(m[0][2],m[2][2]); > rotY = M_PI/2; > rotZ = 0; > } > else if (m[1][0] < -0.99998) { // singularity at south pole > rotX = atan2(m[0][2],m[2][2]); > rotY = -M_PI/2; > rotZ = 0; > }else{ > rotX = atan2(-m[2][0],m[0][0]); // heading > rotZ = atan2(-m[1][2],m[1][1]); // bank > rotY = asin(m[1][0]); // attitude > } > > rotX *= 180.0/M_PI; > rotY *= 180.0/M_PI; > rotZ *= 180.0/M_PI; >} > > > >>-----Original Message----- >>From: [EMAIL PROTECTED] [mailto:opensg-users- >>[EMAIL PROTECTED] On Behalf Of Allen Bierbaum >>Sent: Wednesday, September 27, 2006 6:27 PM >>To: opensg-users >>Subject: [Opensg-users] Getting axis rotations (eulers) from a Quaterion >> >>Is there any way in OpenSG to get rotations around the individual axes >>(euler angles) from a Quaternion? Does anyone have utility code to do >>it with an OpenSG quaternion? >> >>I have found a method to set a quaternion from this information >>(setValue(float,float,float)) but I don't see any routine to get the >>information back out in this form. (and yes I know there will be >>multiple possible ways to represent the values but I need a way to >>represent a rotation in a GUI and AFAIK rotations in degrees around the >>3 axes are still the best way to do this) >> >>-Allen >> >> >>------------------------------------------------------------------------- >>Take Surveys. Earn Cash. Influence the Future of IT >>Join SourceForge.net's Techsay panel and you'll get the chance to share >>your >>opinions on IT & business topics through brief surveys -- and earn cash >>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >>_______________________________________________ >>Opensg-users mailing list >>Opensg-users@lists.sourceforge.net >>https://lists.sourceforge.net/lists/listinfo/opensg-users >> >> > > > >------------------------------------------------------------------------- >Take Surveys. Earn Cash. Influence the Future of IT >Join SourceForge.net's Techsay panel and you'll get the chance to share your >opinions on IT & business topics through brief surveys -- and earn cash >http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >_______________________________________________ >Opensg-users mailing list >Opensg-users@lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/opensg-users > > > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users