diff --git a/src/Demos/osgoccluder/Makefile b/src/Demos/osgoccluder/Makefile new file mode 100644 index 000000000..0d05c021d --- /dev/null +++ b/src/Demos/osgoccluder/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgoccluder.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + Makefile.inst=Makefile + +EXEC = osgoccluder + +include $(TOPDIR)/Make/makerules + diff --git a/src/Demos/osgoccluder/Makefile.inst b/src/Demos/osgoccluder/Makefile.inst new file mode 100644 index 000000000..d5ea94820 --- /dev/null +++ b/src/Demos/osgoccluder/Makefile.inst @@ -0,0 +1,12 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgoccluder.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgoccluder + + +include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osgoccluder/osgoccluder.cpp b/src/Demos/osgoccluder/osgoccluder.cpp new file mode 100644 index 000000000..e34086ff2 --- /dev/null +++ b/src/Demos/osgoccluder/osgoccluder.cpp @@ -0,0 +1,181 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include +#include + +void write_usage(std::ostream& out,const std::string& name) +{ + out << std::endl; + out <<"usage:"<< std::endl; + out <<" "<addChild(model); + + + // create and occluder which will site along side the loadmodel model. + osg::OccluderNode* occluderNode = osgNew osg::OccluderNode; + + // get the bounding volume of the model. + const osg::BoundingSphere& bs = model->getBound(); + + // create a bounding box around the sphere. + osg::BoundingBox bb; + bb.expandBy(bs); + + + osg::ConvexPlanerOccluder* cpo = osgNew osg::ConvexPlanerOccluder; + + // set the occluder up for the front face of the bounding box. + osg::ConvexPlanerPolygon& occluder = cpo->getOccluder(); + occluder.add(osg::Vec3(bb.xMin(),bb.yMin(),bb.zMin())); + occluder.add(osg::Vec3(bb.xMax(),bb.yMin(),bb.zMin())); + occluder.add(osg::Vec3(bb.xMax(),bb.yMin(),bb.zMax())); + occluder.add(osg::Vec3(bb.xMin(),bb.yMin(),bb.zMax())); + + occluderNode->setOccluder(cpo); + + + // create a drawable for occluder. + osg::GeoSet* geoset = osgNew osg::GeoSet; + + osg::Vec3* coords = osgNew osg::Vec3[occluder.getVertexList().size()]; + std::copy(occluder.getVertexList().begin(),occluder.getVertexList().end(),coords); + geoset->setCoords(coords); + + osg::Vec4* color = osgNew osg::Vec4[1]; + color[0].set(1.0f,1.0f,1.0f,0.5f); + geoset->setColors(color); + geoset->setColorBinding(osg::GeoSet::BIND_OVERALL); + + geoset->setPrimType(osg::GeoSet::QUADS); + geoset->setNumPrims(1); + + osg::Geode* geode = osgNew osg::Geode; + geode->addDrawable(geoset); + + osg::StateSet* stateset = osgNew osg::StateSet; + stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + stateset->setMode(GL_BLEND,osg::StateAttribute::ON); + stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + + geoset->setStateSet(stateset); + + // add the occluder geode as a child of the occluder, + // as the occluder can't self occlude its subgraph the + // geode will never be occluder by this occluder. + occluderNode->addChild(geode); + + // add the occluder node into the scene. + scene->addChild(occluderNode); + + return scene; +} + + +int main( int argc, char **argv ) +{ + + // initialize the GLUT + glutInit( &argc, argv ); + + if (argc<2) + { + write_usage(std::cout,argv[0]); + return 0; + } + + // create the commandline args. + std::vector commandLine; + for(int i=1;i