8

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.

Lord_Herman
  • 97
  • 2
  • 10

3 Answers3

5

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;
user2658323
  • 543
  • 4
  • 15
  • Although I'm not even working on that, I have to say thank you for your answer. Also, it was my 1st post and I can't remember what I did to solve that, but I finally did it. – Lord_Herman Apr 07 '14 at 12:07
  • It has been more than a year from the question, I can't remember what I needed but at the end I did it – Lord_Herman Apr 08 '14 at 06:53
1

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.

Ruan Caiman
  • 881
  • 5
  • 5
0

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.

XenonofArcticus
  • 573
  • 2
  • 7