Show
Ignore:
Timestamp:
12/26/06 18:35:45 (7 years ago)
Author:
robert
Message:

Ported osgcatch to use osgViewer

Files:
1 modified

Legend:

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

    r5636 r5847  
    1212*/ 
    1313 
    14 #include <osgProducer/Viewer> 
    1514#include <osgDB/ReadFile> 
    1615#include <osgDB/WriteFile> 
     
    2827#include <osg/TexMat> 
    2928#include <osg/Texture2D> 
     29#include <osg/Timer> 
    3030#include <osg/io_utils> 
     31 
     32#include <osgGA/GUIEventHandler> 
    3133 
    3234#include <osgParticle/ExplosionEffect> 
     
    786788     
    787789    _currentScore = 0; 
     790     
     791    setFOVY(osg::DegreesToRadians(60.0)); 
    788792 
    789793} 
     
    13491353 
    13501354 
     1355 
     1356#if 0 
     1357 
     1358#include <osgProducer/Viewer> 
     1359 
    13511360class CompileStateCallback : public osgProducer::OsgCameraGroup::RealizeCallback 
    13521361{ 
     
    14891498    return 0; 
    14901499} 
    1491  
     1500#else 
     1501 
     1502#include <osgViewer/Viewer> 
     1503#include <iostream> 
     1504 
     1505int main( int argc, char **argv ) 
     1506{ 
     1507 
     1508    // use an ArgumentParser object to manage the program arguments. 
     1509    osg::ArgumentParser arguments(&argc,argv); 
     1510     
     1511    // set up the usage document, in case we need to print out how to use this program. 
     1512    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use node masks to create stereo images."); 
     1513    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye"); 
     1514    arguments.getApplicationUsage()->addCommandLineOption("-d <float>","Time delay in sceonds between the display of successive image pairs when in auto advance mode."); 
     1515    arguments.getApplicationUsage()->addCommandLineOption("-a","Enter auto advance of image pairs on start up."); 
     1516    arguments.getApplicationUsage()->addCommandLineOption("-x <float>","Horizontal offset of left and right images."); 
     1517    arguments.getApplicationUsage()->addCommandLineOption("-y <float>","Vertical offset of left and right images."); 
     1518    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
     1519     
     1520 
     1521    // construct the viewer. 
     1522    osgViewer::Viewer viewer; 
     1523 
     1524    // todo for osgViewer 
     1525    osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts(2); 
     1526    osg::Referenced::setThreadSafeReferenceCounting(true); 
     1527 
     1528    // register the handler to add keyboard and mosue handling. 
     1529    GameEventHandler* seh = new GameEventHandler(); 
     1530    viewer.addEventHandler(seh); 
     1531 
     1532    while (arguments.read("--boy")) seh->addPlayer(GameEventHandler::PLAYER_BOY); 
     1533    while (arguments.read("--girl")) seh->addPlayer(GameEventHandler::PLAYER_GIRL); 
     1534     
     1535     
     1536    // if user request help write it out to cout. 
     1537    if (arguments.read("-h") || arguments.read("--help")) 
     1538    { 
     1539        arguments.getApplicationUsage()->write(std::cout); 
     1540        return 1; 
     1541    } 
     1542 
     1543    // any option left unread are converted into errors to write out later. 
     1544    arguments.reportRemainingOptionsAsUnrecognized(); 
     1545 
     1546    // report any errors if they have occured when parsing the program aguments. 
     1547    if (arguments.errors()) 
     1548    { 
     1549        arguments.writeErrorMessages(std::cout); 
     1550        return 1; 
     1551    } 
     1552     
     1553     
     1554    // enable the image cache so we don't need to keep loading the particle files 
     1555    osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options; 
     1556    options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_IMAGES); 
     1557    osgDB::Registry::instance()->setOptions(options); 
     1558 
     1559 
     1560    // creat the scene from the file list. 
     1561    osg::ref_ptr<osg::Node> rootNode = seh->createScene(); 
     1562 
     1563    //osgDB::writeNodeFile(*rootNode,"test.osg"); 
     1564 
     1565    // set the scene to render 
     1566    viewer.setSceneData(rootNode.get()); 
     1567 
     1568    // viewer.setRealizeCallback(new CompileStateCallback(seh)); 
     1569 
     1570    double fovy, aspectRatio, zNear, zFar; 
     1571    viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); 
     1572    seh->setFOVY(osg::DegreesToRadians(fovy));     
     1573     
     1574    viewer.getCamera()->setClearColor(osg::Vec4f(0.6f,0.6f,0.8f,1.0f)); 
     1575 
     1576    // todo for osgViewer - create default set up. 
     1577    viewer.setUpViewAcrossAllScreens(); 
     1578 
     1579    viewer.realize(); 
     1580 
     1581    // todo for osgViewer - implement warp pointer 
     1582    // viewer.requestWarpPointer(0.5f,0.5f);         
     1583 
     1584    while( !viewer.done() ) 
     1585    { 
     1586        viewer.getCamera()->setViewMatrix(seh->getCameraPosition()); 
     1587 
     1588        // fire off the cull and draw traversals of the scene. 
     1589        viewer.frame(); 
     1590         
     1591    } 
     1592     
     1593    return 0; 
     1594} 
     1595 
     1596#endif