Re: [osg-users] Transformations using Quat and Mat
Hi, Maurus, I think it's the order of the multiplies. It should be like vec*MatA*MatB, If you want to apply an osg::Matrix on a osg::Vec. But I do not quiet know why osg::Quat does not obey this: for a osg::Quat, the form quat * vec is used.___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Transformations using Quat and Mat
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 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Transformations
Hi, It was the loading of the rotation Matrix, the Y-up Rotation just rotates 90 degrees on the wrong axis, but the animation was still working OK :) Pau -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15319#15319 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Transformations
Hi Pau, On 21/7/09 10:12 PM, Pau Moreno wrote: Thank you very much Ulrich!! It works! I don't know why the other things I've tried didn't work but now is working!!! Out of curiosity, what was the issue? The loading of the existing matrix into osg::Matrix or the order of transformation or the Y-up rotation? Cheers /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Transformations
Hi, Thank you very much Ulrich!! It works! I don't know why the other things I've tried didn't work but now is working!!! Thank you! Cheers, Pau -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15195#15195 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Transformations
Hi Ümit, I try to use osg::Switch to insert all the data I have in the files( each file in a separate node with his own transform matrix ), so I can switch the nodes in each frame, but I don't know why it seems that the second and following data I insert accumulates the previous matrix transformation, and I don't want this. I write it seems because I cannot be sure about that, my models are doing some strange movements that are not correctly. I also have a sphere attached to the root node after I attach the switch node, and it seems to be also afected by the previous transformation... Althought, that's not my biggest problem, I can just fix it by adding and deleting one by one the nodes to the root node. My problem is that the transformation I apply in OGL is not the same as in OSG, and I need the same transformation. So the gridOrientation is a Matrix3x3 wich contains the rotation in the object. , that's why I'm adding some more values. My matrix rotation in OGL is like that: gridOrientation.set(0,0,rotation.get(0,0)); gridOrientation.set(0,1,rotation.get(1,0)); gridOrientation.set(0,2,rotation.get(2,0)); gridOrientation.set(0,3,0.0f); gridOrientation.set(1,0,rotation.get(0,1)); gridOrientation.set(1,1,rotation.get(1,1)); gridOrientation.set(1,2,rotation.get(2,1)); gridOrientation.set(1,3,0.0f); gridOrientation.set(2,0,rotation.get(0,2)); gridOrientation.set(2,1,rotation.get(1,2)); gridOrientation.set(2,2,rotation.get(2,2)); gridOrientation.set(2,3,0.0f); gridOrientation.set(3,0,0.0f); gridOrientation.set(3,1,0.0f); gridOrientation.set(3,2,0.0f); gridOrientation.set(3,3,1.0f); As I can understand about the precedence of OGL and OSG, if I do translate and then rotate in ogl, I have to do rotate * translate in OSG Otherwise, I've tried both combinations, and no one is working... :S Cheers, Pau. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15115#15115 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Transformations
On 17/7/09 8:19 PM, Pau Moreno Font wrote: I'm trying to change my OGL code to OSG but I'm having really problems with the transformations... I have 174 data files that each contains a cloud of points, a vector3 with the translartion, and the matrix of rotation of each cloud. So in OGL, i just do: { LoadFile( x++) //Loads a diferent file in each iteration glPushMatrix(); glTranslate( x , y , z ) glMultMatrixf( rotation ); { osg::Matrixf rotation; rotation.set( gridOrientation.get( 0 , 0 ) , gridOrientation.get( 0 , 1 ) , gridOrientation.get( 0 , 2 ) , 0.0, gridOrientation.get( 1 , 0 ) , gridOrientation.get( 1 , 1 ) , gridOrientation.get( 1 , 2 ) , 0.0, gridOrientation.get( 2 , 0 ) , gridOrientation.get( 2 , 1 ) , gridOrientation.get( 2 , 2 ) , 0.0, 0.0f , 0.0f , 0.0f , 1.0f ); translation.setTrans( x , y , z ); By the way I read the OSGQSG (page 64) the memory layout of OSG and OpenGL matrices is identical. So it should be possible to pass the 'rotation' matrix from the OGL code to the Matrix constructor and at least tie down that end. rotationOGL.makeRotate( osg::DegreesToRadians(90.0) , osg::Vec3d( 0.0 , 1.0 , 0.0 )); transformationOGL-setMatrix(rotationOGL); transformationOGL-addChild(m_root); m_vViewer.setSceneData( transformationOGL ); Is 'rotationOGL' is supposed to convert OSG Z-up convention to OpenGL's Y-up? If that's the case you should rotate around the X-axis, not the Y-axis. Also: this probably doesn't affect the outcome but I tend to use osg::Vec3 and osg::Matrix instead of their respective float/double versions and instead rely on OSG to pick its compile setting. Cheers, /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Transformations
Hi, I'm trying to change my OGL code to OSG but I'm having really problems with the transformations... I have 174 data files that each contains a cloud of points, a vector3 with the translartion, and the matrix of rotation of each cloud. So in OGL, i just do: { LoadFile( x++) //Loads a diferent file in each iteration glPushMatrix(); glTranslate( x , y , z ) glMultMatrixf( rotation ); glBegin( GL_POINTS ) glEnd(); glPopMatrix(); } So in OSG first of all I try to do it with a osg::Switch but seems that this node accumulate the transformations... is that right?? So what I finally do is to attach a diferent node in each iteration and detach the previous one. But the real problem is that OSG is not doing the same as OGL. I do this for each node: { osg::Matrixf rotation; osg::Matrixf translation; osg::Matrixf result; rotation.set( gridOrientation.get( 0 , 0 ) , gridOrientation.get( 0 , 1 ) , gridOrientation.get( 0 , 2 ) , 0.0, gridOrientation.get( 1 , 0 ) , gridOrientation.get( 1 , 1 ) , gridOrientation.get( 1 , 2 ) , 0.0, gridOrientation.get( 2 , 0 ) , gridOrientation.get( 2 , 1 ) , gridOrientation.get( 2 , 2 ) , 0.0, 0.0f , 0.0f , 0.0f , 1.0f ); translation.setTrans( x , y , z ); result = rotation * translation; osg::MatrixTransform *transformation = new osg::MatrixTransform(); transformation-addChild( gNode ); transformation-setMatrix( result ); } rotationOGL.makeRotate( osg::DegreesToRadians(90.0) , osg::Vec3d( 0.0 , 1.0 , 0.0 )); transformationOGL-setMatrix(rotationOGL); transformationOGL-addChild(m_root); m_vViewer.setSceneData( transformationOGL ); m_root-addChild( transformation ); . What I'm doing wrong? I've tried a lot of combinations of creating rotation , translation, result, but no one is the correct!! I think I'm doing something wrong I cannot apreciate. Thanks!! ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Transformations
Hi Paul; So in OSG first of all I try to do it with a osg::Switch but seems that this node accumulate the transformations... is that right? What do you mean about osg::Switch. It's not specific feaute on accumulating trasformation for osg::Switch as I know. It actual target is switching node while rendering scene graph. What type gridOrientation is? Be careful while multiplying the matricies because precedence is important for kind of these operations : result = rotation * translation; Regards. Ümit Uzun 2009/7/17 Pau Moreno Font tekka...@gmail.com Hi, I'm trying to change my OGL code to OSG but I'm having really problems with the transformations... I have 174 data files that each contains a cloud of points, a vector3 with the translartion, and the matrix of rotation of each cloud. So in OGL, i just do: { LoadFile( x++) //Loads a diferent file in each iteration glPushMatrix(); glTranslate( x , y , z ) glMultMatrixf( rotation ); glBegin( GL_POINTS ) glEnd(); glPopMatrix(); } So in OSG first of all I try to do it with a osg::Switch but seems that this node accumulate the transformations... is that right?? So what I finally do is to attach a diferent node in each iteration and detach the previous one. But the real problem is that OSG is not doing the same as OGL. I do this for each node: { osg::Matrixf rotation; osg::Matrixf translation; osg::Matrixf result; rotation.set( gridOrientation.get( 0 , 0 ) , gridOrientation.get( 0 , 1 ) , gridOrientation.get( 0 , 2 ) , 0.0, gridOrientation.get( 1 , 0 ) , gridOrientation.get( 1 , 1 ) , gridOrientation.get( 1 , 2 ) , 0.0, gridOrientation.get( 2 , 0 ) , gridOrientation.get( 2 , 1 ) , gridOrientation.get( 2 , 2 ) , 0.0, 0.0f , 0.0f , 0.0f , 1.0f ); translation.setTrans( x , y , z ); result = rotation * translation; osg::MatrixTransform *transformation = new osg::MatrixTransform(); transformation-addChild( gNode ); transformation-setMatrix( result ); } rotationOGL.makeRotate( osg::DegreesToRadians(90.0) , osg::Vec3d( 0.0 , 1.0 , 0.0 )); transformationOGL-setMatrix(rotationOGL); transformationOGL-addChild(m_root); m_vViewer.setSceneData( transformationOGL ); m_root-addChild( transformation ); . What I'm doing wrong? I've tried a lot of combinations of creating rotation , translation, result, but no one is the correct!! I think I'm doing something wrong I cannot apreciate. Thanks!! ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org