[osg-users] Transformations using Quat and Mat

Michael Maurus michael.maurus at web.de
Tue Nov 14 06:43:02 PST 2017


Hello everyboy,

currently, I am trying to get some transformations working to display a cylinder as a line of sight.
As you can see in the code below, I want to get the rotation represented by the Quaternion q into the Matrix mat, but neither preMultRotate using the quat nor multiplying as a Matrix won't give the expected results.
Any ideas/clues?

I am using OpenSceneGraph 3.5.5, commit from 7.10.2016 (6142ea1d4671c18ff1cb51bc49ba74c11df0d15b)


Code:

osg::Vec3 dir(1,1,1);
osg::Vec3 z(0,0,1);
dir.normalize();
osg::Quat q = getQuaternionFromTwoVectors(z, dir);

//q*z == dir.normalize() => TRUE (0.57735, 0.57735, 0.57735)

osg::Matrixd MV = getModelViewmatrix();
osg::Matrixd invMV = osg::Matrix::inverse(MV);

//invMV * MV * z == z => TRUE

//q * (invMV * MV * z) == dir.normalize() => true

osg::Matrixd mat = invMat;
mat.preMultRotate(q);

//mat * MV * u == dir.normalize() => false (-0.57735, -0.57735, 0.57735) instead of (0.57735, 0.57735, 0.57735)

mat = osg::Matrixd(q) * mat;
//mat * MV * u == dir.normalize() => false (-0.57735, -0.57735, 0.57735) instead of (0.57735, 0.57735, 0.57735)




Thank you!

Cheers,
Michael

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







More information about the osg-users mailing list