[osg-users] Yaw pitch and roll or xyz conversion to and from Quaternion

240 views
Skip to first unread message

Jason Anderssen

unread,
Dec 17, 2014, 5:31:17 PM12/17/14
to OpenSceneGraph Users
Hi all,

Just wondering if in OSG there is anywhere I can extract either Yaw pitch and roll / or XYZ eular angles, too and from either a matrix or a quaternion?

Thank you in advance.

Cheers
Jason Anderssen
Internet Email Confidentiality Footer: This email and any files transmitted with it contain privileged/confidential information intended for the addressee. Neither the confidentiality of nor any privilege in the email is waived, lost or destroyed by reason that it has been transmitted other than to the addressee. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message, and notify us immediately.

Chris Hanson

unread,
Dec 17, 2014, 5:48:22 PM12/17/14
to OpenSceneGraph Users
Just wondering if in OSG there is anywhere I can extract either Yaw pitch and roll / or XYZ eular angles, too and from either a matrix or a quaternion?

  The 
void get (Matrixd &matrix) const

method lets you convert a Quat to a 4x4 Matrix.

void decompose (osg::Vec3d &translation, osg::Quat &rotation, osg::Vec3d &scaleosg::Quat &so) const
 decompose the matrix into translation, rotation, scale and scale orientation. 

Will extract the trans, rot and scale components out of the matrix.

Is that what you want?

--
Chris 'Xenon' Hanson, omo sanza lettere. Xe...@AlphaPixel.com http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 • GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Digital Imaging • GIS • GPS • osgEarth • Terrain • Telemetry • Cryptography • Digital Audio • LIDAR • Kinect • Embedded • Mobile • iPhone/iPad/iOS • Android
@alphapixel facebook.com/alphapixel (775) 623-PIXL [7495]

Jason Anderssen

unread,
Dec 17, 2014, 6:03:10 PM12/17/14
to OpenSceneGraph Users
Hi Chris,

Thank you for you reply.

I had a look at those, maybe I can get it to work with them, but I really just want a simple 3 values for Yaw Pitch and Roll, from which I can re-create the exactly same Quat or Matrix.  I will also clarify, I don’t care about translation or scale etc, and the quaternion I am using is of course only a rotation anyway.

So basically I want the following type of code :

getYPR(float &yaw, float &pitch, float &roll);

Quaternion::fromYPR(yaw, pitch, roll);

Cheers
Jason Anderssen

_______________________________________________ osg-users mailing list osg-...@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org Internet Email Confidentiality Footer: This email and any files transmitted with it contain privileged/confidential information intended for the addressee. Neither the confidentiality of nor any privilege in the email is waived, lost or destroyed by reason that it has been transmitted other than to the addressee. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message, and notify us immediately.

Trajce Nikolov NICK

unread,
Dec 18, 2014, 3:14:49 AM12/18/14
to OpenSceneGraph Users
Hi Jason,

here you have YPR from osg::Quat (look at the snippets)

http://forum.openscenegraph.org/viewtopic.php?t=548

As for the other way it is easy, you create the Matrix and get the rotate Quat, (return matrix.getRotate()), something like:

osg::Matrixd Utils::createMatrix(double x, double y, double z, double h, double p, double r)
{
    osg::Matrixd mxR;
    mxR.makeRotate(osg::DegreesToRadians(r),osg::Vec3(0,1,0));
    osg::Matrixd mxP;
    mxP.makeRotate(osg::DegreesToRadians(p),osg::Vec3(1,0,0));
    osg::Matrixd mxH;
    mxH.makeRotate(osg::DegreesToRadians(h),osg::Vec3(0,0,1));
    osg::Matrixd mxT;
    mxT.makeTranslate(osg::Vec3(x,y,z));

    return (mxP*mxH*mxT*mxR);
}
--
trajce nikolov nick

Jason Anderssen

unread,
Dec 18, 2014, 9:10:36 PM12/18/14
to OpenSceneGraph Users
Hi NICK,

Thank you for your reply.

What do you think I maybe doing wrong with the following code : (NOTE: getHPRfromQuat is cut and paste from link, and the createMatrix is cut and paste from your reply.
I was basically hoping that q2  ==  q after the conversion to and from????

osg::Quat q(-0.7071067811865475, 0.0, 0.0, 0.7071067811865476);
osg::Vec3d hpr = getHPRfromQuat(q);

osg::Matrixd m = createMatrix(0.0, 0.0, 0.0, hpr.x(), hpr.y(), hpr.z());
osg::Quat q2;
q2.set(m);
Any assistance is very much appreciated.

Cheers
Jason Anderssen


Jason Anderssen, Senior Product Engineer
Exactal — Precision Software

Exactal Pty Ltd Level 2, Toowong Tower, 9 Sherwood Road, Toowong QLD 4066, Australia
P: +61 7 3870 2666   |   F: +61 7 3870 5266   |   jande...@exactal.com   |   www.exactal.com
Download CostX ViewerSend a CostX Invitation


From: osg-users [osg-user...@lists.openscenegraph.org] on behalf of Trajce Nikolov NICK [trajce.ni...@gmail.com]
Sent: Thursday, 18 December 2014 6:14 PM
To: OpenSceneGraph Users

Trajce Nikolov NICK

unread,
Dec 19, 2014, 3:10:59 AM12/19/14
to OpenSceneGraph Users
Hi Jason,

I had to apply -90 (in degrees) to the pitch to get the correct results after getHPRFromQuat(). Also createMatrix is expecting the input in degrees. Maybe this will help

Nick

Jordi Torres

unread,
Dec 19, 2014, 3:17:16 AM12/19/14
to OpenSceneGraph Users
Hi Jason et al,

I think in osgWorks there are utilities for such a conversion. Take a look to https://code.google.com/p/osgworks/source/browse/trunk/src/osgwTools/Orientation.cpp

Cheers. 
Jordi Torres


Jason Anderssen

unread,
Dec 19, 2014, 3:24:49 AM12/19/14
to OpenSceneGraph Users
Thank you very much, I shall test this and see that f it resolves my issues, by looking over it quickly I think it will.

Cheers
Jason

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages