[osg-users] Getting the combined matrix from a Node?

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Mon May 7 23:27:57 PDT 2018


Hi Marlin,

you need to get the appropriate parent-node paths:

osg::NodePathList parent_node_list = mat.getParentalNodePaths();
Now if you know the path you want to retrieve, you can call
e.g.:
node_path = parent_node_list[1];

osg::Matrix mat = osg::computeLocalToWorld(node_path);

Also the getParentalNodePaths() function lets you specify the node in 
the parent path where to stop traversal (e.g. to get transformations in 
a local model reference-frame)

The reason is, that the scene-graph is a DAG where nodes can have 
multiple parents.
Another possibility is to use the per-instance transform inside an 
update callback:

void MyUpdateCallback::operator()( osg::Node* node, osg::NodeVisitor* nv)
{
	osg::NodePath& node_path = nv->getNodePath() ;
	osg::Matrix mat = osg::computeLocalToWorld(node_path);
	///...
	traverse(node,nv);
}



Cheers
Sebastian


Am 07.05.2018 um 20:58 schrieb Rowley, Marlin R:
> Hello,
> 
> I’m trying to figure out how to retrieve the combined matrix from a node 
> that is of a PositionAttitudeTransform node type.  I can get it 
> converted to a Transform() class, but there is no clear way of getting 
> the combined matrix from local to world.  For example,
> 
> Osg::PositionAttitudeTransform trans;
> 
> Trans.setScale(2,2,2);
> 
> Trans.setPosition(0,10,0);
> 
> Osg::Matrixd temp = getCombinedTransform(trans);
> 
> Osg::Matrixd getCombinedTransform(const osg::ref_ptr<osg::Node> & mat)
> 
> {
> 
>                Auto m = mat->asTransform();
> 
>                Return m->computeLocalToWorldMatrix (m, ???); << ====== 
> why use a node visitor on yourself?
> 
>                Or
> 
>                Return m->getCombinedMatrix()?? <<  ===== is there such a 
> thing?
> 
> }
> 
> ----------------------------------------
> 
> Marlin Rowley
> 
> Software Engineer, Staff
> 
> cid:image002.jpg at 01D39374.DEC5A2E0
> 
> /Missiles and Fire Control/
> 
> 972-603-1931 (office)
> 
> 214-926-0622 (mobile)
> 
> marlin.r.rowley at lmco.com <mailto:marlin.r.rowley at lmco.com>
> 
> 
> 
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 


More information about the osg-users mailing list