| 296 | | // add a viewport to the viewer and attach the scene graph. |
| 297 | | viewer.setSceneData(root.get()); |
| 298 | | |
| 299 | | osg::ref_ptr<osgGA::NodeTrackerManipulator> tm; |
| 300 | | |
| 301 | | osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get()); |
| 302 | | if (csn) |
| 303 | | { |
| 304 | | |
| 305 | | osg::ref_ptr<osgSim::OverlayNode> overlayNode; |
| 306 | | if (useOverlay) |
| 307 | | { |
| 308 | | overlayNode = new osgSim::OverlayNode(technique); |
| 309 | | |
| | 302 | |
| | 303 | if (!overlayFilename.empty()) |
| | 304 | { |
| | 305 | //osg::Object *pObj = osgDB::readObjectFile("alaska_clean.shp"); |
| | 306 | //osg::ref_ptr<osg::Geode> shapefile = dynamic_cast<osg::Geode*> (pObj); |
| | 307 | // |
| | 308 | //ConvertLatLon2EllipsoidCoordinates latlon2em; |
| | 309 | //shapefile->accept(latlon2em); |
| | 310 | |
| | 311 | osg::ref_ptr<osg::Node> shapefile = osgDB::readNodeFile(overlayFilename); |
| | 312 | |
| | 313 | if (!shapefile) |
| | 314 | { |
| | 315 | osg::notify(osg::NOTICE)<<"File `"<<overlayFilename<<"` not found"<<std::endl; |
| | 316 | return 1; |
| | 317 | } |
| | 318 | |
| | 319 | osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get()); |
| | 320 | if (csn) |
| | 321 | { |
| | 322 | |
| | 323 | osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode(technique); |
| | 324 | overlayNode->getOrCreateStateSet()->setTextureAttribute(1, new osg::TexEnv(osg::TexEnv::DECAL)); |
| | 325 | overlayNode->setOverlaySubgraph(shapefile.get()); |
| | 326 | overlayNode->setOverlayTextureSizeHint(1024); |
| | 327 | |
| 317 | | csn->addChild(overlayNode.get()); |
| 318 | | |
| 319 | | // tell the overlay node to continously update its overlay texture |
| 320 | | // as we know we'll be tracking a moving target. |
| 321 | | overlayNode->setContinuousUpdate(true); |
| 322 | | } |
| 323 | | |
| 324 | | |
| 325 | | osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); |
| 326 | | if (cessna) |
| 327 | | { |
| 328 | | double s = 200000.0 / cessna->getBound().radius(); |
| 329 | | |
| 330 | | osg::MatrixTransform* scaler = new osg::MatrixTransform; |
| 331 | | scaler->addChild(cessna); |
| 332 | | scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation)); |
| 333 | | scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); |
| 334 | | |
| 335 | | if (false) |
| 336 | | { |
| 337 | | osgSim::SphereSegment* ss = new osgSim::SphereSegment( |
| 338 | | osg::Vec3(0.0f,0.0f,0.0f), // center |
| 339 | | 19.9f, // radius |
| 340 | | osg::DegreesToRadians(135.0f), |
| 341 | | osg::DegreesToRadians(240.0f), |
| 342 | | osg::DegreesToRadians(-10.0f), |
| 343 | | osg::DegreesToRadians(30.0f), |
| 344 | | 60); |
| 345 | | |
| 346 | | scaler->addChild(ss); |
| 347 | | } |
| 348 | | |
| 349 | | osg::MatrixTransform* mt = new osg::MatrixTransform; |
| 350 | | mt->addChild(scaler); |
| 351 | | |
| 352 | | |
| 353 | | if (!nc) nc = new ModelPositionCallback(speed); |
| 354 | | |
| 355 | | mt->setUpdateCallback(nc); |
| 356 | | |
| 357 | | csn->addChild(mt); |
| 358 | | |
| 359 | | // if we are using an overaly node, use the cessna subgraph as the overlay subgraph |
| 360 | | if (overlayNode.valid()) |
| 361 | | { |
| 362 | | overlayNode->setOverlaySubgraph(mt); |
| 363 | | } |
| 364 | | |
| 365 | | tm = new osgGA::NodeTrackerManipulator; |
| 366 | | tm->setTrackerMode(trackerMode); |
| 367 | | tm->setRotationMode(rotationMode); |
| 368 | | tm->setTrackNode(scaler); |
| | 335 | csn->addChild(overlayNode); |
| | 336 | |
| | 337 | viewer.setSceneData(csn); |
| 372 | | std::cout<<"Failed to read cessna.osg"<<std::endl; |
| 373 | | } |
| 374 | | |
| 375 | | } |
| 376 | | |
| | 341 | osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode(technique); |
| | 342 | overlayNode->getOrCreateStateSet()->setTextureAttribute(1, new osg::TexEnv(osg::TexEnv::DECAL)); |
| | 343 | overlayNode->setOverlaySubgraph(shapefile.get()); |
| | 344 | overlayNode->setOverlayTextureSizeHint(1024); |
| | 345 | overlayNode->addChild(root.get()); |
| | 346 | |
| | 347 | viewer.setSceneData(overlayNode); |
| | 348 | } |
| | 349 | } |
| | 350 | else |
| | 351 | { |
| | 352 | |
| | 353 | |
| | 354 | // add a viewport to the viewer and attach the scene graph. |
| | 355 | viewer.setSceneData(root.get()); |
| | 356 | |
| | 357 | osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root.get()); |
| | 358 | if (csn) |
| | 359 | { |
| | 360 | |
| | 361 | osg::ref_ptr<osgSim::OverlayNode> overlayNode; |
| | 362 | if (useOverlay) |
| | 363 | { |
| | 364 | overlayNode = new osgSim::OverlayNode(technique); |
| | 365 | |
| | 366 | // insert the OverlayNode between the coordinate system node and its children. |
| | 367 | for(unsigned int i=0; i<csn->getNumChildren(); ++i) |
| | 368 | { |
| | 369 | overlayNode->addChild( csn->getChild(i) ); |
| | 370 | } |
| | 371 | |
| | 372 | csn->removeChildren(0, csn->getNumChildren()); |
| | 373 | csn->addChild(overlayNode.get()); |
| | 374 | |
| | 375 | // tell the overlay node to continously update its overlay texture |
| | 376 | // as we know we'll be tracking a moving target. |
| | 377 | overlayNode->setContinuousUpdate(true); |
| | 378 | } |
| | 379 | |
| | 380 | |
| | 381 | osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); |
| | 382 | if (cessna) |
| | 383 | { |
| | 384 | double s = 200000.0 / cessna->getBound().radius(); |
| | 385 | |
| | 386 | osg::MatrixTransform* scaler = new osg::MatrixTransform; |
| | 387 | scaler->addChild(cessna); |
| | 388 | scaler->setMatrix(osg::Matrixd::scale(s,s,s)*osg::Matrixd::rotate(rotation)); |
| | 389 | scaler->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL,osg::StateAttribute::ON); |
| | 390 | |
| | 391 | if (false) |
| | 392 | { |
| | 393 | osgSim::SphereSegment* ss = new osgSim::SphereSegment( |
| | 394 | osg::Vec3(0.0f,0.0f,0.0f), // center |
| | 395 | 19.9f, // radius |
| | 396 | osg::DegreesToRadians(135.0f), |
| | 397 | osg::DegreesToRadians(240.0f), |
| | 398 | osg::DegreesToRadians(-10.0f), |
| | 399 | osg::DegreesToRadians(30.0f), |
| | 400 | 60); |
| | 401 | |
| | 402 | scaler->addChild(ss); |
| | 403 | } |
| | 404 | |
| | 405 | osg::MatrixTransform* mt = new osg::MatrixTransform; |
| | 406 | mt->addChild(scaler); |
| | 407 | |
| | 408 | |
| | 409 | if (!nc) nc = new ModelPositionCallback(speed); |
| | 410 | |
| | 411 | mt->setUpdateCallback(nc); |
| | 412 | |
| | 413 | csn->addChild(mt); |
| | 414 | |
| | 415 | // if we are using an overaly node, use the cessna subgraph as the overlay subgraph |
| | 416 | if (overlayNode.valid()) |
| | 417 | { |
| | 418 | overlayNode->setOverlaySubgraph(mt); |
| | 419 | } |
| | 420 | |
| | 421 | tm = new osgGA::NodeTrackerManipulator; |
| | 422 | tm->setTrackerMode(trackerMode); |
| | 423 | tm->setRotationMode(rotationMode); |
| | 424 | tm->setTrackNode(scaler); |
| | 425 | } |
| | 426 | else |
| | 427 | { |
| | 428 | std::cout<<"Failed to read cessna.osg"<<std::endl; |
| | 429 | } |
| | 430 | |
| | 431 | } |
| | 432 | } |