[osg-users] Camera and light problem
Vincent Bourdier
vincent.bourdier at gmail.com
Mon Mar 10 01:20:07 PDT 2008
Hi Jon,
If your light is in the model at (0,0,0) it is normal, because in the graph,
the position is always relative (depends on the parent node) (if you let it
by default).
try something like :
-ROOT
---lightsource
---tranform
------geode
In this case light source will be in relative coordinates but in the
coordinate system of the root node (it is like being in absolute )
And light will not move with the geode, because it is not in the transform
group.
Note : if ROOT is not the real root node but juste the root of the scene,
try this :
-REAL_ROOT
--- ...
------...
------lightsource
------ROOT
---------tranform
---------geode
Hoping this will help you.
Vincent.
2008/3/8, Jon <lunatike at hotmail.fr>:
>
> Thanks Vincent for your answer.
>
>
>
> I tried to follow your suggestion, but the problem persists.
>
>
>
> If you look at the code, I have :
>
> |_root
>
> ---|_modelGraph
>
> ---|transform
>
> ---------|lightsource
>
> ---------|geode
>
>
>
> Any suggestions ? What are my mistakes?
>
> My goal is to have a model moving with the camera and a light represented
> by a sphere that does not move (fixed coord).
>
> Just one precision: when I place the light in the scene, the light
> coordinates depends of the model: ((0,0,0) puts the light inside the model)
>
>
>
> Could this explain the problem?
>
> How can I prevent this?
>
>
>
> Thanks again.
>
>
>
> {
>
> *//_modelGraph group represents the current scene*
>
> *//_root group will contains _modelGraph plus the light*
>
>
>
> //create the light
>
> osg::ref_ptr<osg::Light> light = new osg::Light;
>
> //make the light a point light by setting w to 1.0
>
> light->setPosition(osg::Vec4(-10.0f, -10.0f, 0.0f, 10.0f));
>
>
>
> //create a lightsource for the light
>
> osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource;
>
>
>
> //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));
>
>
>
> //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(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());
>
>
>
> _root->addChild(transform.get());
>
>
>
> //add the model to the light's root group
>
> _root->addChild(_modelGraph.get());
>
> }
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080310/4aa378fd/attachment.htm
More information about the osg-users
mailing list