osg::Node can not be displayed front of the Earth on the screen

classic Classic list List threaded Threaded
3 messages Options
aozdin aozdin
Reply | Threaded
Open this post in threaded view
|

osg::Node can not be displayed front of the Earth on the screen

Hello,

I drew an osg::Node and I want to put it on the center of the screen like any labelControl. How can I do that? I put a sample code below.

If I change the line from
<<viewer.setSceneData( mainGroup );>> to <<viewer.setSceneData( nn.get() );>>
AND
remove these two lines
<<manipulator = new EarthManipulator(  arguments );>>
<<viewer.setCameraManipulator( manipulator ); >>

 I am only able to see the geometry which I draw. However if I setSceneData as mapNode and geometry which are in "mainGroup" and if my camera manipulator is EarthManipulator; I am only able to see the earth.
To sum up, I want to see the earth in the back and I want to put my geometry front of the earth and on the center of the screen.



osg::ref_ptr<osg::Node> createSceneGraph()
{
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
geom->setVertexArray( v.get() );

//horizontal
v->push_back( osg::Vec3( -1.f, 1.f, 0.f ) );
v->push_back( osg::Vec3( -0.6f, 1.f, 0.f ) );
v->push_back( osg::Vec3( -0.4f, 1.f, 0.f ) );
v->push_back( osg::Vec3( 0.f, 1.f, 0.f ) );

//vertical
v->push_back( osg::Vec3( -0.5f, 1.f, 0.5f ) );
v->push_back( osg::Vec3( -0.5f, 1.f, 0.1f ) );
v->push_back( osg::Vec3( -0.5f, 1.f, -0.5f ) );
v->push_back( osg::Vec3( -0.5f, 1.f, -0.1f ) );


osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
geom->setColorArray( c.get() );
geom->setColorBinding( osg::Geometry::BIND_OVERALL );
c->push_back( osg::Vec4( 1.f, 1.f, 1.f, 1.f ) );

osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
geom->setNormalArray( n.get() );
geom->setNormalBinding( osg::Geometry::BIND_OVERALL );
n->push_back( osg::Vec3( 0.f, -1.f, 0.f ) );

osg::LineWidth* linewdth = new osg::LineWidth();
linewdth->setWidth(25.0);
geom->getOrCreateStateSet()->setAttributeAndModes( linewdth, osg::StateAttribute::ON ) ;
geom->addPrimitiveSet(
        new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, 8 ) );

osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable( geom.get() );
return geode.get();
}

int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);
    viewer.setUpViewInWindow(100,100,500,500);
    viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( true, false );
    osgDB::Registry::instance()->getObjectWrapperManager()->findWrapper("osg::Image");
    manipulator = new EarthManipulator(  arguments );
    viewer.setCameraManipulator( manipulator );

    osg::Group* mainGroup = new osg::Group();
    osg::Group* group = MapNodeHelper().load(arguments, &viewer);
    osg::ref_ptr<osg::Node> nn = createSceneGraph();

    mainGroup->addChild(nn.get());
    mainGroup->addChild(group);
                               
    viewer.setSceneData( mainGroup );
    viewer.run();
}
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: osg::Node can not be displayed front of the Earth on the screen

aozdin,

OSG installs a default manipulator (the code that automatically configures the OpenGL view matrix based on mouse and keyboard input) based on the geometry it finds in the scene. So when you just load your own geometry, it centers the view on that geometry.

When you load it with a MapNode, the scene contains the planet (which is centered at 0,0,0 and is about 6371000m in radius) and your tiny 1m wide geometry at the center where you cannot see it.

You probably need a HUD (heads up display) camera. Go look at the OpenSceneGraph example called "osghud" to see how to set one up. This will help you draw your node in screen space instead of in world space.

https://github.com/openscenegraph/OpenSceneGraph/blob/master/examples/osghud/osghud.cpp

Good luck.
Glenn Waldron / Pelican Mapping
aozdin aozdin
Reply | Threaded
Open this post in threaded view
|

Re: osg::Node can not be displayed front of the Earth on the screen

Thank you, I solved the problem.