Show
Ignore:
Timestamp:
01/05/07 22:19:01 (8 years ago)
Author:
robert
Message:

Ported osgcluster to osgViewer.

Files:
1 modified

Legend:

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

    r5592 r5920  
    99#include <osgDB/ReadFile> 
    1010 
    11 #include <osgProducer/Viewer> 
     11#include <osgViewer/Viewer> 
    1212 
    1313#include <osg/Quat> 
    1414#include <osg/io_utils> 
     15 
     16#include <iostream> 
    1517 
    1618#if defined (WIN32) && !defined(__CYGWIN__) 
     
    4850        } 
    4951         
    50         void readEventQueue(osgProducer::Viewer& viewer); 
    51          
    52         void writeEventQueue(osgProducer::Viewer& viewer); 
     52        void readEventQueue(osgViewer::Viewer& viewer); 
     53         
     54        void writeEventQueue(osgViewer::Viewer& viewer); 
    5355 
    5456        void setMasterKilled(const bool flag) { _masterKilled = flag; } 
     
    380382}; 
    381383 
    382 void CameraPacket::readEventQueue(osgProducer::Viewer& viewer) 
     384void CameraPacket::readEventQueue(osgViewer::Viewer& viewer) 
    383385{ 
    384386    _events.clear(); 
    385387 
    386     viewer.getKeyboardMouseCallback()->copyEventQueue(_events); 
     388    viewer.getEventQueue()->copyEvents(_events); 
    387389 
    388390    osg::notify(osg::INFO)<<"written events = "<<_events.size()<<std::endl; 
    389391} 
    390392 
    391 void CameraPacket::writeEventQueue(osgProducer::Viewer& viewer) 
     393void CameraPacket::writeEventQueue(osgViewer::Viewer& viewer) 
    392394{ 
    393395    osg::notify(osg::INFO)<<"recieved events = "<<_events.size()<<std::endl; 
    394396 
    395     // copy the events to osgProducer style events. 
    396     viewer.getKeyboardMouseCallback()->appendEventQueue(_events); 
     397    viewer.getEventQueue()->appendEvents(_events); 
    397398} 
    398399 
     
    422423     
    423424    // construct the viewer. 
    424     osgProducer::Viewer viewer(arguments); 
    425  
    426     // set up the value with sensible default event handlers. 
    427     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    428  
    429     // get details on keyboard and mouse bindings used by the viewer. 
    430     viewer.getUsage(*arguments.getApplicationUsage()); 
     425    osgViewer::Viewer viewer; 
    431426 
    432427 
     
    470465        return 1; 
    471466    } 
    472      
    473      
     467 
    474468    // load model. 
    475469    osg::ref_ptr<osg::Node> rootnode = osgDB::readNodeFiles(arguments); 
    476470 
    477      
    478471    // set the scene to render 
    479472    viewer.setSceneData(rootnode.get()); 
    480473 
     474    if (camera_fov>0.0f) 
     475    { 
     476        double fovy, aspectRatio, zNear, zFar; 
     477        viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); 
     478         
     479        double original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; 
     480        std::cout << "setting lens perspective : original "<<original_fov<<"  "<<fovy<<std::endl; 
     481         
     482        fovy = atan(tan(osg::DegreesToRadians(camera_fov)*0.5)/aspectRatio)*2.0; 
     483        viewer.getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); 
     484     
     485        viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,zNear, zFar); 
     486        original_fov = atan(tan(osg::DegreesToRadians(fovy)*0.5)*aspectRatio)*2.0; 
     487        std::cout << "setting lens perspective : new "<<original_fov<<"  "<<fovy<<std::endl; 
     488    } 
     489 
     490 
    481491    // create the windows and run the threads. 
    482492    viewer.realize(); 
    483  
    484  
    485     // set up the lens after realize as the Producer lens is not set up properly before this.... will need to inveestigate this at a later date. 
    486     if (camera_fov>0.0f) 
    487     { 
    488         float aspectRatio = tan( osg::DegreesToRadians(viewer.getLensVerticalFov()*0.5)) / tan(osg::DegreesToRadians(viewer.getLensHorizontalFov()*0.5)); 
    489         float new_fovy = osg::RadiansToDegrees(atan( aspectRatio * tan( osg::DegreesToRadians(camera_fov*0.5))))*2.0f; 
    490         std::cout << "setting lens perspective : original "<<viewer.getLensHorizontalFov()<<"  "<<viewer.getLensVerticalFov()<<std::endl; 
    491         viewer.setLensPerspective(camera_fov,new_fovy,1.0f,1000.0f); 
    492         std::cout << "setting lens perspective : new "<<viewer.getLensHorizontalFov()<<"  "<<viewer.getLensVerticalFov()<<std::endl; 
    493     } 
    494493 
    495494 
     
    509508    while( !viewer.done() && !masterKilled ) 
    510509    { 
    511         // wait for all cull and draw threads to complete. 
    512         viewer.sync(); 
    513  
    514510        osg::Timer_t startTick = osg::Timer::instance()->tick(); 
    515511                  
     512        viewer.advance(); 
     513 
    516514        // special handling for working as a cluster. 
    517515        switch (viewerMode) 
     
    521519                 
    522520                // take camera zero as the guide. 
    523                 osg::Matrix modelview(viewer.getCamera(0)->getViewMatrix()); 
     521                osg::Matrix modelview(viewer.getCamera()->getViewMatrix()); 
    524522                 
    525523                cp->setPacket(modelview,viewer.getFrameStamp()); 
     
    572570        // update the scene by traversing it with the the update visitor which will 
    573571        // call all node update callbacks and animations. 
    574         viewer.update(); 
     572        viewer.eventTraversal(); 
     573        viewer.updateTraversal(); 
    575574 
    576575        if (viewerMode==SLAVE) 
     
    579578            cp->getModelView(modelview,camera_offset); 
    580579         
    581             viewer.setView(modelview); 
     580            viewer.getCamera()->setViewMatrix(modelview); 
    582581        } 
    583582 
    584583        // fire off the cull and draw traversals of the scene. 
    585584        if(!masterKilled) 
    586             viewer.frame(); 
     585            viewer.renderingTraversals(); 
    587586         
    588587    } 
    589  
    590     // wait for all cull and draw threads to complete. 
    591     viewer.sync(); 
    592  
    593     // run a clean up frame to delete all OpenGL objects. 
    594     viewer.cleanup_frame(); 
    595  
    596     // wait for all the clean up frame to complete. 
    597     viewer.sync(); 
    598588 
    599589    // if we are master clean up by telling all slaves that we're going down.