Show
Ignore:
Timestamp:
11/09/15 17:13:03 (2 years ago)
Author:
robert
Message:

Release OpenSceneGraph-3.5.1

Files:
1 modified

Legend:

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

    r13376 r13574  
    4545{ 
    4646    public: 
    47      
     47 
    4848        OccluderEventHandler(osgViewer::Viewer* viewer):_viewer(viewer) {} 
    49      
     49 
    5050        virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); 
    5151 
    5252        void addPoint(const osg::Vec3& pos); 
    53                  
     53 
    5454        void endOccluder(); 
    55          
     55 
    5656        osg::Group* rootNode() { return dynamic_cast<osg::Group*>(_viewer->getSceneData()); } 
    57          
    58          
     57 
     58 
    5959        osgViewer::Viewer*                    _viewer; 
    6060        osg::ref_ptr<osg::Group>                _occluders; 
     
    9191                if (_occluders.valid()) 
    9292                { 
    93                      
     93 
    9494                    if (osgDB::writeNodeFile(*_occluders,"saved_occluders.osgt")) 
    9595                        std::cout<<"saved occluders to 'saved_occluders.osgt'"<<std::endl; 
     
    112112{ 
    113113    std::cout<<"add point "<<pos<<std::endl; 
    114      
     114 
    115115    if (!_convexPlanarOccluder.valid()) _convexPlanarOccluder = new osg::ConvexPlanarOccluder; 
    116      
     116 
    117117    osg::ConvexPlanarPolygon& occluder = _convexPlanarOccluder->getOccluder(); 
    118118    occluder.add(pos); 
    119119 
    120 //      
     120// 
    121121//     osg::BoundingSphere bs = rootNode()->getBound(); 
    122 //  
     122// 
    123123//     osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(pos,bs.radius()*0.001f)); 
    124124//     osg::Geode* geode = new osg::Geode; 
    125125//     geode->addDrawable(sd); 
    126 //  
     126// 
    127127//     rootNode()->addChild(geode); 
    128 //  
    129      
    130 } 
    131                  
     128// 
     129 
     130} 
     131 
    132132void OccluderEventHandler::endOccluder() 
    133133{ 
    134     if (_convexPlanarOccluder.valid())  
     134    if (_convexPlanarOccluder.valid()) 
    135135    { 
    136136        if (_convexPlanarOccluder->getOccluder().getVertexList().size()>=3) 
     
    157157        std::cout<<"No occluder points to create occluder with."<<std::endl; 
    158158    } 
    159      
     159 
    160160    // reset current occluder. 
    161161    _convexPlanarOccluder = NULL; 
     
    174174    occluderNode->setOccluder(cpo); 
    175175    occluderNode->setName("occluder"); 
    176      
     176 
    177177    // set the occluder up for the front face of the bounding box. 
    178178    osg::ConvexPlanarPolygon& occluder = cpo->getOccluder(); 
     
    201201 
    202202        cpo->addHole(hole); 
    203     }     
    204      
     203    } 
     204 
    205205 
    206206   // create a drawable for occluder. 
    207207    osg::Geometry* geom = new osg::Geometry; 
    208      
     208 
    209209    osg::Vec3Array* coords = new osg::Vec3Array(occluder.getVertexList().begin(),occluder.getVertexList().end()); 
    210210    geom->setVertexArray(coords); 
    211      
     211 
    212212    osg::Vec4Array* colors = new osg::Vec4Array(1); 
    213213    (*colors)[0].set(1.0f,1.0f,1.0f,0.5f); 
    214     geom->setColorArray(colors); 
    215     geom->setColorBinding(osg::Geometry::BIND_OVERALL); 
    216      
     214    geom->setColorArray(colors, osg::Array::BIND_OVERALL); 
     215 
    217216    geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); 
    218      
     217 
    219218    osg::Geode* geode = new osg::Geode; 
    220219    geode->addDrawable(geom); 
    221      
     220 
    222221    osg::StateSet* stateset = new osg::StateSet; 
    223222    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 
    224223    stateset->setMode(GL_BLEND,osg::StateAttribute::ON); 
    225224    stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 
    226      
     225 
    227226    geom->setStateSet(stateset); 
    228      
     227 
    229228    // add the occluder geode as a child of the occluder, 
    230229    // as the occluder can't self occlude its subgraph the 
    231230    // geode will never be occluded by this occluder. 
    232     occluderNode->addChild(geode);     
    233      
     231    occluderNode->addChild(geode); 
     232 
    234233    return occluderNode; 
    235   
     234 
    236235 } 
    237236 
     
    248247    // get the bounding volume of the model. 
    249248    const osg::BoundingSphere bs = model->getBound(); 
    250      
     249 
    251250    // create a bounding box around the sphere. 
    252251    osg::BoundingBox bb; 
     
    279278 
    280279    return scene; 
    281 }  
     280} 
    282281 
    283282 
     
    293292    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    294293    arguments.getApplicationUsage()->addCommandLineOption("-m","Mannually create occluders"); 
    295     
     294 
    296295    // initialize the viewer. 
    297296    osgViewer::Viewer viewer; 
     
    314313    // load the nodes from the commandline arguments. 
    315314    osg::Node* loadedmodel = osgDB::readNodeFiles(arguments); 
    316      
     315 
    317316    // if not loaded assume no arguments passed in, try using default mode instead. 
    318317    if (!loadedmodel) loadedmodel = osgDB::readNodeFile("glider.osgt"); 
    319      
     318 
    320319    if (!loadedmodel) 
    321320    { 
     
    323322        return 1; 
    324323    } 
    325      
     324 
    326325    // run optimization over the scene graph 
    327326    osgUtil::Optimizer optimzer; 
     
    330329    // add the occluders to the loaded model. 
    331330    osg::ref_ptr<osg::Group> rootnode; 
    332      
     331 
    333332    if (manuallyCreateOccluders) 
    334333    { 
     
    336335        rootnode->addChild(loadedmodel); 
    337336    } 
    338     else     
     337    else 
    339338    { 
    340339        rootnode = createOccludersAroundModel(loadedmodel); 
    341340    } 
    342      
    343       
     341 
     342 
    344343    // add a viewport to the viewer and attach the scene graph. 
    345344    viewer.setSceneData( rootnode.get() );