From 6778bfca44f5bd9882a62798b71d165c9dbadf33 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 1 Dec 2006 15:19:21 +0000 Subject: [PATCH] Added support for placing a base in the scene to shadow against --- examples/osgshadow/osgshadow.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index e3f020e74..2b360f0cc 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -149,6 +149,9 @@ int main(int argc, char** argv) bool updateLightPosition = true; while (arguments.read("--noUpdate")) updateLightPosition = false; + bool createBase = false; + while (arguments.read("--base")) createBase = true; + bool doShadow = true; while (arguments.read("--noShadow")) doShadow = false; @@ -174,6 +177,29 @@ int main(int argc, char** argv) ComputeBoundingBoxVisitor cbbv; model->accept(cbbv); osg::BoundingBox bb = cbbv.getBoundingBox(); + + if (createBase) + { + osg::ref_ptr newGroup = new osg::Group; + newGroup->addChild(model.get()); + + osg::Geode* geode = new osg::Geode; + + osg::Vec3 widthVec(bb.radius(), 0.0f, 0.0f); + osg::Vec3 depthVec(0.0f, bb.radius(), 0.0f); + osg::Vec3 centerBase( (bb.xMin()+bb.xMax())*0.5f, (bb.yMin()+bb.yMax())*0.5f, bb.zMin()-bb.radius()*0.1f ); + + geode->addDrawable( createTexturedQuadGeometry( centerBase-widthVec*1.5f-depthVec*1.5f, + widthVec*3.0f, depthVec*3.0f) ); + newGroup->addChild(geode); + + model = newGroup.get(); + } + + // get the bounds of the model. + cbbv.reset(); + model->accept(cbbv); + bb = cbbv.getBoundingBox(); osg::ref_ptr group = new osg::Group; @@ -205,6 +231,7 @@ int main(int argc, char** argv) } + osg::ref_ptr light = new osg::Light; if (!doShadow)