|
osg::ref_ptr<osgViewer::Viewer>viewer=new osgViewer::Viewer;
osg::ref_ptr<osg::Group>group=new osg::Group;
osg::ref_ptr<osgShadow::ShadowedScene>shadowscene=new osgShadow::ShadowedScene;
osg::ref_ptr<osgShadow::ShadowTexture>shadowtextue=new osgShadow::ShadowTexture;
shadowscene->setShadowTechnique(shadowtextue.get());
shadowscene->setCastsShadowTraversalMask(0x1);
shadowscene->setReceivesShadowTraversalMask(0x2);
//创建光照 这儿我想用太阳关如向量为 vDirect(0.3, -0.9, 0.3)
osg::ref_ptr<osg:ightSource>lightsource=new osg::LightSource;
osg::ref_ptr<osg::Light>light=lightsource->getLight();
light->setAmbient(osg::Vec4(0.5f,0.5f,0.5f,1.0f));
light->setDiffuse(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
light->setPosition(osg::Vec4(0.0f,0.0f,100.0f,1.0f));
shadowscene->addChild(lightsource.get());
//创建场景 地形在xoy平面,飞机高度为50, 光源高度为100
osg::ref_ptr<osg::Node>cessna=osgDB::readNodeFile("cessna.osg");
osg::ref_ptr<osg::MatrixTransform>cessnaMatrix=new osg::MatrixTransform;
cessnaMatrix->setMatrix(osg::Matrix::translate(osg::Vec3(0.0f,0.0f,50.0f)));
cessnaMatrix->addChild(cessna);
//请代码阅读者,互换接收或者被接收mask,飞机投影地形是没有问题的,但是地形投影飞机却是不正确的结果
cessna->setNodeMask(0x1);
osg::ref_ptr<osg::Node>terrain=createTerrain();
terrain->setNodeMask(0x2);
shadowscene->addChild(cessnaMatrix.get());
shadowscene->addChild(terrain.get());
group->addChild(shadowscene);
viewer->setSceneData(group.get());
viewer->run(); |
|