Hello Sajjadul,

Sajjadul Islam wrote:
> Hello,
> I am trying to add light to  the planetary system that is depicted in
> the chapter titled "Node Cores" at  the tutorial section.
> 
> The scene graph of the planetary system is same as before, - the only
> thing that is added now is that i have a NodePtr pLightNode as the
> ancestor and set PointLightPtr as its core.
> 
> I have set the beacon to point to  the sun node.

did you attach the correct code ? This description does not seem to
match the contents of the file you attached, as that has a lit water mesh ?

> But when i compile and run the program i do not see any effect .

Little side note here: it makes things easier for us if you attach all
files needed to compile, i.e. your Basic.h header was missing.

> I am attaching the code for it(even though it is bit long , it is well
> well organized)
> 
> So i believe that some one would be kind enough to go through  the code
> and let me know what did i miss or i miss the whole concept of lighting.

The problem with your code is mainly that your light source is very weak
and it's effect is simply not visible, because it is dominated by the
SSM headlight. Also there were two instances of beginEditCP that should
have been endEditCP, see the comments below.

[SNIP]
> 
> NodePtr createWater(void);
> 
> 
> NodePtr createWater(void)
> {
[SNIP]
> 
>          //Let there be light!!!!!
>               
>               //start with  the point light
>               PointLightPtr pLight = PointLight::create();
> 
>               //then i try  the directional light
>               //DirectionalLightPtr dLight = DirectionalLight::create();
> 
>               NodePtr water = Node::create();
>               NodePtr pLightTransformNode = Node::create();
>               TransformPtr pLightTransform = Transform::create();
>               NodePtr pLightNode = Node::create();
>               
> 
>               beginEditCP(pLightNode, Node::CoreFieldMask);
>                       pLightNode->setCore(Group::create());
>               endEditCP(pLightNode, Node::CoreFieldMask);
> 
> 
>               Matrix m;
>               m.setIdentity();
>               m.setTranslate(50,25,50);
> 
> 
>               beginEditCP(pLightTransform, Transform::MatrixFieldMask);
>                               pLightTransform->setMatrix(m);
>               endEditCP(pLightTransform, Transform::MatrixFieldMask);
> 
> 
>               //we add a little sphere that will represent the little light 
>               //souce that we are trying to simulate
>               GeometryPtr sphere = makeSphereGeo(2,2);
> 
>               SimpleMaterialPtr sm = SimpleMaterial::create();
> 
>               beginEditCP(sm, SimpleMaterial::DiffuseFieldMask |
>                                                        
> SimpleMaterial::LitFieldMask);
>                                                        
>                                                        sm->setLit(false);
>                                                        
> sm->setDiffuse(Color3f(1,1,1));
> 
>       endEditCP(sm, SimpleMaterial::DiffuseFieldMask |
>                                                        
> SimpleMaterial::LitFieldMask);
>               
> 
>               beginEditCP(sphere, Geometry::MaterialFieldMask);
>                               sphere->setMaterial(sm);
>               endEditCP(sphere, Geometry::MaterialFieldMask);
> 
> 
> 
>               NodePtr sphereNode = Node::create();
> 
>               beginEditCP(sphereNode, Node::CoreFieldMask);
>                               sphereNode->setCore(sphere);
>               endEditCP(sphereNode, Node::CoreFieldMask);
> 
> 
>               beginEditCP(pLightTransformNode, Node::CoreFieldMask | 
>                                                                               
>                         Node::ChildrenFieldMask);
>                               pLightTransformNode->setCore(pLightTransform);
>                               pLightTransformNode->addChild(pLightNode);
>                               pLightTransformNode->addChild(sphereNode);
>               endEditCP(pLightTransformNode, Node::CoreFieldMask | 
>                                                                               
>                  Node::ChildrenFieldMask);                                    
>                                                           
> 
>         
>               beginEditCP(pLight, PointLight::PositionFieldMask               
>                                 |
>                                                                 
> PointLight::ConstantAttenuationFieldMask              |
>                                                                 
> PointLight::LinearAttenuationFieldMask                        |
>                                                                 
> PointLight::QuadraticAttenuationFieldMask             |
>                                                                 
> PointLight::DiffuseFieldMask                                          |
>                                                                 
> PointLight::AmbientFieldMask                                          |
>                                                                 
> PointLight::SpecularFieldMask                                         |
>                                                                 
> PointLight::BeaconFieldMask);
>                                               //attenuation information
>                                               
> pLight->setPosition(Pnt3f(0,0,0));
>                                               
> pLight->setConstantAttenuation(1);
>                                               pLight->setLinearAttenuation(0);
>                                               
> pLight->setQuadraticAttenuation(0);
> 
> 
>                                               //color information
>                                               
> pLight->setDiffuse(Color4f(1,1,1,1));
>                                               
> pLight->setDiffuse(Color4f(0.2,0.2,0.2,1));

you create a very weak gray light source here. The effect is easily
dominated by the SSM headlight, which you should turn off to see the
effect of your own light source clearly.
                                                
>                                               
> pLight->setSpecular(Color4f(1,1,1,1));
> 
> 
>                                               //set beacon
>                                               pLight->setBeacon(pLightNode);
> 
>               beginEditCP(pLight, PointLight::PositionFieldMask               
>                                 |
>                                                                 
> PointLight::ConstantAttenuationFieldMask              |
>                                                                 
> PointLight::LinearAttenuationFieldMask                        |
>                                                                 
> PointLight::QuadraticAttenuationFieldMask             |
>                                                                 
> PointLight::DiffuseFieldMask                                          |
>                                                                 
> PointLight::AmbientFieldMask                                          |
>                                                                 
> PointLight::SpecularFieldMask                                         |
>                                                                 
> PointLight::BeaconFieldMask);

                ^^^^^^^^^^^^
                endEditCP(....
        
>    
> 
>    /*
>       beginEditCP(dLight, DirectionalLight::DiffuseFieldMask  |
>                                                         
> DirectionalLight::AmbientFieldMask    |
>                                                         
> DirectionalLight::SpecularFieldMask   |
>                                                         
> DirectionalLight::BeaconFieldMask);
>                                       dLight->setDiffuse(Color4f(1,1,1,1));
>                                       
> dLight->setAmbient(Color4f(0.2,0.2,0.2,1));
>                                       dLight->setSpecular(Color4f(1,1,1,1));
>                                       dLight->setBeacon(pLightNode);
>       endEditCP(dLight,   DirectionalLight::DiffuseFieldMask  |
>                                                         
> DirectionalLight::AmbientFieldMask    |
>                                                         
> DirectionalLight::SpecularFieldMask   |
>                                                         
> DirectionalLight::BeaconFieldMask);
>    */
>       beginEditCP(water, Node::CoreFieldMask);
>               water->setCore(geo);
>       endEditCP(water, Node::CoreFieldMask);
> 
> 
>       //finally we put the newly created core
>       //to the nore and return
>       NodePtr root = Node::create();
>       
>       beginEditCP(root, Node::CoreFieldMask |
>                                                       
> Node::ChildrenFieldMask);
>                               root->setCore(pLight);
>                               root->addChild(water);
>                               root->addChild(pLightTransformNode);
>       beginEditCP(root, Node::CoreFieldMask |
>                                                       
> Node::ChildrenFieldMask);

        ^^^^^^^^^^^
        endEditCP(....
>       
> 
>       return root;
> }
> 
> 
> 
> int main(int argc, char **argv)
> {
>       osgInit(argc,argv);
> 
>       //create the GLUTWindow which is same for most of the application
>       int winid = setupGLUT(&argc,argv);      
> 
> 
>       GLUTWindowPtr gwin = GLUTWindow::create();
> 
> 
>       gwin->setId(winid);
>       gwin->init();
>       
>       scene = createWater();
> 
> 
>       //Create and setup the SSM
>       mgr = new SimpleSceneManager();
>       mgr->setWindow(gwin);
>       mgr->setRoot(scene);
>       mgr->setHeadlight(true);
                          ^^^^^
                        put false here to turn off the SSM headlight

>       mgr->showAll();
> 
> 
>       /*
>       without the following code i have to rotate to get  
>       a view of the quad. To solve that problem we will be adding 
>       value to  the camera position during the setup. 
>       */
>       Navigator *nav = mgr->getNavigator();
>       nav->setFrom(nav->getFrom() + Vec3f(0,50,0));
>               
> 
>       //give control to  the glut mainloop
>       glutMainLoop();
> 
> }
[SNIP]

With these changes I get a lit water mesh.

        Hope it helps,
                Carsten


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to