简体   繁体   中英

OSG: Get transform matrix from a node

First af all i have to apologize for my english.

I'm working on an application where we have to know at each moment the attributes of each node (position, rotation...), so I thought about taking from the scene graph the transformation matrix of each node.

Te problem I have is that i don't 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 transform matrix from the Node object called root. I have 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 like just to have only the matrix, is it possible?

Thank you.

PD: I'm using nodeVisitor for doing this.

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

#include <osg/io_utils>

std:: cout << mat;

Do you mean you just want a pointer to the 4x4 array? Try mat.ptr(); Or you can use the overloaded () to get the 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 decompose to get your Translation, Rotation, and Scale values in one call.

Well, you have the matrix in osg::Matrix mat. I'm not clear on what you mean by "I would like just to have only the matrix". If you clarify, I can probably help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM