void LineOfSightTether::operator()(osg::Node* node, osg::NodeVisitor* nv) { if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) { LinearLineOfSightNode* los = static_cast<LinearLineOfSightNode*>(node); if ( los->getMapNode() ) { if (_startNode.valid()) { osg::Vec3d worldStart = getNodeCenter(_startNode); //Convert to mappoint since that is what LOS expects GeoPoint mapStart; mapStart.fromWorld( los->getMapNode()->getMapSRS(), worldStart ); los->setStart( mapStart ); //.vec3d() ); } if (_endNode.valid()) { osg::Vec3d worldEnd = getNodeCenter( _endNode ); //Convert to mappoint since that is what LOS expects GeoPoint mapEnd; mapEnd.fromWorld( los->getMapNode()->getMapSRS(), worldEnd ); los->setEnd( mapEnd ); //.vec3d() ); } } } traverse(node, nv); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); // load the .earth file from the command line. osg::Node* earthNode = osgDB::readNodeFiles( arguments ); if (!earthNode) { OE_NOTICE << "Unable to load earth model" << std::endl; return 1; } osg::Group* root = new osg::Group(); osgEarth::MapNode * mapNode = osgEarth::MapNode::findMapNode( earthNode ); if (!mapNode) { OE_NOTICE << "Could not find MapNode " << std::endl; return 1; } osgEarth::Util::EarthManipulator* manip = new EarthManipulator(); viewer.setCameraManipulator( manip ); root->addChild( earthNode ); viewer.getCamera()->addCullCallback( new AutoClipPlaneCullCallback(mapNode)); //Create a point to point LineOfSightNode. LinearLineOfSightNode* los = new LinearLineOfSightNode( mapNode, osg::Vec3d(-121.665, 46.0878, 1258.00), osg::Vec3d(-121.488, 46.2054, 3620.11)); root->addChild( los ); los->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); //Create an editor for the point to point line of sight that allows you to drag the beginning and end points around. //This is just one way that you could manipulator the LineOfSightNode. LinearLineOfSightEditor* p2peditor = new LinearLineOfSightEditor( los ); root->addChild( p2peditor ); //Create a relative point to point LineOfSightNode. LinearLineOfSightNode* relativeLOS = new LinearLineOfSightNode( mapNode, osg::Vec3d(-121.2, 46.1, 10), osg::Vec3d(-121.488, 46.2054, 10)); relativeLOS->setStartAltitudeMode( ALTMODE_RELATIVE ); relativeLOS->setEndAltitudeMode( ALTMODE_RELATIVE ); root->addChild( relativeLOS ); relativeLOS->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); LinearLineOfSightEditor* relEditor = new LinearLineOfSightEditor( relativeLOS ); root->addChild( relEditor ); //Create a RadialLineOfSightNode that allows you to do a 360 degree line of sight analysis. RadialLineOfSightNode* radial = new RadialLineOfSightNode( mapNode ); radial->setCenter( osg::Vec3d(-121.515, 46.054, 847.604) ); radial->setRadius( 2000 ); radial->setNumSpokes(100); radial->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); root->addChild( radial ); RadialLineOfSightEditor* radialEditor = new RadialLineOfSightEditor( radial ); root->addChild( radialEditor ); //Create a relative RadialLineOfSightNode that allows you to do a 360 degree line of sight analysis. RadialLineOfSightNode* radialRelative = new RadialLineOfSightNode( mapNode ); radialRelative->setCenter( osg::Vec3d(-121.2, 46.054, 10) ); radialRelative->setAltitudeMode( ALTMODE_RELATIVE ); radialRelative->setRadius( 3000 ); radialRelative->setNumSpokes(60); radialRelative->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); root->addChild( radialRelative ); RadialLineOfSightEditor* radialRelEditor = new RadialLineOfSightEditor( radialRelative ); root->addChild( radialRelEditor ); //Create an editor for the radial line of sight that allows you to drag it around. //Load a plane model. osg::ref_ptr< osg::Node > plane = osgDB::readNodeFile("../data/cessna.osg.5,5,5.scale"); //Create 2 moving planes osg::Node* plane1 = createPlane(plane, mapNode, osg::Vec3d(-121.656, 46.0935, 4133.06), 5000, 20); osg::Node* plane2 = createPlane(plane, mapNode, osg::Vec3d(-121.321, 46.2589, 1390.09), 3000, 5); root->addChild( plane1 ); root->addChild( plane2 ); //Create a LineOfSightNode that will use a LineOfSightTether callback to monitor //the two plane's positions and recompute the LOS when they move LinearLineOfSightNode* tetheredLOS = new LinearLineOfSightNode( mapNode); tetheredLOS->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); root->addChild( tetheredLOS ); tetheredLOS->setUpdateCallback( new LineOfSightTether( plane1, plane2 ) ); //Create another plane and attach a RadialLineOfSightNode to it using the RadialLineOfSightTether osg::Node* plane3 = createPlane(plane, mapNode, osg::Vec3d( -121.463, 46.3548, 1348.71), 10000, 5); root->addChild( plane3 ); RadialLineOfSightNode* tetheredRadial = new RadialLineOfSightNode( mapNode ); tetheredRadial->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); tetheredRadial->setRadius( 5000 ); //This RadialLineOfSightNode is going to be filled, so set some alpha values for the colors so it's partially transparent tetheredRadial->setFill( true ); tetheredRadial->setGoodColor( osg::Vec4(0,1,0,0.3) ); tetheredRadial->setBadColor( osg::Vec4(1,0,0,0.3) ); tetheredRadial->setNumSpokes( 100 ); root->addChild( tetheredRadial ); tetheredRadial->setUpdateCallback( new RadialLineOfSightTether( plane3 ) ); manip->setHomeViewpoint(Viewpoint( "Mt Rainier", osg::Vec3d( -121.488, 46.2054, 0 ), 0.0, -50, 100000 )); viewer.setSceneData( root ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgViewer::ThreadingHandler()); viewer.addEventHandler(new osgViewer::LODScaleHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); // load the .earth file from the command line. osg::Node* earthNode = osgDB::readNodeFiles( arguments ); if (!earthNode) { OE_NOTICE << "Unable to load earth model" << std::endl; return 1; } osg::Group* root = new osg::Group(); osgEarth::MapNode * mapNode = osgEarth::MapNode::findMapNode( earthNode ); if (!mapNode) { OE_NOTICE << "Could not find MapNode " << std::endl; return 1; } osgEarth::Util::EarthManipulator* manip = new EarthManipulator(); viewer.setCameraManipulator( manip ); root->addChild( earthNode ); //viewer.getCamera()->addCullCallback( new AutoClipPlaneCullCallback(mapNode)); osg::Group* losGroup = new osg::Group(); losGroup->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); losGroup->getOrCreateStateSet()->setAttributeAndModes(new osg::Depth(osg::Depth::ALWAYS, 0, 1, false)); root->addChild(losGroup); // so we can speak lat/long: const SpatialReference* mapSRS = mapNode->getMapSRS(); const SpatialReference* geoSRS = mapSRS->getGeographicSRS(); //Create a point to point LineOfSightNode. LinearLineOfSightNode* los = new LinearLineOfSightNode( mapNode, GeoPoint(geoSRS, -121.665, 46.0878, 1258.00, ALTMODE_ABSOLUTE), GeoPoint(geoSRS, -121.488, 46.2054, 3620.11, ALTMODE_ABSOLUTE) ); losGroup->addChild( los ); //Create an editor for the point to point line of sight that allows you to drag the beginning and end points around. //This is just one way that you could manipulator the LineOfSightNode. LinearLineOfSightEditor* p2peditor = new LinearLineOfSightEditor( los ); root->addChild( p2peditor ); //Create a relative point to point LineOfSightNode. LinearLineOfSightNode* relativeLOS = new LinearLineOfSightNode( mapNode, GeoPoint(geoSRS, -121.2, 46.1, 10, ALTMODE_RELATIVE), GeoPoint(geoSRS, -121.488, 46.2054, 10, ALTMODE_RELATIVE) ); losGroup->addChild( relativeLOS ); LinearLineOfSightEditor* relEditor = new LinearLineOfSightEditor( relativeLOS ); root->addChild( relEditor ); //Create a RadialLineOfSightNode that allows you to do a 360 degree line of sight analysis. RadialLineOfSightNode* radial = new RadialLineOfSightNode( mapNode ); radial->setCenter( GeoPoint(geoSRS, -121.515, 46.054, 847.604, ALTMODE_ABSOLUTE) ); radial->setRadius( 2000 ); radial->setNumSpokes( 100 ); losGroup->addChild( radial ); RadialLineOfSightEditor* radialEditor = new RadialLineOfSightEditor( radial ); losGroup->addChild( radialEditor ); //Create a relative RadialLineOfSightNode that allows you to do a 360 degree line of sight analysis. RadialLineOfSightNode* radialRelative = new RadialLineOfSightNode( mapNode ); radialRelative->setCenter( GeoPoint(geoSRS, -121.2, 46.054, 10, ALTMODE_RELATIVE) ); radialRelative->setRadius( 3000 ); radialRelative->setNumSpokes(60); losGroup->addChild( radialRelative ); RadialLineOfSightEditor* radialRelEditor = new RadialLineOfSightEditor( radialRelative ); losGroup->addChild( radialRelEditor ); //Load a plane model. osg::ref_ptr< osg::Node > plane = osgDB::readNodeFile("../data/cessna.osgb.5,5,5.scale"); //Create 2 moving planes osg::Node* plane1 = createPlane(plane, GeoPoint(geoSRS, -121.656, 46.0935, 4133.06, ALTMODE_ABSOLUTE), mapSRS, 5000, 20); osg::Node* plane2 = createPlane(plane, GeoPoint(geoSRS, -121.321, 46.2589, 1390.09, ALTMODE_ABSOLUTE), mapSRS, 3000, 5); root->addChild( plane1 ); root->addChild( plane2 ); //Create a LineOfSightNode that will use a LineOfSightTether callback to monitor //the two plane's positions and recompute the LOS when they move LinearLineOfSightNode* tetheredLOS = new LinearLineOfSightNode( mapNode); losGroup->addChild( tetheredLOS ); tetheredLOS->setUpdateCallback( new LineOfSightTether( plane1, plane2 ) ); //Create another plane and attach a RadialLineOfSightNode to it using the RadialLineOfSightTether osg::Node* plane3 = createPlane(plane, GeoPoint(geoSRS, -121.463, 46.3548, 1348.71, ALTMODE_ABSOLUTE), mapSRS, 10000, 5); losGroup->addChild( plane3 ); RadialLineOfSightNode* tetheredRadial = new RadialLineOfSightNode( mapNode ); tetheredRadial->setRadius( 5000 ); //This RadialLineOfSightNode is going to be filled, so set some alpha values for the colors so it's partially transparent tetheredRadial->setFill( true ); tetheredRadial->setGoodColor( osg::Vec4(0,1,0,0.3) ); tetheredRadial->setBadColor( osg::Vec4(1,0,0,0.3) ); tetheredRadial->setNumSpokes( 100 ); losGroup->addChild( tetheredRadial ); tetheredRadial->setUpdateCallback( new RadialLineOfSightTether( plane3 ) ); osgEarth::Viewpoint vp; vp.name() = "Mt Ranier"; vp.focalPoint()->set(geoSRS, -121.488, 46.2054, 0, ALTMODE_ABSOLUTE); vp.pitch() = -50.0; vp.range() = 100000; manip->setHomeViewpoint( vp ); viewer.setSceneData( root ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgViewer::ThreadingHandler()); viewer.addEventHandler(new osgViewer::LODScaleHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }