Offset according to 3D Model

classic Classic list List threaded Threaded
5 messages Options
nebsar nebsar
Reply | Threaded
Open this post in threaded view
|

Offset according to 3D Model

Hello;

I want to add a drawable shape just next to my 3d model. How can I add the shape next to 3d model with an offset without using lat lon values? Thanks.

Nebi.
ceranco ceranco
Reply | Threaded
Open this post in threaded view
|

Re: Offset according to 3D Model

Hi Nebi,

In general, transformations are done by placing nodes under osg::Transform derived nodes.

You can use osg::MatrixTransform and osg::PositionAttitudeTransform for what you want, which is offsets without lat/lon values.

You should place the drawable under one of the transforms mentioned above, which itself should be placed as a brother to the 3d model under the transform node that transforms it.
For example:


osgEarth::GeoTransform (lat/lon values)
        |                                   |
   3d model    MatrixTransform/PositionAttitudeTransform
                                            |
                                       drawable
Eran Cohen
nebsar nebsar
Reply | Threaded
Open this post in threaded view
|

Re: Offset according to 3D Model

Thank you Eran. But since I am new to both OpenSceneGraph and Osg earth. I could not thoroughly understand transforms I think. Could you give me a more specific example. Thanks.

Nebi
ceranco ceranco
Reply | Threaded
Open this post in threaded view
|

Re: Offset according to 3D Model

Sure,

A model is typically loaded using osgDB in the following way:

osg::Node* model = osgDB::readNodeFile("path_to_file")


The model node contains the data telling OpenSceneGraph how to draw the model itself, but not where to draw it.
To enable transformations of nodes, OpenSceneGraph uses Transformation nodes.
These nodes affect all their children in the scene graph.

For example:

// this the root node of the scene graph
osg::Group* root = new osg::Group;

// this is the loaded model
osg::Node* model = osgDB::readNodeFile("path_to_file");

root->addChild(model);

osgViewer::Viewer viewer;
viewer.setSceneData(root);
viewer.run();

In the example above, I simply added the model under the root node. Because of this, the model will be drawn in the center of the 'world space'.
But what if I want to load another model 15 units to the side of the first model?
To accomplish this, I will use a osg::MatrixTransform. This transform takes a osg::Matrix and transforms its children accordingly:


// this the root node of the scene graph
osg::Group* root = new osg::Group;

// this is the first model
osg::Node* model1 = osgDB::readNodeFile("path_to_file");
// this is the secondmodel
osg::Node* model2 = osgDB::readNodeFile("path_to_file");

// this is my transform node, and will transform all of its children
osg::MatrixTransform* transform = new osg::MatrixTransform(osg::Matrix::translate(15, 0, 0));
// the second model is added to the transform so that it will be transformed
transform->addChild(model2);

root->addChild(model1);
root->addChild(transform)

osgViewer::Viewer viewer;
viewer.setSceneData(root);
viewer.run();

These are the basics of how transforms work. When you use osgEarth, you position a model according to the center of the earth, and also need to rotate it so that its down is toward earth's center.
To make this easier, osgEarth has a osgEarth::GeoTransform node.

Transform nodes can also be chained: GeoTransform->MatrixTransform->Model

What I meant in my first post, is that your 3d model should be positioned using a Transform node (GeoTransform if you are using LLA or ECEF). To offset your drawable be a certain amount, you should use another Transform under the first transform that will offset your drawable by however much you want, using world coordinates (x, y, z) instead of LLA.

I recommend that you read "OpenSceneGraph 3.0: Beginner's Guide" by Rui Wang, Xuelei Qian.
They cover the basics of OpenSceneGraph much better than I can, but if you have any other questions I'm happy to help.
Eran Cohen
nebsar nebsar
Reply | Threaded
Open this post in threaded view
|

Re: Offset according to 3D Model

Thank you for your help Eran. I will listen to your advise.

Regards.

Nebi.