Re: [osg-users] getting correct light position

2012-04-12 Thread Andrey Ibe
Hi,

update: working! ... almost correctly

I have recently realized, that the problem may be caused by me not treating the 
fourth vector component (w) well - but if i use .project() method of either 
osg::Vec4d or osg::Vec4dH, it produces infinity for directional lights, which 
is expected, but how do i treat such values ? :?

the light is finally positioned well :D  if i alter the fourth component not to 
be zero, but some small value close to zero, just before using .project() 
method on the light's position. but i do not want to keep using this kind of 
hack. is there another way?
i need to get the light's position to be able to compute precise vectors for 
lighting equations ... 

Thank you for suggestions!

Cheers,
Andrey

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=47011#47011





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] getting correct light position

2012-03-28 Thread Sergey Polischuk
Hi
check if you treat directional light in a right way (i mean use light direction 
instead of position and such)

28.03.2012, 13:29, Andrey Ibe xry...@gmail.com:
 Hi,

 i am doing an off-line ray-tracing. at the beginning of the computation i 
 fetch all the lights and then use them.

 the problem is, i am not getting the correct light position, obviously. i 
 attached two pictures showing the difference between the position the 
 osg::viewer is getting and the one i'm getting for the ray-tracing. the 
 pictures feature a solo directional light. in the viewer picture you can 
 guess the position of the light by the specular reflection on the pink 
 object. it seems to be exactly on the opposite side compared to the 
 ray-traced image.

 so far this only happened with the directional light for this model, but i 
 start to suspect, that the other lights (in different models) are not 
 positioned correctly either.

 i fetch the lights using a lightsource visitor, taht collects the light 
 sources, then i use getWorldMatrices() and take the first transformation 
 matrix, finally i multiply the light's position and directions.  this is the 
 code:
 Code:

 void RayManager::collectLightSources(WorldLightSourceContainer lc) const {

 osg::ref_ptrLightSourceVisitor lVisitor = new 
 LightSourceVisitor(lc.sources);
 _scene-accept(*(lVisitor.get()));
 for (LightSources::iterator lsIt = lc.sources.begin(); lsIt != 
 lc.sources.end(); lsIt++) {

 osg::MatrixList worldMatrices = (*lsIt)-getWorldMatrices();
 // take the first world matrix
 osg::Matrix m = worldMatrices.front();
 lc.positions.push_back((*lsIt)-getLight()-getPosition()
  * m);
 osg::Vec3d direction = 
 (*lsIt)-getLight()-getDirection() * m;
 direction.normalize();
 lc.directions.push_back(direction);
 }
 }

 and this is the code for my lighSource visitor
 Code:

 LightSourceVisitor::LightSourceVisitor(LightSources lightSources) : 
 osg::NodeVisitor(TRAVERSE_ALL_CHILDREN),
 _lightSources(lightSources) {
 }

 void LightSourceVisitor::apply(osg::LightSource node) {
 _lightSources.push_back(node);
 osg::NodeVisitor::apply((osg::Group)node);
 }

 am i doing something wrong ? the code seems to work for the two other lights 
 (which are turned off in the attached pictures), that's what worries me.
 Thank you!

 Cheers,
 Andrey

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=46645#46645

 ___
 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] getting correct light position

2012-03-28 Thread Andrey Ibe
Hi and thank you for the quick suggestion.

i double checked. i treat all three types of the light equally, in terms of 
vector mathematics. the only difference is the attenuation stuff, but these 
values are scalar.

Cheers,
Andrey

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46651#46651





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org