OSG: Get transform matrix from a node
Asked Answered
C

3

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.

Cryology answered 31/1, 2013 at 9:26 Comment(0)
A
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;
Acclamation answered 4/4, 2014 at 8:35 Comment(2)
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.Cryology
It has been more than a year from the question, I can't remember what I needed but at the end I did itCryology
M
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.

Muss answered 5/2, 2013 at 17:4 Comment(0)
B
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.

Blenheim answered 1/2, 2013 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.