Show
Ignore:
Timestamp:
06/08/11 11:24:29 (2 years ago)
Author:
robert
Message:

Simplified the osgdepthpartion example to use the osgView::View::setUpDepthPartition(..) feature

Files:
1 modified

Legend:

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

    r10021 r12503  
    2525 
    2626#include <osgGA/TrackballManipulator> 
     27#include <osgGA/StateSetManipulator> 
    2728 
    2829#include <osgViewer/Viewer> 
    29  
    30 #include "DepthPartitionNode.h" 
     30#include <osgViewer/ViewerEventHandlers> 
    3131 
    3232const double r_earth = 6378.137; 
     
    133133    osgViewer::Viewer viewer; 
    134134 
     135    // add the state manipulator 
     136    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 
     137 
     138    // add stats 
     139    viewer.addEventHandler( new osgViewer::StatsHandler() ); 
     140 
    135141    bool needToSetHomePosition = false; 
    136142 
     
    144150        needToSetHomePosition = true; 
    145151    } 
    146      
    147     // Create a DepthPartitionNode to manage partitioning of the scene 
    148     osg::ref_ptr<DepthPartitionNode> dpn = new DepthPartitionNode; 
    149     dpn->addChild(scene.get()); 
    150     dpn->setActive(true); // Control whether the node analyzes the scene 
    151          
    152152    // pass the loaded scene graph to the viewer. 
    153     viewer.setSceneData(dpn.get()); 
     153    viewer.setSceneData(scene.get()); 
    154154 
    155155    viewer.setCameraManipulator(new osgGA::TrackballManipulator); 
     
    157157    if (needToSetHomePosition) 
    158158    { 
    159       viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); 
     159        viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); 
    160160    } 
    161161     
    162     // depth partion node is only supports single window/single threaded at present. 
    163     viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); 
     162    double zNear=1.0, zMid=10.0, zFar=1000.0; 
     163    if (arguments.read("--depth-partition",zNear, zMid, zFar)) 
     164    { 
     165        // set up depth partitioning 
     166        osg::ref_ptr<osgViewer::DepthPartitionSettings> dps = new osgViewer::DepthPartitionSettings; 
     167        dps->_mode = osgViewer::DepthPartitionSettings::FIXED_RANGE; 
     168        dps->_zNear = zNear; 
     169        dps->_zMid = zMid; 
     170        dps->_zFar = zFar; 
     171        viewer.setUpDepthPartition(dps.get()); 
     172    } 
     173    else 
     174    { 
     175        // set up depth partitioning with default settings 
     176        viewer.setUpDepthPartition(); 
     177    } 
     178     
    164179 
    165180    return viewer.run();