[osg-users] getting eye position / direction

2012-03-09 Thread Andrey Ibe
Hi,

i am trying to get eyePosition and direction, more precisely, the direction of 
a ray for the purpose of ray tracing.

this is what i am doing:

Code:
const osg::Vec3d collisionPoint = intersection.getWorldIntersectPoint();
...
osg::Vec3d eyeDirection = collisionPoint - _tracer->getEye();
eyeDirection.normalize();


where the _tracer->getEye() method returns the position of the eye (computed 
once for a frame):
Code:

if (!_eye_set) {
osg::Vec3d center, up;
getCamera()->getViewMatrixAsLookAt(_eye, center, up);
_eye_set = true;
}


i am not sure whether this is the correct way to get the eye 
position/direction. i was thinking there has to be a way to get the direction 
from an intersection itself, but i am not confident using the start/end points 
(transforming them into appropriate coordinates) considering i create the rays 
(line segment intersectors) in WINDOW and also MODEL coordinate frames.

can anyone tell me whether my method is correct or i should rather try getting 
the start/end points from the intersector, transforming them and this way 
getting the ray (==eye) direction ?

Thank you!

Cheers,
Andrey[/code]

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





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


Re: [osg-users] getting eye position / direction

2012-03-09 Thread Robert Osfield
HI Andrey,

I'm rather confused about what you are trying to do, you question
seems rather mixed up.  Could you take a step back and explain at a
higher level what you are trying to achieve and we can then point you
in the right direction of how to achieve.

Robert.

On 9 March 2012 08:29, Andrey Ibe  wrote:
> Hi,
>
> i am trying to get eyePosition and direction, more precisely, the direction 
> of a ray for the purpose of ray tracing.
>
> this is what i am doing:
>
> Code:
> const osg::Vec3d collisionPoint = intersection.getWorldIntersectPoint();
> ...
> osg::Vec3d eyeDirection = collisionPoint - _tracer->getEye();
>                eyeDirection.normalize();
>
>
> where the _tracer->getEye() method returns the position of the eye (computed 
> once for a frame):
> Code:
>
>        if (!_eye_set) {
>                osg::Vec3d center, up;
>                getCamera()->getViewMatrixAsLookAt(_eye, center, up);
>                _eye_set = true;
>        }
>
>
> i am not sure whether this is the correct way to get the eye 
> position/direction. i was thinking there has to be a way to get the direction 
> from an intersection itself, but i am not confident using the start/end 
> points (transforming them into appropriate coordinates) considering i create 
> the rays (line segment intersectors) in WINDOW and also MODEL coordinate 
> frames.
>
> can anyone tell me whether my method is correct or i should rather try 
> getting the start/end points from the intersector, transforming them and this 
> way getting the ray (==eye) direction ?
>
> Thank you!
>
> Cheers,
> Andrey[/code]
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=46123#46123
>
>
>
>
>
> ___
> 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 eye position / direction

2012-03-09 Thread Andrey Ibe
i am trying to compute the direction of an osg::LineSegmentIntersector object. 
i can get the collision point and i am trying to get the starting point - i 
need the vector of the intersector's direction.

i do this for the purpose of ray tracing (or ray casting). i create the 
intersectors this way 
Code:
new osgUtil::LineSegmentIntersector(cf, x, y);

where cf is 'WINDOW' (this is for the primary rays). i am not sure how to 
transform the starting/end point of the intersector into model (world) space. 
that's why i am trying to get the position of the camera as the starting point. 
i looked at the code of the linesegmentintersector thoroughly, but still am 
confused about the matrices, so i decided it could be less difficult to use the 
camera.

i need the vector to calculate the specular color.

robert, thank you very much for your help.

andrey

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





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


Re: [osg-users] getting eye position / direction

2012-03-09 Thread Robert Osfield
Hi Andrey,

Thanks for the explanation, make more sense now.

If you have a perspective camera then you'll be able to assume that
the all the line segments will start at the cameras eye point and end
at the intersection point that is returned.  To compute the camera's
eye position in world coordinates what you need to do is multiple the
(0,0,0) eye position in eye coorindates into the world coordinates by
multiply it by the the inverse of the camera's view matrix.

i.e.

  osg::Vec3d eyeInWorld = osg::Vec3d(0.0,0.0,0.0) *
osg::Matrixd::inverse(camera->getViewMatrix());


Robert.

