<div dir="ltr">Hi All,<br><br>I have an simple question about light the terrain model problem. I have added two sphere(osg::Sphere) and one terrain(JoeDirt.flt) to the scene. I am trying to effect the components of scene with green light. Although green light could effected two of sphere, couldn't get<span style="background-color: rgb(255, 0, 0);"></span> success on the terrain model. What can I do to effect the terrain with green light? I have tried this code block;<br>
<br>--------------------------------------------------------------------------------------------------------------------------------------------------<br><b>int main()<br>{<br> osgViewer::Viewer viewer;<br> osg::ref_ptr<osg::Group> root (new osg::Group);<br>
<br> osg::ref_ptr<osg::MatrixTransform> terrainScaleMAT (new osg::MatrixTransform);<br> osg::Matrix terrainScaleMatrix;<br> terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f);<br> <br> //Lighting code<br>
osg::ref_ptr<osg::Group> lightGroup (new osg::Group);<br> osg::ref_ptr<osg::StateSet> lightSS (root->getOrCreateStateSet());<br> osg::ref_ptr<osg::LightSource> lightSource1 = new osg::LightSource;<br>
<br> // create a local light.<br> osg::Vec4f lightPosition (osg::Vec4f(0.0,0.0,3.0,1.0f));<br> osg::ref_ptr<osg::Light> myLight = new osg::Light;<br> myLight->setLightNum(1);<br> myLight->setPosition(lightPosition);<br>
myLight->setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f));<br> myLight->setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f));<br> myLight->setConstantAttenuation(1.0f);<br> lightSource1->setLight(myLight.get());<br>
<br> lightSource1->setLocalStateSetModes(osg::StateAttribute::ON); <br> lightSource1->setStateSetModes(*lightSS,osg::StateAttribute::ON); <br> <br> lightGroup->addChild(lightSource1.get());<br> <br>
//Light markers: small spheres<br> osg::ref_ptr<osg::Geode> lightMarkerGeode (new osg::Geode);<br> lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(-5.0f,-2.0f,3.0f),0.5f)));<br>
<br> //lightMarkerGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);<br> <br> //Second light marker<br> lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(2.0f,-1.0f,3.0f),0.5f)));<br>
<br> //Loading the terrain node<br> osg::ref_ptr<osg::Node> terrainnode (osgDB::readNodeFile("JoeDirt.flt"));<br> terrainScaleMAT->addChild(terrainnode.get());<br> terrainScaleMAT->setMatrix(terrainScaleMatrix);<br>
<br> //adding the terrain node to the root node<br> root->addChild(terrainScaleMAT.get());<br> <br> //lighting code<br> root->addChild(lightGroup.get());<br> //Adding the light marker geode<br>
root->addChild(lightMarkerGeode.get());<br><br> // add the state manipulator<br> viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );<br> <br> viewer.setSceneData( root.get() );<br>
<br> return (viewer.run());<br>}</b><br>--------------------------------------------------------------------------------------------------------------------------------------------------<br></div>