Show
Ignore:
Timestamp:
11/18/04 16:01:41 (9 years ago)
Author:
robert
Message:

Increased accuracy of animation path, moved main to end.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgplanets/osgplanets.cpp

    r3665 r3666  
    2424#include <osgDB/Registry> 
    2525#include <osgDB/ReadFile> 
     26#include <osgDB/WriteFile> 
     27 
    2628 
    2729#include <osgGA/NodeTrackerManipulator> 
     
    129131    animationPath->setLoopMode(osg::AnimationPath::LOOP); 
    130132     
    131     int numSamples = 40; 
     133    int numSamples = 1000; 
    132134    float yaw = 0.0f; 
    133135    float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f); 
     
    263265    NodeList _foundNodes; 
    264266}; 
    265  
    266 int main( int argc, char **argv ) 
    267 { 
    268     // use an ArgumentParser object to manage the program arguments. 
    269     osg::ArgumentParser arguments(&argc,argv); 
    270  
    271     // set up the usage document, in case we need to print out how to use this program. 
    272     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of osg::AnimationPath and UpdateCallbacks for adding animation to your scenes."); 
    273     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    274     arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    275  
    276     // initialize the viewer. 
    277     osgProducer::Viewer viewer(arguments); 
    278  
    279     // set up the value with sensible default event handlers. 
    280     viewer.setUpViewer(osgProducer::Viewer::ESCAPE_SETS_DONE | osgProducer::Viewer::VIEWER_MANIPULATOR | osgProducer::Viewer::STATE_MANIPULATOR); 
    281  
    282     // get details on keyboard and mouse bindings used by the viewer. 
    283     viewer.getUsage(*arguments.getApplicationUsage()); 
    284  
    285     SolarSystem solarSystem; 
    286  
    287     while (arguments.read("--radiusSpace",solarSystem._radiusSpace)) { } 
    288     while (arguments.read("--radiusSun",solarSystem._radiusSun)) { } 
    289     while (arguments.read("--radiusEarth",solarSystem._radiusEarth)) { } 
    290     while (arguments.read("--radiusMoon",solarSystem._radiusMoon)) { } 
    291      
    292     while (arguments.read("--RorbitEarth",solarSystem._RorbitEarth)) { } 
    293     while (arguments.read("--RorbitMoon",solarSystem._RorbitMoon)) { } 
    294      
    295     while (arguments.read("--rotateSpeedEarthAndMoon",solarSystem._rotateSpeedEarthAndMoon)) { } 
    296     while (arguments.read("--rotateSpeedEarth",solarSystem._rotateSpeedEarth)) { } 
    297     while (arguments.read("--rotateSpeedMoon",solarSystem._rotateSpeedMoon)) { } 
    298     while (arguments.read("--tiltEarth",solarSystem._tiltEarth)) { } 
    299      
    300     while (arguments.read("--mapSpace",solarSystem._mapSpace)) { } 
    301     while (arguments.read("--mapEarth",solarSystem._mapEarth)) { } 
    302     while (arguments.read("--mapEarthNight",solarSystem._mapEarthNight)) { } 
    303     while (arguments.read("--mapMoon",solarSystem._mapMoon)) { } 
    304      
    305      
    306      
    307     osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; 
    308     std::string mode; 
    309     while (arguments.read("--tracker-mode",mode)) 
    310     { 
    311         if (mode=="NODE_CENTER_AND_ROTATION") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; 
    312         else if (mode=="NODE_CENTER_AND_AZIM") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_AZIM; 
    313         else if (mode=="NODE_CENTER") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER; 
    314         else 
    315         { 
    316             std::cout<<"Unrecognized --tracker-mode option "<<mode<<", valid options are:"<<std::endl; 
    317             std::cout<<"    NODE_CENTER_AND_ROTATION"<<std::endl; 
    318             std::cout<<"    NODE_CENTER_AND_AZIM"<<std::endl; 
    319             std::cout<<"    NODE_CENTER"<<std::endl; 
    320             return 1; 
    321         } 
    322     } 
    323      
    324      
    325     osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; 
    326     while (arguments.read("--rotation-mode",mode)) 
    327     { 
    328         if (mode=="TRACKBALL") rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; 
    329         else if (mode=="ELEVATION_AZIM") rotationMode = osgGA::NodeTrackerManipulator::ELEVATION_AZIM; 
    330         else 
    331         { 
    332             std::cout<<"Unrecognized --rotation-mode option "<<mode<<", valid options are:"<<std::endl; 
    333             std::cout<<"    TRACKBALL"<<std::endl; 
    334             std::cout<<"    ELEVATION_AZIM"<<std::endl; 
    335             return 1; 
    336         } 
    337     } 
    338      
    339  
    340     solarSystem.printParameters(); 
    341  
    342     // if user request help write it out to cout. 
    343     if (arguments.read("-h") || arguments.read("--help")) 
    344     { 
    345         std::cout << "setup the following arguments: " << std::endl; 
    346         std::cout << "--radiusSpace: double" << std::endl; 
    347         std::cout << "--radiusSun: double" << std::endl; 
    348         std::cout << "--radiusEarth: double" << std::endl; 
    349         std::cout << "--radiusMoon: double" << std::endl; 
    350          
    351         std::cout << "--RorbitEarth: double" << std::endl; 
    352         std::cout << "--RorbitMoon: double" << std::endl; 
    353          
    354         std::cout << "--rotateSpeedEarthAndMoon: double" << std::endl; 
    355         std::cout << "--rotateSpeedEarth: double" << std::endl; 
    356         std::cout << "--rotateSpeedMoon: double" << std::endl; 
    357         std::cout << "--tiltEarth: double" << std::endl; 
    358          
    359         std::cout << "--mapSpace: string" << std::endl; 
    360         std::cout << "--mapEarth: string" << std::endl; 
    361         std::cout << "--mapEarthNight: string" << std::endl; 
    362         std::cout << "--mapMoon: string" << std::endl; 
    363                          
    364         return 1; 
    365     } 
    366  
    367     // any option left unread are converted into errors to write out later. 
    368     arguments.reportRemainingOptionsAsUnrecognized(); 
    369  
    370     // report any errors if they have occured when parsing the program aguments. 
    371     if (arguments.errors()) 
    372     { 
    373         arguments.writeErrorMessages(std::cout); 
    374         return 1; 
    375     } 
    376      
    377      
    378     osg::Group* root = new osg::Group; 
    379  
    380     osg::Group* sunLight = solarSystem.createSunLight(); 
    381     root->addChild(sunLight); 
    382  
    383     // create the sun 
    384     osg::Node* solarSun = solarSystem.createPlanet( solarSystem._radiusSun, "Sun", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapSun ); 
    385     osg::StateSet* sunStateSet = solarSun->getOrCreateStateSet(); 
    386     osg::Material* material = new osg::Material; 
    387     material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 1.0f, 0.0f, 0.0f ) ); 
    388     sunStateSet->setAttributeAndModes( material, osg::StateAttribute::ON ); 
    389  
    390     osg::Billboard* sunBillboard = new osg::Billboard(); 
    391     sunBillboard->setMode(osg::Billboard::POINT_ROT_EYE); 
    392     sunBillboard->addDrawable( 
    393         createSquare(osg::Vec3(-5.0f,0.0f,-5.0f),osg::Vec3(10.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,10.0f),createBillboardImage( osg::Vec4( 1.0, 1.0, 0, 1.0f), 64, 1.0) ), 
    394         osg::Vec3(0.0f,0.0f,0.0f)); 
    395          
    396     sunLight->addChild( sunBillboard ); 
    397  
    398     // stick sun right under root, no transformations for the sun 
    399     sunLight->addChild( solarSun ); 
    400  
    401     // create light source in the sun 
    402  
    403 /* 
    404 ********************************************* 
    405 **  earthMoonGroup and Transformations  
    406 ********************************************* 
    407 */ 
    408     // create earth and moon 
    409     osg::Node* earth = solarSystem.createPlanet( solarSystem._radiusEarth, "Earth", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapEarth, solarSystem._mapEarthNight ); 
    410     osg::Node* moon = solarSystem.createPlanet( solarSystem._radiusMoon, "Moon", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapMoon ); 
    411  
    412     // create transformations for the earthMoonGroup 
    413     osg::MatrixTransform* aroundSunRotationEarthMoonGroup = solarSystem.createRotation( solarSystem._RorbitEarth, solarSystem._rotateSpeedEarthAndMoon ); 
    414     osg::MatrixTransform* earthMoonGroupPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitEarth, solarSystem._tiltEarth ); 
    415  
    416  
    417     //Group with earth and moon under it 
    418     osg::Group* earthMoonGroup = new osg::Group; 
    419      
    420  
    421     //transformation to rotate the earth around itself 
    422     osg::MatrixTransform* earthAroundItselfRotation = solarSystem.createRotation ( 0.0, solarSystem._rotateSpeedEarth ); 
    423  
    424     //transformations for the moon 
    425     osg::MatrixTransform* moonAroundEarthRotation = solarSystem.createRotation( solarSystem._RorbitMoon, solarSystem._rotateSpeedMoon ); 
    426     osg::MatrixTransform* moonTranslation = solarSystem.createTranslationAndTilt( solarSystem._RorbitMoon, 0.0f ); 
    427  
    428  
    429     moonTranslation->addChild( moon ); 
    430     moonAroundEarthRotation->addChild( moonTranslation ); 
    431     earthMoonGroup->addChild( moonAroundEarthRotation ); 
    432  
    433     earthAroundItselfRotation->addChild( earth ); 
    434  
    435     earthMoonGroup->addChild( earthAroundItselfRotation ); 
    436  
    437     earthMoonGroupPosition->addChild( earthMoonGroup ); 
    438  
    439     aroundSunRotationEarthMoonGroup->addChild( earthMoonGroupPosition ); 
    440  
    441     sunLight->addChild( aroundSunRotationEarthMoonGroup ); 
    442 /* 
    443 ********************************************* 
    444 **  end earthMoonGroup and Transformations  
    445 ********************************************* 
    446 */ 
    447  
    448 /* 
    449 ********************************************* 
    450 **  Mercury and Transformations  
    451 ********************************************* 
    452 */ 
    453     osg::Node* mercury = solarSystem.createPlanet( solarSystem._radiusMercury, "Mercury", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMercury, "" ); 
    454      
    455     osg::MatrixTransform* aroundSunRotationMercury = solarSystem.createRotation( solarSystem._RorbitMercury, solarSystem._rotateSpeedMercury ); 
    456     osg::MatrixTransform* mercuryPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMercury, 0.0f ); 
    457      
    458     mercuryPosition->addChild( mercury ); 
    459     aroundSunRotationMercury->addChild( mercuryPosition ); 
    460      
    461     sunLight->addChild( aroundSunRotationMercury ); 
    462 /* 
    463 ********************************************* 
    464 **  end Mercury and Transformations  
    465 ********************************************* 
    466 */ 
    467  
    468 /* 
    469 ********************************************* 
    470 **  Venus and Transformations  
    471 ********************************************* 
    472 */ 
    473     osg::Node* venus = solarSystem.createPlanet( solarSystem._radiusVenus, "Venus", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapVenus, "" ); 
    474      
    475     osg::MatrixTransform* aroundSunRotationVenus = solarSystem.createRotation( solarSystem._RorbitVenus, solarSystem._rotateSpeedVenus ); 
    476     osg::MatrixTransform* venusPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitVenus, 0.0f ); 
    477      
    478     venusPosition->addChild( venus ); 
    479     aroundSunRotationVenus->addChild( venusPosition ); 
    480      
    481     sunLight->addChild( aroundSunRotationVenus ); 
    482 /* 
    483 ********************************************* 
    484 **  end Venus and Transformations  
    485 ********************************************* 
    486 */ 
    487  
    488 /* 
    489 ********************************************* 
    490 **  Mars and Transformations  
    491 ********************************************* 
    492 */ 
    493     osg::Node* mars = solarSystem.createPlanet( solarSystem._radiusMars, "Mars", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMars, "" ); 
    494      
    495     osg::MatrixTransform* aroundSunRotationMars = solarSystem.createRotation( solarSystem._RorbitMars, solarSystem._rotateSpeedMars ); 
    496     osg::MatrixTransform* marsPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMars, 0.0f ); 
    497      
    498     marsPosition->addChild( mars ); 
    499     aroundSunRotationMars->addChild( marsPosition ); 
    500      
    501     sunLight->addChild( aroundSunRotationMars ); 
    502 /* 
    503 ********************************************* 
    504 **  end Mars and Transformations  
    505 ********************************************* 
    506 */ 
    507  
    508 /* 
    509 ********************************************* 
    510 **  Jupiter and Transformations  
    511 ********************************************* 
    512 */ 
    513     osg::Node* jupiter = solarSystem.createPlanet( solarSystem._radiusJupiter, "Jupiter", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapJupiter, "" ); 
    514      
    515     osg::MatrixTransform* aroundSunRotationJupiter = solarSystem.createRotation( solarSystem._RorbitJupiter, solarSystem._rotateSpeedJupiter ); 
    516     osg::MatrixTransform* jupiterPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitJupiter, 0.0f ); 
    517      
    518     jupiterPosition->addChild( jupiter ); 
    519     aroundSunRotationJupiter->addChild( jupiterPosition ); 
    520      
    521     sunLight->addChild( aroundSunRotationJupiter ); 
    522 /* 
    523 ********************************************* 
    524 **  end Jupiter and Transformations  
    525 ********************************************* 
    526 */ 
    527  
    528 /* 
    529     // add space, but don't light it, as its not illuminated by our sun 
    530     osg::Node* space = solarSystem.createSpace( "Space", solarSystem._mapSpace ); 
    531     space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 
    532     root->addChild( space ); 
    533 */     
    534       
    535     // run optimization over the scene graph 
    536     osgUtil::Optimizer optimzer; 
    537     optimzer.optimize( root ); 
    538       
    539     // set the scene to render 
    540     viewer.setSceneData( root ); 
    541  
    542  
    543     // set up tracker manipulators, once for each astral body 
    544      
    545     { 
    546         FindNamedNodeVisitor fnnv("Moon"); 
    547         root->accept(fnnv); 
    548  
    549         if (!fnnv._foundNodes.empty()) 
    550         { 
    551             // set up the node tracker. 
    552             osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 
    553             tm->setTrackerMode( trackerMode ); 
    554             tm->setRotationMode( rotationMode ); 
    555             tm->setTrackNode( fnnv._foundNodes.front().get() ); 
    556  
    557             unsigned int num = viewer.addCameraManipulator( tm ); 
    558             viewer.selectCameraManipulator( num ); 
    559         } 
    560     }     
    561  
    562     { 
    563         FindNamedNodeVisitor fnnv("Earth"); 
    564         root->accept(fnnv); 
    565  
    566         if (!fnnv._foundNodes.empty()) 
    567         { 
    568             // set up the node tracker. 
    569             osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 
    570             tm->setTrackerMode( trackerMode ); 
    571             tm->setRotationMode( rotationMode ); 
    572             tm->setTrackNode( fnnv._foundNodes.front().get() ); 
    573  
    574             unsigned int num = viewer.addCameraManipulator( tm ); 
    575             viewer.selectCameraManipulator( num ); 
    576         } 
    577     }     
    578      
    579     { 
    580         FindNamedNodeVisitor fnnv("Sun"); 
    581         root->accept(fnnv); 
    582  
    583         if (!fnnv._foundNodes.empty()) 
    584         { 
    585             // set up the node tracker. 
    586             osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 
    587             tm->setTrackerMode( trackerMode ); 
    588             tm->setRotationMode( rotationMode ); 
    589             tm->setTrackNode( fnnv._foundNodes.front().get() ); 
    590  
    591             unsigned int num = viewer.addCameraManipulator( tm ); 
    592             viewer.selectCameraManipulator( num ); 
    593         } 
    594     }     
    595      
    596     // create the windows and run the threads. 
    597     viewer.realize(); 
    598      
    599     viewer.setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 
    600  
    601     while( !viewer.done() ) 
    602     { 
    603         // wait for all cull and draw threads to complete. 
    604         viewer.sync(); 
    605  
    606         // update the scene by traversing it with the the update visitor which will 
    607         // call all node update callbacks and animations. 
    608         viewer.update(); 
    609           
    610         // fire off the cull and draw traversals of the scene. 
    611         viewer.frame(); 
    612          
    613     } 
    614      
    615      
    616     // wait for all cull and draw threads to complete before exit. 
    617     viewer.sync(); 
    618  
    619     return 0; 
    620 }// end main 
    621267 
    622268 
     
    844490    std::cout << "mapMoon(" << _radiusSpace << ")" << std::endl; 
    845491} 
     492 
     493 
     494int main( int argc, char **argv ) 
     495{ 
     496    // use an ArgumentParser object to manage the program arguments. 
     497    osg::ArgumentParser arguments(&argc,argv); 
     498 
     499    // set up the usage document, in case we need to print out how to use this program. 
     500    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of osg::AnimationPath and UpdateCallbacks for adding animation to your scenes."); 
     501    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
     502    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
     503    arguments.getApplicationUsage()->addCommandLineOption("-o <filename>","Write created model to file"); 
     504 
     505    // initialize the viewer. 
     506    osgProducer::Viewer viewer(arguments); 
     507 
     508    // set up the value with sensible default event handlers. 
     509    viewer.setUpViewer(osgProducer::Viewer::ESCAPE_SETS_DONE | osgProducer::Viewer::VIEWER_MANIPULATOR | osgProducer::Viewer::STATE_MANIPULATOR); 
     510 
     511    // get details on keyboard and mouse bindings used by the viewer. 
     512    viewer.getUsage(*arguments.getApplicationUsage()); 
     513 
     514    SolarSystem solarSystem; 
     515 
     516    while (arguments.read("--radiusSpace",solarSystem._radiusSpace)) { } 
     517    while (arguments.read("--radiusSun",solarSystem._radiusSun)) { } 
     518    while (arguments.read("--radiusEarth",solarSystem._radiusEarth)) { } 
     519    while (arguments.read("--radiusMoon",solarSystem._radiusMoon)) { } 
     520     
     521    while (arguments.read("--RorbitEarth",solarSystem._RorbitEarth)) { } 
     522    while (arguments.read("--RorbitMoon",solarSystem._RorbitMoon)) { } 
     523     
     524    while (arguments.read("--rotateSpeedEarthAndMoon",solarSystem._rotateSpeedEarthAndMoon)) { } 
     525    while (arguments.read("--rotateSpeedEarth",solarSystem._rotateSpeedEarth)) { } 
     526    while (arguments.read("--rotateSpeedMoon",solarSystem._rotateSpeedMoon)) { } 
     527    while (arguments.read("--tiltEarth",solarSystem._tiltEarth)) { } 
     528     
     529    while (arguments.read("--mapSpace",solarSystem._mapSpace)) { } 
     530    while (arguments.read("--mapEarth",solarSystem._mapEarth)) { } 
     531    while (arguments.read("--mapEarthNight",solarSystem._mapEarthNight)) { } 
     532    while (arguments.read("--mapMoon",solarSystem._mapMoon)) { } 
     533     
     534    std::string writeFileName; 
     535    while (arguments.read("-o",writeFileName)) { } 
     536     
     537     
     538    osgGA::NodeTrackerManipulator::TrackerMode trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; 
     539    std::string mode; 
     540    while (arguments.read("--tracker-mode",mode)) 
     541    { 
     542        if (mode=="NODE_CENTER_AND_ROTATION") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION; 
     543        else if (mode=="NODE_CENTER_AND_AZIM") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER_AND_AZIM; 
     544        else if (mode=="NODE_CENTER") trackerMode = osgGA::NodeTrackerManipulator::NODE_CENTER; 
     545        else 
     546        { 
     547            std::cout<<"Unrecognized --tracker-mode option "<<mode<<", valid options are:"<<std::endl; 
     548            std::cout<<"    NODE_CENTER_AND_ROTATION"<<std::endl; 
     549            std::cout<<"    NODE_CENTER_AND_AZIM"<<std::endl; 
     550            std::cout<<"    NODE_CENTER"<<std::endl; 
     551            return 1; 
     552        } 
     553    } 
     554     
     555     
     556    osgGA::NodeTrackerManipulator::RotationMode rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; 
     557    while (arguments.read("--rotation-mode",mode)) 
     558    { 
     559        if (mode=="TRACKBALL") rotationMode = osgGA::NodeTrackerManipulator::TRACKBALL; 
     560        else if (mode=="ELEVATION_AZIM") rotationMode = osgGA::NodeTrackerManipulator::ELEVATION_AZIM; 
     561        else 
     562        { 
     563            std::cout<<"Unrecognized --rotation-mode option "<<mode<<", valid options are:"<<std::endl; 
     564            std::cout<<"    TRACKBALL"<<std::endl; 
     565            std::cout<<"    ELEVATION_AZIM"<<std::endl; 
     566            return 1; 
     567        } 
     568    } 
     569     
     570 
     571    solarSystem.printParameters(); 
     572 
     573    // if user request help write it out to cout. 
     574    if (arguments.read("-h") || arguments.read("--help")) 
     575    { 
     576        std::cout << "setup the following arguments: " << std::endl; 
     577        std::cout << "--radiusSpace: double" << std::endl; 
     578        std::cout << "--radiusSun: double" << std::endl; 
     579        std::cout << "--radiusEarth: double" << std::endl; 
     580        std::cout << "--radiusMoon: double" << std::endl; 
     581         
     582        std::cout << "--RorbitEarth: double" << std::endl; 
     583        std::cout << "--RorbitMoon: double" << std::endl; 
     584         
     585        std::cout << "--rotateSpeedEarthAndMoon: double" << std::endl; 
     586        std::cout << "--rotateSpeedEarth: double" << std::endl; 
     587        std::cout << "--rotateSpeedMoon: double" << std::endl; 
     588        std::cout << "--tiltEarth: double" << std::endl; 
     589         
     590        std::cout << "--mapSpace: string" << std::endl; 
     591        std::cout << "--mapEarth: string" << std::endl; 
     592        std::cout << "--mapEarthNight: string" << std::endl; 
     593        std::cout << "--mapMoon: string" << std::endl; 
     594                         
     595        return 1; 
     596    } 
     597 
     598    // any option left unread are converted into errors to write out later. 
     599    arguments.reportRemainingOptionsAsUnrecognized(); 
     600 
     601    // report any errors if they have occured when parsing the program aguments. 
     602    if (arguments.errors()) 
     603    { 
     604        arguments.writeErrorMessages(std::cout); 
     605        return 1; 
     606    } 
     607     
     608     
     609    osg::Group* root = new osg::Group; 
     610 
     611    osg::Group* sunLight = solarSystem.createSunLight(); 
     612    root->addChild(sunLight); 
     613 
     614    // create the sun 
     615    osg::Node* solarSun = solarSystem.createPlanet( solarSystem._radiusSun, "Sun", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapSun ); 
     616    osg::StateSet* sunStateSet = solarSun->getOrCreateStateSet(); 
     617    osg::Material* material = new osg::Material; 
     618    material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 1.0f, 0.0f, 0.0f ) ); 
     619    sunStateSet->setAttributeAndModes( material, osg::StateAttribute::ON ); 
     620 
     621    osg::Billboard* sunBillboard = new osg::Billboard(); 
     622    sunBillboard->setMode(osg::Billboard::POINT_ROT_EYE); 
     623    sunBillboard->addDrawable( 
     624        createSquare(osg::Vec3(-5.0f,0.0f,-5.0f),osg::Vec3(10.0f,0.0f,0.0f),osg::Vec3(0.0f,0.0f,10.0f),createBillboardImage( osg::Vec4( 1.0, 1.0, 0, 1.0f), 64, 1.0) ), 
     625        osg::Vec3(0.0f,0.0f,0.0f)); 
     626         
     627    sunLight->addChild( sunBillboard ); 
     628 
     629    // stick sun right under root, no transformations for the sun 
     630    sunLight->addChild( solarSun ); 
     631 
     632    // create light source in the sun 
     633 
     634/* 
     635********************************************* 
     636**  earthMoonGroup and Transformations  
     637********************************************* 
     638*/ 
     639    // create earth and moon 
     640    osg::Node* earth = solarSystem.createPlanet( solarSystem._radiusEarth, "Earth", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapEarth, solarSystem._mapEarthNight ); 
     641    osg::Node* moon = solarSystem.createPlanet( solarSystem._radiusMoon, "Moon", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), solarSystem._mapMoon ); 
     642 
     643    // create transformations for the earthMoonGroup 
     644    osg::MatrixTransform* aroundSunRotationEarthMoonGroup = solarSystem.createRotation( solarSystem._RorbitEarth, solarSystem._rotateSpeedEarthAndMoon ); 
     645    osg::MatrixTransform* earthMoonGroupPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitEarth, solarSystem._tiltEarth ); 
     646 
     647 
     648    //Group with earth and moon under it 
     649    osg::Group* earthMoonGroup = new osg::Group; 
     650     
     651 
     652    //transformation to rotate the earth around itself 
     653    osg::MatrixTransform* earthAroundItselfRotation = solarSystem.createRotation ( 0.0, solarSystem._rotateSpeedEarth ); 
     654 
     655    //transformations for the moon 
     656    osg::MatrixTransform* moonAroundEarthRotation = solarSystem.createRotation( solarSystem._RorbitMoon, solarSystem._rotateSpeedMoon ); 
     657    osg::MatrixTransform* moonTranslation = solarSystem.createTranslationAndTilt( solarSystem._RorbitMoon, 0.0f ); 
     658 
     659 
     660    moonTranslation->addChild( moon ); 
     661    moonAroundEarthRotation->addChild( moonTranslation ); 
     662    earthMoonGroup->addChild( moonAroundEarthRotation ); 
     663 
     664    earthAroundItselfRotation->addChild( earth ); 
     665 
     666    earthMoonGroup->addChild( earthAroundItselfRotation ); 
     667 
     668    earthMoonGroupPosition->addChild( earthMoonGroup ); 
     669 
     670    aroundSunRotationEarthMoonGroup->addChild( earthMoonGroupPosition ); 
     671 
     672    sunLight->addChild( aroundSunRotationEarthMoonGroup ); 
     673/* 
     674********************************************* 
     675**  end earthMoonGroup and Transformations  
     676********************************************* 
     677*/ 
     678 
     679/* 
     680********************************************* 
     681**  Mercury and Transformations  
     682********************************************* 
     683*/ 
     684    osg::Node* mercury = solarSystem.createPlanet( solarSystem._radiusMercury, "Mercury", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMercury, "" ); 
     685     
     686    osg::MatrixTransform* aroundSunRotationMercury = solarSystem.createRotation( solarSystem._RorbitMercury, solarSystem._rotateSpeedMercury ); 
     687    osg::MatrixTransform* mercuryPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMercury, 0.0f ); 
     688     
     689    mercuryPosition->addChild( mercury ); 
     690    aroundSunRotationMercury->addChild( mercuryPosition ); 
     691     
     692    sunLight->addChild( aroundSunRotationMercury ); 
     693/* 
     694********************************************* 
     695**  end Mercury and Transformations  
     696********************************************* 
     697*/ 
     698 
     699/* 
     700********************************************* 
     701**  Venus and Transformations  
     702********************************************* 
     703*/ 
     704    osg::Node* venus = solarSystem.createPlanet( solarSystem._radiusVenus, "Venus", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapVenus, "" ); 
     705     
     706    osg::MatrixTransform* aroundSunRotationVenus = solarSystem.createRotation( solarSystem._RorbitVenus, solarSystem._rotateSpeedVenus ); 
     707    osg::MatrixTransform* venusPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitVenus, 0.0f ); 
     708     
     709    venusPosition->addChild( venus ); 
     710    aroundSunRotationVenus->addChild( venusPosition ); 
     711     
     712    sunLight->addChild( aroundSunRotationVenus ); 
     713/* 
     714********************************************* 
     715**  end Venus and Transformations  
     716********************************************* 
     717*/ 
     718 
     719/* 
     720********************************************* 
     721**  Mars and Transformations  
     722********************************************* 
     723*/ 
     724    osg::Node* mars = solarSystem.createPlanet( solarSystem._radiusMars, "Mars", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapMars, "" ); 
     725     
     726    osg::MatrixTransform* aroundSunRotationMars = solarSystem.createRotation( solarSystem._RorbitMars, solarSystem._rotateSpeedMars ); 
     727    osg::MatrixTransform* marsPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitMars, 0.0f ); 
     728     
     729    marsPosition->addChild( mars ); 
     730    aroundSunRotationMars->addChild( marsPosition ); 
     731     
     732    sunLight->addChild( aroundSunRotationMars ); 
     733/* 
     734********************************************* 
     735**  end Mars and Transformations  
     736********************************************* 
     737*/ 
     738 
     739/* 
     740********************************************* 
     741**  Jupiter and Transformations  
     742********************************************* 
     743*/ 
     744    osg::Node* jupiter = solarSystem.createPlanet( solarSystem._radiusJupiter, "Jupiter", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f ), solarSystem._mapJupiter, "" ); 
     745     
     746    osg::MatrixTransform* aroundSunRotationJupiter = solarSystem.createRotation( solarSystem._RorbitJupiter, solarSystem._rotateSpeedJupiter ); 
     747    osg::MatrixTransform* jupiterPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitJupiter, 0.0f ); 
     748     
     749    jupiterPosition->addChild( jupiter ); 
     750    aroundSunRotationJupiter->addChild( jupiterPosition ); 
     751     
     752    sunLight->addChild( aroundSunRotationJupiter ); 
     753/* 
     754********************************************* 
     755**  end Jupiter and Transformations  
     756********************************************* 
     757*/ 
     758 
     759/* 
     760    // add space, but don't light it, as its not illuminated by our sun 
     761    osg::Node* space = solarSystem.createSpace( "Space", solarSystem._mapSpace ); 
     762    space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 
     763    root->addChild( space ); 
     764*/     
     765      
     766    if (!writeFileName.empty()) 
     767    { 
     768        osgDB::writeNodeFile(*root, writeFileName); 
     769        std::cout<<"Written solar system to \""<<writeFileName<<"\""<<std::endl; 
     770    } 
     771 
     772 
     773    // run optimization over the scene graph 
     774    osgUtil::Optimizer optimzer; 
     775    optimzer.optimize( root ); 
     776      
     777    // set the scene to render 
     778    viewer.setSceneData( root ); 
     779 
     780 
     781    // set up tracker manipulators, once for each astral body 
     782     
     783    { 
     784        FindNamedNodeVisitor fnnv("Moon"); 
     785        root->accept(fnnv); 
     786 
     787        if (!fnnv._foundNodes.empty()) 
     788        { 
     789            // set up the node tracker. 
     790            osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 
     791            tm->setTrackerMode( trackerMode ); 
     792            tm->setRotationMode( rotationMode ); 
     793            tm->setTrackNode( fnnv._foundNodes.front().get() ); 
     794 
     795            unsigned int num = viewer.addCameraManipulator( tm ); 
     796            viewer.selectCameraManipulator( num ); 
     797        } 
     798    }     
     799 
     800    { 
     801        FindNamedNodeVisitor fnnv("Earth"); 
     802        root->accept(fnnv); 
     803 
     804        if (!fnnv._foundNodes.empty()) 
     805        { 
     806            // set up the node tracker. 
     807            osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 
     808            tm->setTrackerMode( trackerMode ); 
     809            tm->setRotationMode( rotationMode ); 
     810            tm->setTrackNode( fnnv._foundNodes.front().get() ); 
     811 
     812            unsigned int num = viewer.addCameraManipulator( tm ); 
     813            viewer.selectCameraManipulator( num ); 
     814        } 
     815    }     
     816     
     817    { 
     818        FindNamedNodeVisitor fnnv("Sun"); 
     819        root->accept(fnnv); 
     820 
     821        if (!fnnv._foundNodes.empty()) 
     822        { 
     823            // set up the node tracker. 
     824            osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; 
     825            tm->setTrackerMode( trackerMode ); 
     826            tm->setRotationMode( rotationMode ); 
     827            tm->setTrackNode( fnnv._foundNodes.front().get() ); 
     828 
     829            unsigned int num = viewer.addCameraManipulator( tm ); 
     830            viewer.selectCameraManipulator( num ); 
     831        } 
     832    }     
     833     
     834    // create the windows and run the threads. 
     835    viewer.realize(); 
     836     
     837    viewer.setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 
     838 
     839    while( !viewer.done() ) 
     840    { 
     841        // wait for all cull and draw threads to complete. 
     842        viewer.sync(); 
     843 
     844        // update the scene by traversing it with the the update visitor which will 
     845        // call all node update callbacks and animations. 
     846        viewer.update(); 
     847          
     848        // fire off the cull and draw traversals of the scene. 
     849        viewer.frame(); 
     850         
     851    } 
     852     
     853     
     854    // wait for all cull and draw threads to complete before exit. 
     855    viewer.sync(); 
     856 
     857    return 0; 
     858}// end main 
     859