On 9 March 2012 10:41, Andrey Ibe  wrote:
> i am trying to compute the direction of an osg::LineSegmentIntersector 
> object. i can get the collision point and i am trying to get the starting 
> point - i need the vector of the intersector's direction.
>
> i do this for the purpose of ray tracing (or ray casting). i create the 
> intersectors this way
> Code:
> new osgUtil::LineSegmentIntersector(cf, x, y);
>
> where cf is 'WINDOW' (this is for the primary rays). i am not sure how to 
> transform the starting/end point of the intersector into model (world) space. 
> that's why i am trying to get the position of the camera as the starting 
> point. i looked at the code of the linesegmentintersector thoroughly, but 
> still am confused about the matrices, so i decided it could be less difficult 
> to use the camera.
>
> i need the vector to calculate the specular color.
>
> robert, thank you very much for your help.
>
> andrey
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=46129#46129
>
>
>
>
>
> ___
> 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 eye position / direction

2012-03-18 Thread Andrey Ibe
again, thank you, robert. now i know i'm getting correct results.

regards,
Andrey

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





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


Re: [osg-users] getting eye position / direction

2012-03-30 Thread Andrey Ibe
Hello again!

I've just realized i do need to be able to translate the starting and ending 
points of a LineSegmentIntersector created in WINDOW coordinate frame into the 
WORLD coordinate space.

is there any simple method to do so ? by retrieving them from the intersector 
or its intersection. i couldn't find any.

my guess is to take matrices, make an inverse and multiply:
Code:
osg::Matrix matrix;
matrix.preMult( somehow.getWindowMatrix() );
matrix.preMult( somehow.getProjectionMatrix() );
matrix.preMult( somehow.getViewMatrix() );
osg::Matrix inverse;
inverse.invert(matrix);

startPointInWorldCoordinates = startPoint * inverse;

but this seems computation-wise lengthy and i am not sure how to get all these 
matrices ... maybe the window matrix from viewport and the other two from 
camera.
but I see this is done in the lineSegmentIntersector, the matrices are 
retrieved from the visitor, yet neither the matrices, nor the points are 
stored. my second guess would be inheriting the LineSegmentIntersector itself 
and modify the descendant to store those translated points.

I found out that having a wall (or any other object) close behind the 
projection pane (e.g. looking into a room from a corner or from a point close 
to the wall) is fine in the osg::viewer, but if i take the camera as the 
starting point of the rays, the rays end up hitting the wall, which is not 
actually seen. that's why i need to start the rays not from the camera, but 
from the projection pane and to do so i need to be able to translate the points 
on it into the WORLD coordinate space.

Thank you for any pointers!

Cheers,
Andrey

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





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


Re: [osg-users] getting eye position / direction

2012-03-31 Thread Andrey Ibe
update:

Code:
// get matrices
osg::Matrix matrix;
matrix.preMult(_tracer->getCamera()->getViewport()->computeWindowMatrix());
matrix.preMult(_tracer->getCamera()->getProjectionMatrix());
matrix.preMult(_tracer->getCamera()->getViewMatrix());

// invert
osg::Matrix inverse;
inverse.invert(matrix);

// set results
_startWorldPoint = getStart() * inverse;
_endWorldPoint = getEnd() * inverse;

...
Code:
osg::Vec3d eyeDirection = collisionPoint - _tracer->getEye();
eyeDirection.normalize(); // this vector is correct, but the starting point 
(the eye) is not sufficient for my application

osg::Vec3d newDirection = getReverseDirection(); // _reverseDirectionVector = 
(getEndWorldPoint() - getStartWorldPoint()).getVectorPart();
newDirection.normalize(); // this vector is slightly different, i suppose the 
points are not correctly positioned 


this approach results in similar, but not the same vectors. definitely not 
correct though, according to visual results.

any suggestions?

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





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


Re: [osg-users] getting eye position / direction

2012-04-15 Thread Andrey Ibe
Hi, this post is for those reading this thread wondering how i solved the issue.

I solved it by creating the line segment intersectors in model coordinate 
space, transforming the starting/ending point using this matrix:
Code:
osg::Matrixd matrix;
matrix.preMult(_masterCamera->getViewport()->computeWindowMatrix());
matrix.preMult(_masterCamera->getProjectionMatrix());
matrix.preMult(_masterCamera->getViewMatrix());
_renderMatrixInverse->invert(matrix);


This way the lineSegmentIntersector gets initialized correctly and the 
intersections are computed well. The problem itself originated elsewhere - i 
was using the camera as the ROOT node for intersectionVisitor, which did not 
behave the way expected.
I encountered another issue when using the camera as the root - the invisible 
parts of the scene got culled away (as expected for rendering), however, while 
computing reflected rays, this caused serious issues, as these rays did not hit 
the expected objects, because they 'were not there'. I had to use own matrix 
transformation for the primary rays and let all the rest compute in the model 
coordinate space, the scene being the root (without any other transformations).

take care,
Andrey

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





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