[osg-users] How to rotate node's local coordinate system?

403 views
Skip to first unread message

Elias Tarasov

unread,
Jun 22, 2015, 11:14:03 PM6/22/15
to osg-...@lists.openscenegraph.org
Hello!
I'm sorry for noob question, but i cannot figure out how to rotate node's local coordinate system.

For my task i use default OSG cessna model. According to my experiments, it has axes: X - from center to left wing. Y - from center down tail. Z - down.

What i want is to rotate axes: X - from center to nose. Y - from center to right wing. Z - down.

I think i have skills to define rotation matrix, but i don't know the way to rotate osg::Node and save that rotated osg::Node.

Basically something like that:

Code:

osg::ref_ptr<osg::Node> cessna = osgDB::readNodeFile(...)
//Here should be the "rotation" func
osg::ref_ptr<osg::Node> rotated_cessna = rotateLocalXYZ(cessna.get())

nodeTracker = new osgGA::NodeTrackerManipulator;

//now here i can setup eye and up vectors more consistently
nodeTracker->setHomePosition( Vec3(0,270,0), Vec3(), Z_AXIS );

nodeTracker->setTrackerMode( osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION );
nodeTracker->setTrackNode( rotated_cessna.get() );



Can anybody provided an example how to do it?

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64149#64149





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Jun 23, 2015, 3:45:15 AM6/23/15
to OpenSceneGraph Users
Hi Elias,

The osg::Transform is the base class for creating transforms in the scene graph, there are a collection of subclasses that you can use, osg::MatrixTransform and osg::PositionAttitudeTransform being the most commonly used, either of these can work for you.  Have a look at the osganimation example to see how to use these classes, or just do a search in the examples for MatrixTransform/PositionAttitudeTransform.

Robert.

Elias Tarasov

unread,
Jun 23, 2015, 4:55:58 AM6/23/15
to osg-...@lists.openscenegraph.org
Hello, Robert!
Thanks for the quick reply.
It seems i wasn't able to clarify my question. I dont use MatrixTransform or PositionAttitudeTransform here because i don't want to transform my target node relate to others. I want to change local XYZ in that node itself, not the position of my node relate to other nodes or world XYZ.

Let me describe more specifically.
Standart aerodynamic convention (and it also looks reasonable in most practical situations) defines local(body) coordinate system as:
O - center of mass (here just center of a node), X - from center up to nose, Y - from center up to right wing, Z - down. That leads to Roll, Pitch, Yaw rotations around X,Y,Z respectively.

Let say i want to place camera right behind cessna's tail. Then, AFAIK that code can help me

Code:

nodeTracker = new osgGA::NodeTrackerManipulator;
nodeTracker->setHomePosition( Vec3(-90,0,0), Vec3(), Z_AXIS );
nodeTracker->setTrackerMode(osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION );
nodeTracker->setTrackNode( cessna.get() );




So: eye Vec3(-90,0,0) means 90 behind center on X. //Local coords, right?
And of course what we can see now is depended on how X is oriented with respect to model body.

If, for instance, X has center at model's center and go straight up to nose,
then -90 means right behind tail (this is what i want to achieve)

But if X has center at model's center and go from right wing, then -90 means we see left side of an aeroplane, not the tail.

Then, even when cessna moves correctly (for instance, straight to the north), i see at as moving with right wing forward and nose to the west.

Also, Roll (rotation about X axis) will be looking like pitch (rotation about Y axis according to aerodynamic standart)
So to avoid confusion and necessity to remeber how that particular node (cessna) is oriented with respect to its own local coords, maybe the better
way is to rotate local coords somehow?

I might be wrong, just to explain why i cannot use Tranform classes according to you advice.

Could you explain how that problem might be solved?

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64161#64161

Robert Osfield

unread,
Jun 23, 2015, 5:09:36 AM6/23/15
to OpenSceneGraph Users
Hi Elias,

It seems to me that you are confusing local, world and eye coordinate frames.

I really don't know why you are discussing NodeTrackerManipualtor in this context, it's a camera manupulator for setting the view matrix of the viewer's Camera to follow a Node in the scene graph.  The manipulator is setting eye coordinates.  The object it tracks has a path from the root of the scene graph to the node, the transforms between the root and the node you specify provides the coordinate frame relative to world coordinates, where world coordinates it the coordinate frame of the root node.   The manipulator doesn't have any effect on the coordinate frame of the node being tracked, just affects viewer's Camera's view matrix.

If you want to change a node local coordinate frame then you use a transform.

Robert.



Sebastian Messerschmidt

unread,
Jun 23, 2015, 6:01:15 AM6/23/15
to osg-...@lists.openscenegraph.org
Hi Elias,


Seems like you are after a change of coordinate frame (e.g. which axis
is front/up etc.)
From my experience: don't ...
What I usually do ist to transform at the interface by using a
permutation matrix.
So for instance if you want
x = x´
y = -z
z = y

then multiply your incoming positions/orientation with the matrix
1 0 0 0
0 0 -1 0
0 1 0 0
0 0 0 1

and your outgoing with the inverse (or transpose in this case).

This saves you the trouble of fiddeling with the coordinates inside osg.

Cheers
Sebastian

Elias Tarasov

unread,
Jun 24, 2015, 7:56:23 AM6/24/15
to osg-...@lists.openscenegraph.org
Hi, Sebastian!
Your suggestion works, i get now properly oriented cessna.
However, my eye vector is oriented not as i expected.
So i can't say that i was able to properly figure out what happens with my node and camera.
Anyway, it's a one step closer now.

Thank you!

Cheers,
Elias

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64179#64179
Reply all
Reply to author
Forward
0 new messages