Hi all,
I have currently a simple model on my scene, and I've added a light to the scene represented by a small sphere. I would like to fix light position and I don't want this one to move with the model (when I move the camera), or to move it independently from the main camera... So I decided to add a camera and to add the light to this one, this didn't solve the problem, both are moving togethers. Following is the main code that creates and place objects. I cannot use normals because I don't have geometry node. I would appreciate some help for this easy problem! Thanks in advance. Jon. { . //_modelGraph group represents the current scene //_root group will contains _modelGraph plus the light //create a group for the light _lightGraph = new osg::Group; . _root->addChild(_modelGraph.get()); //create a camera to install the light osg::ref_ptr<osg::Camera> camera = new osg::Camera; // just inherit the main cameras view camera->setProjectionMatrix(osg::Matrix::identity()); camera->setViewMatrix(osg::Matrix::identity()); //create the light osg::ref_ptr<osg::Light> light = new osg::Light; //Set options. //create a lightsource for the light osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource; lightSource->setLight(light.get()); lightSource->setLocalStateSetModes(osg::StateAttribute::ON); //create a transformation node that will move the node in the scene osg::ref_ptr<osg::MatrixTransform> transform = new osg::MatrixTransform; transform->addChild(lightSource.get()); //Position the light osg::Vec3 pos(-5.0f, 10.0f, 0.0f); transform->setMatrix(osg::Matrix::translate(pos)); //Add the transform to the camera camera->addChild(transform.get()); //create a small sphere to represent the lights position osg::ref_ptr<osg::Geode> geode = new osg::Geode; osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; hints->setDetailRatio(0.3); osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 0.6f), hints.get()); shape->setColor(lightColor); geode->addDrawable(shape.get()); transform->addChild(geode.get()); camera->addChild(_lightGraph.get()); // set the camera to render before the main camera (else just the light appears on a black screen) camera->setRenderOrder(osg::Camera::NESTED_RENDER); _root->addChild(camera.get()); }
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org