Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 614
Lord_Herman Avatar asked Jan 31 '13 09:01

Lord_Herman


1 Answers

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;
like image 96
user2658323 Avatar answered Sep 29 '22 21:09

user2658323