[osg-users] osg::Node can not be displayed front of the Earth on the screen

Ali Ozdin alinailozdin at gmail.com
Fri Mar 2 07:23:33 PST 2018


I could not relate the example with my question. I am using osgEarth.
Can you be more expressive what causes this?

Thanks,


Trajce Nikolov NICK wrote:
> Hi Ali,
> 
> have a look at the osghud example from the osg repo
> 
> 
> On Fri, Mar 2, 2018 at 1:44 PM, Ali Ozdin < ()> wrote:
> 
> > Hi,
> > 
> > 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
> > 
> > Code:
> > viewer.setSceneData( mainGroup );
> > 
> >  to
> > Code:
> > viewer.setSceneData( nn.get() );
> > 
> > 
> > and remove these two lines
> > 
> > Code:
> > 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.
> > 
> > 
> > 
> > 
> > Code:
> > 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();
> > }
> > 
> > 
> > 
> > Thank you!
> > 
> > Cheers,
> > Ali
> > 
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=72998#72998 (http://forum.openscenegraph.org/viewtopic.php?p=72998#72998)
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > osg-users mailing list
> >  ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > 
> 
> 
> 
> 
> -- 
> trajce nikolov nick
> 
>  ------------------
> Post generated by Mail2Forum


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







More information about the osg-users mailing list