Hi Jon

If you add your transform to the camera, it is normal that the light follow
the camera..
If you want to keep the light at the same position, you have to attach it
near the root node, and attach the rest of the scene a lower levels than it.


Each child inherit from its parents, so if you attach a group to a
transform, each child of the group (and their children) will follow the
group's transformation.


Vincent.


2008/3/5, Jon <[EMAIL PROTECTED]>:
>
>  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 = newosg::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 = newosg::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 = newosg::TessellationHints;
>
>       hints->setDetailRatio(0.3);
>
>
>
>       osg::ref_ptr<osg::ShapeDrawable> shape = new 
> osg::ShapeDrawable(newosg::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
>
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to