Changeset 9413

Show
Ignore:
Timestamp:
12/19/08 17:13:19 (4 years ago)
Author:
robert
Message:

Added support for user defined clipping of the precipitation effect, to test use:

osgpreciptation lz.osg --clip 20


Files:
1 modified

Legend:

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

    r6941 r9413  
    2121#include <osgUtil/Optimizer> 
    2222#include <osgUtil/CullVisitor> 
     23#include <osg/ClipNode> 
     24 
     25 
     26#include <osgGA/TrackballManipulator> 
     27#include <osgGA/FlightManipulator> 
     28#include <osgGA/DriveManipulator> 
     29#include <osgGA/KeySwitchMatrixManipulator> 
     30#include <osgGA/StateSetManipulator> 
     31#include <osgGA/AnimationPathManipulator> 
     32#include <osgGA/TerrainManipulator> 
     33 
    2334#include <osgViewer/Viewer> 
    2435 
     
    8495    osgViewer::Viewer viewer; 
    8596 
     97    // set up the camera manipulators. 
     98    { 
     99        osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 
     100 
     101        keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 
     102        keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 
     103        keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); 
     104        keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); 
     105 
     106        std::string pathfile; 
     107        char keyForAnimationPath = '5'; 
     108        while (arguments.read("-p",pathfile)) 
     109        { 
     110            osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 
     111            if (apm || !apm->valid())  
     112            { 
     113                unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); 
     114                keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); 
     115                keyswitchManipulator->selectMatrixManipulator(num); 
     116                ++keyForAnimationPath; 
     117            } 
     118        } 
     119 
     120        viewer.setCameraManipulator( keyswitchManipulator.get() ); 
     121    } 
     122 
    86123    osg::ref_ptr<osgParticle::PrecipitationEffect> precipitationEffect = new osgParticle::PrecipitationEffect; 
    87124 
     
    109146    osg::Vec3 cellSize; 
    110147    while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize);  
     148 
     149    double clipDistance = 0.0; 
     150    while (arguments.read("--clip",clipDistance)) {} 
    111151 
    112152    osg::BoundingBox bb; 
     
    145185    // precipitationEffect->setUpdateCallback(new MyGustCallback); 
    146186     
    147  
    148187    osg::ref_ptr<osg::Group> group = new osg::Group; 
    149     group->addChild(precipitationEffect.get()); 
    150  
     188     
     189    if (clipDistance!=0.0) 
     190    {     
     191        osg::ref_ptr<osg::ClipNode> clipNode = new osg::ClipNode; 
     192        clipNode->addClipPlane( new osg::ClipPlane( 0 ) ); 
     193        clipNode->getClipPlane(0)->setClipPlane( 0.0, 0.0, -1.0, -clipDistance ); 
     194        clipNode->setReferenceFrame(osg::ClipNode::ABSOLUTE_RF); 
     195        clipNode->addChild(precipitationEffect.get()); 
     196 
     197        group->addChild(clipNode.get()); 
     198    } 
     199    else 
     200    { 
     201        group->addChild(precipitationEffect.get()); 
     202    } 
     203     
    151204    group->addChild(loadedModel.get()); 
     205 
    152206    loadedModel->getOrCreateStateSet()->setAttributeAndModes(precipitationEffect->getFog()); 
    153207