Hi,
I know I said I wouldnt need this feature for a while yet, but i do. I need to
impliment this before my toolkit gets too large.
So in the hope that someones up to the challenge I present here a simple
example of a shadowed scene containing a cube which has been split in half by a
clipPlane leaving a hole.
The challenge is to fill this hole.
Heres hoping,
Thank you!
Cheers,
PaulG
Code:
#include <osg/ArgumentParser>
#include <osg/Texture2D>
#include <osg/ShapeDrawable>
#include <osg/ClipNode>
#include <osg/MatrixTransform>
#include <osg/Geometry>
#include <osgViewer/Viewer>
#include <osgShadow/ShadowedScene>
#include <osgShadow/ShadowMap>
#include <osgShadow/LightSpacePerspectiveShadowMap>
#include <iostream>
#include <osgGA/TrackballManipulator>
static int ReceivesShadowTraversalMask = 0x1;
static int CastsShadowTraversalMask = 0x2;
int main(int argc, char** argv)
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc, argv);
// construct the viewer.
osgViewer::Viewer viewer(arguments);
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new
osgShadow::ShadowedScene;
shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask);
osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
shadowedScene->setShadowTechnique(sm.get());
int mapres = 1024;
sm->setTextureSize(osg::Vec2s(mapres,mapres));
osg::Vec4 lightpos;
lightpos.set(0.5f,0.25f,0.8f,0.0f);
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
ls->getLight()->setPosition(lightpos);
ls->getLight()->setAmbient(osg::Vec4(0.2,0.2,0.2,1.0));
ls->getLight()->setDiffuse(osg::Vec4(0.8,0.8,0.8,1.0));
osg::ref_ptr<osg::ClipNode> clipNode= new osg::ClipNode;
clipNode->setCullingActive(false);
osg::ref_ptr<osg::MatrixTransform> clipNodeTransform = new
osg::MatrixTransform;
osg::Matrix clipNodeTrans;
clipNodeTrans = osg::Matrix::translate(0.f, 5.f, 0.f);
clipNodeTransform->setMatrix(clipNodeTrans);
clipNodeTransform->addChild(clipNode);
shadowedScene->addChild(clipNodeTransform);
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints;
hints->setDetailRatio(2.0f);
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f,
0.0f, -2.0f), 2.f, 2.f, 2.f), hints));
clipNode->addChild(geode.get());
osg::ClipPlane* clipPlane = new osg::ClipPlane();
osg::Vec4d plane;
plane.set(0.5f, 1.f, 0.f, 0.f);
clipPlane->setClipPlane(plane);
clipNode->addClipPlane(clipPlane);
shadowedScene->addChild(ls.get());
viewer.setSceneData(shadowedScene.get());
viewer.setCameraManipulator(new osgGA::TrackballManipulator);
// create the windows and run the threads.
viewer.realize();
while (!viewer.done())
{
{
osgShadow::MinimalShadowMap * msm =
dynamic_cast<osgShadow::MinimalShadowMap*>( shadowedScene->getShadowTechnique()
);
if( msm ) {
// If scene decorated by CoordinateSystemNode
try to find localToWorld
// and set modellingSpaceToWorld matrix to
optimize scene bounds computation
osg::NodePath np =
viewer.getCoordinateSystemNodePath();
if( !np.empty() ) {
osg::CoordinateSystemNode * csn =
dynamic_cast<osg::CoordinateSystemNode *>( np.back() );
if( csn ) {
osg::Vec3d pos =
viewer.getCameraManipulator()->getMatrix().getTrans();
msm->setModellingSpaceToWorldTransform
(
csn->computeLocalCoordinateFrame( pos ) );
}
}
}
}
viewer.frame();
}
return 0;
}
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=12867#12867
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org