OSG: get transformation matrix from node

First I have to apologize for my English.

I am working on an application in which every moment I need to know the attributes of each node (position, rotation ...), so I thought about taking the transformation matrix of each node from the scene graph.

The problem that I have is that I do not know how to do this. For example, if I have something like:

osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("cessna.osg.15,20,25.trans.180,90,360.rot.2,3,4.scale"); 

I want to take the transformation matrix from a node object called root. I found something like:

 osg::Matrix mat = osg::computeWorldToLocal(this->getNodePath()); std::cout << "X: " << mat.getTrans().x() << std::endl; std::cout << "Rot X: " << mat.getRotate().x() << std::endl; std::cout << "Scale X: " << mat.getScale().x() << std::endl; 

But I would just like to have only a matrix, is this possible?

Thanks.

PD: I use nodeVisitor for this.

+6
source share
3 answers

I think you just want to print the matrix on the console. In this case, use the stream operator specified in <osg/io_utils> :

 #include <osg/io_utils> std:: cout << mat; 
+3
source

Do you want you to just point to a 4x4 array? Try mat.ptr (); Or you can use overloaded () to get individual elements:

 mat(0,0) mat(0,1) mat(0,2) mat(0,3) mat(1,0) . . . mat(2,0) . . . mat(3,0) . . mat(3,3) 

ps, you can use decomposition to get translation, rotation and scaling values ​​in one call.

+1
source

Well, you have a matrix in osg :: Matrix mat. I don’t understand what you mean by "I would just like to have only a matrix." If you clarify, I can probably help you.

0
source

All Articles