I'm trying to use osgShadow, I read examples on osg website and try to run
this code

But the shadow appears strangely like this picture:

http://i475.photobucket.com/albums/rr113/tek3D/shadow.jpg

Here is the code I tested:

int main()

{

           osgViewer::Viewer viewer;

 

           osg::ref_ptr<osg::Group> root = new osg::Group;

           // create light source.

           osg::LightSource* lightsource = new osg::LightSource;

           osg::Light* light = new osg::Light;

           lightsource->setLight(light);

           light->setDirection(osg::Vec3(0,10,0));

           light->setPosition(osg::Vec4(0,0,90,1.0f));

           light->setAmbient(osg::Vec4(0.00f,0.00f,0.08f,1.0f));

           light->setDiffuse(osg::Vec4(1.0f,1.0f,1.0f,1.0f));

           root->addChild(lightsource);

 

           //shadow

           const int ReceivesShadowTraversalMask = 0x1;

 

           const int CastsShadowTraversalMask = 0x2;

 

    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));

           sm->setLight(light);

 

    osg::Node* cessna1 = osgDB::readNodeFile("car68/car68.3DS");

    cessna1->setNodeMask(CastsShadowTraversalMask);

 

    osg::Node* cessna2 = osgDB::readNodeFile("lai.flt");

    cessna2->setNodeMask(ReceivesShadowTraversalMask);

 

    osg::MatrixTransform* positioned = new osg::MatrixTransform;

           osg::Matrix mat = osg::Matrix::rotate(2.7, osg::Vec3(0,0,1));

 
positioned->setMatrix(mat*positioned->getMatrix()*osg::Matrix::translate(10,
40,2));

    positioned->addChild(cessna1);

           

           shadowedScene->addChild(positioned);

           shadowedScene->addChild(cessna2);    

 

           root->addChild(shadowedScene);

 

           viewer.setSceneData(root);

           return viewer.run();

}

 

Could anyone help me with this problem? Thanks in advance!

<<image001.jpg>>

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to