Re: [osg-users] Camera and light problem

2008-03-10 Thread Vincent Bourdier
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 [EMAIL PROTECTED]:

  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_ptrosg::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_ptrosg::LightSource lightSource = new osg::LightSource;



 //create a transformation node that will move the node in the scene

 osg::ref_ptrosg::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_ptrosg::Geode geode = new osg::Geode;



 osg::ref_ptrosg::TessellationHints hints = new osg::TessellationHints;

 hints-setDetailRatio(0.3);



 osg::ref_ptrosg::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@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


Re: [osg-users] Camera and light problem

2008-03-06 Thread Vincent Bourdier
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_ptrosg::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_ptrosg::Light light = new osg::Light;

 //Set options…



 //create a lightsource for the light

   osg::ref_ptrosg::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_ptrosg::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_ptrosg::Geode geode = new osg::Geode;



   osg::ref_ptrosg::TessellationHints hints = newosg::TessellationHints;

   hints-setDetailRatio(0.3);



   osg::ref_ptrosg::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