OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Getting the combined matrix from a Node?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Rowley, Marlin R
Guest





PostPosted: Mon May 07, 2018 7:01 pm    Post subject:
Getting the combined matrix from a Node?
Reply with quote

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

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)

------------------
Post generated by Mail2Forum
Back to top
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 822

PostPosted: Tue May 08, 2018 6:28 am    Post subject:
Getting the combined matrix from a Node?
Reply with quote

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:
Quote:
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:

/Missiles and Fire Control/

972-603-1931 (office)

214-926-0622 (mobile)

<mailto:>







------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12024

PostPosted: Tue May 08, 2018 7:24 am    Post subject:
Getting the combined matrix from a Node?
Reply with quote

Hi Marlin,


The Transform class and it's subclasses are designed to be used as part of scene graph, this allow Transform subclasses that are absolute (ignore transforms+camera matrices above them) or relative (multiple the inherited modelview matrix) to enable this in a generic way the Transform class has two helper methods Transform::computeLocalToWorld(osg::Matrix& matrix, NodeVistor*) and computeWorldToLocal(osg::Matrix& matrix, NodeVisior*). Only some Transform implementations need to check the NodeVisitor for extra data, most will just ignore that parameter and just do the matrix maths required.


The computeLocalToWorld() method returns a bool on success, and you pass in the matrix you want to apply,  You're code segment appears to confuse things in this regard. 



If you want to transform of any node in the scene graph you can do Node::getWorldMatrices(), this finds all the parental NodePaths of that node and then returns a vector containing a matrix for each NodePath found. 


Robert.







On 7 May 2018 at 19:58, Rowley, Marlin R < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:

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

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
 


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Stuck with applying an offset to proj... wernerM General 5 Mon Jun 25, 2018 10:11 am View latest post
No new posts Leaking memory on node removal Tini General 1 Fri May 25, 2018 6:48 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:39 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:30 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:27 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP