[osg-users] osg::Light Simple Question ?
Ümit Uzun
umituzun84 at gmail.com
Fri Jul 18 15:39:22 PDT 2008
Hi All,
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 success on the terrain
model. What can I do to effect the terrain with green light? I have tried
this code block;
--------------------------------------------------------------------------------------------------------------------------------------------------
*int main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root (new osg::Group);
osg::ref_ptr<osg::MatrixTransform> terrainScaleMAT (new
osg::MatrixTransform);
osg::Matrix terrainScaleMatrix;
terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f);
//Lighting code
osg::ref_ptr<osg::Group> lightGroup (new osg::Group);
osg::ref_ptr<osg::StateSet> lightSS (root->getOrCreateStateSet());
osg::ref_ptr<osg::LightSource> lightSource1 = new osg::LightSource;
// create a local light.
osg::Vec4f lightPosition (osg::Vec4f(0.0,0.0,3.0,1.0f));
osg::ref_ptr<osg::Light> myLight = new osg::Light;
myLight->setLightNum(1);
myLight->setPosition(lightPosition);
myLight->setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f));
myLight->setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f));
myLight->setConstantAttenuation(1.0f);
lightSource1->setLight(myLight.get());
lightSource1->setLocalStateSetModes(osg::StateAttribute::ON);
lightSource1->setStateSetModes(*lightSS,osg::StateAttribute::ON);
lightGroup->addChild(lightSource1.get());
//Light markers: small spheres
osg::ref_ptr<osg::Geode> lightMarkerGeode (new osg::Geode);
lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new
osg::Sphere(osg::Vec3f(-5.0f,-2.0f,3.0f),0.5f)));
//lightMarkerGeode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
//Second light marker
lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new
osg::Sphere(osg::Vec3f(2.0f,-1.0f,3.0f),0.5f)));
//Loading the terrain node
osg::ref_ptr<osg::Node> terrainnode
(osgDB::readNodeFile("JoeDirt.flt"));
terrainScaleMAT->addChild(terrainnode.get());
terrainScaleMAT->setMatrix(terrainScaleMatrix);
//adding the terrain node to the root node
root->addChild(terrainScaleMAT.get());
//lighting code
root->addChild(lightGroup.get());
//Adding the light marker geode
root->addChild(lightMarkerGeode.get());
// add the state manipulator
viewer.addEventHandler( new
osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
viewer.setSceneData( root.get() );
return (viewer.run());
}*
--------------------------------------------------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080719/1280048a/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TerrainLightening.png
Type: image/png
Size: 181563 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080719/1280048a/attachment-0002.png>
More information about the osg-users
mailing list