Hi,

i'm trying to rotate a rod (part of a 3rd party model) on its Y asxis. I read 
on OSG Startguide that to do it, i need to find the correct position of my 
object from the origin and apply a multiplication like T * M * -T. 
The source code that tries to do it is the follow
Code:
ing:
printVector("    Original amtRod trans: ", 
amtRod->getWorldMatrices()[0].getTrans());
                    printVector("    Original amtRod rotate: ", 
amtRod->getWorldMatrices()[0].getRotate());
                    printVector("\t amtRod center: ", 
amtRod->getBound().center());
                    
                    osg::Vec3 offset = amtRod->getWorldMatrices()[0].getTrans();
                    printVector("\t amtRod offset =  ", offset);

                    osg::Matrix get = 
osg::Matrix::translate(-amtRod->getBound().center() - offset);
                    osg::Matrix m = amtRod->getMatrix() * 
osg::Matrix::rotate(rotation, osg::Vec3(0,1,0));
                    osg::Matrix put = osg::Matrix::translate( 
amtRod->getBound().center() + offset);
                    amtRod->setMatrix( get * m * put );

                    printVector("\t get.getTrans =  ", get.getTrans());
                    printVector("\t m.getRotate  =  ", m.getRotate());
                    printVector("\t m.getTrans   =  ", m.getTrans());
                    
                    printVector("    Current amtRod trans:  ", 
amtRod->getWorldMatrices()[0].getTrans());
                    printVector("    Current amtRod rotate: ", 
amtRod->getWorldMatrices()[0].getRotate());



(printVector only prints the osg::Vec3 or a osg::Quat in a file).
The result isn't what i expect, since it rotates the rod but also translate it, 
as the following output demonstrates:
    Original amtRod trans: (0, 0, -309)
    Original amtRod rotate: (0, 0, 0)
         amtRod center: (6.55547, 150.952, -142.15)
         amtRod offset =  (0, 0, -309)
         get.getTrans =  (-6.55547, -150.952, 451.15)
         m.getRotate  =  (0, -0.130526, 0)
         m.getTrans   =  (79.9751, 0, -298.471)
    Current amtRod trans:  (-36.5678, 0, -315.54)
    Current amtRod rotate: (0, -0.130526, 0)


What's wrong in my reasoning?


Thank you for help!

Cheers,
Axel

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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to