diff --git a/examples/osgprecipitation/osgprecipitation.cpp b/examples/osgprecipitation/osgprecipitation.cpp index be48a6cf8..98ad13fb4 100644 --- a/examples/osgprecipitation/osgprecipitation.cpp +++ b/examples/osgprecipitation/osgprecipitation.cpp @@ -20,6 +20,17 @@ #include #include #include +#include + + +#include +#include +#include +#include +#include +#include +#include + #include #include @@ -83,6 +94,32 @@ int main( int argc, char **argv ) // construct the viewer. osgViewer::Viewer viewer; + // set up the camera manipulators. + { + osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; + + keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); + keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); + keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); + keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); + + std::string pathfile; + char keyForAnimationPath = '5'; + while (arguments.read("-p",pathfile)) + { + osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); + if (apm || !apm->valid()) + { + unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); + keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); + keyswitchManipulator->selectMatrixManipulator(num); + ++keyForAnimationPath; + } + } + + viewer.setCameraManipulator( keyswitchManipulator.get() ); + } + osg::ref_ptr precipitationEffect = new osgParticle::PrecipitationEffect; float intensity; @@ -109,6 +146,9 @@ int main( int argc, char **argv ) osg::Vec3 cellSize; while (arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z())) precipitationEffect->setCellSize(cellSize); + double clipDistance = 0.0; + while (arguments.read("--clip",clipDistance)) {} + osg::BoundingBox bb; while (arguments.read("--boundingBox", bb.xMin(), bb.yMin(), @@ -144,11 +184,25 @@ int main( int argc, char **argv ) // precipitationEffect->setUpdateCallback(new MyGustCallback); - osg::ref_ptr group = new osg::Group; - group->addChild(precipitationEffect.get()); + + if (clipDistance!=0.0) + { + osg::ref_ptr clipNode = new osg::ClipNode; + clipNode->addClipPlane( new osg::ClipPlane( 0 ) ); + clipNode->getClipPlane(0)->setClipPlane( 0.0, 0.0, -1.0, -clipDistance ); + clipNode->setReferenceFrame(osg::ClipNode::ABSOLUTE_RF); + clipNode->addChild(precipitationEffect.get()); + group->addChild(clipNode.get()); + } + else + { + group->addChild(precipitationEffect.get()); + } + group->addChild(loadedModel.get()); + loadedModel->getOrCreateStateSet()->setAttributeAndModes(precipitationEffect->getFog()); // create the light