Volker Poplawski wrote:
Paul Martz 12.02.2010 20:45:
The Camera's View matrix contains the eye position, if that's what
you're trying to obtain:

   osg::Matrix m( getCamera()->getViewMatrix() );
   osg::Vec3 eye( m(3,0), m(3,1), m(3.2) );

(OK, I might have row versus column order messed up, so swap the row and
column parameters if needed.)
    -Paul


What I'm actually trying to obtain is the line-of-sight in world space going from eye point to the where the mouse cursor points to. Any hints on that particular problem?

Well, your original message below seems to be on the right track, but you only mentioned trouble computing the eye position. What happens when you use the mouse click position as input to your function below? And then use the eye position as computed above, and create a ray from that? Doesn't that work for you?

If What you have below doesn't work and you're unable to debug it using normal debugging techniques... I guess I'd code it slightly different. I would try something like this instead:

osg::Vec4 ndc;
ndc[0] = winX / viewport.width * 2. - 1.;
ndc[1] = winY / viewport.height * 2. - 1.;
ndc[2] = -1.;
ndc[3] = 1.;
osg::Vec3 oc = ndc * projectionInverse * modelViewInverse;

This is pretty much straight out of the Mesa implementation for gluUnProject.
   -Paul


Volker Poplawski wrote:
Hi everyone.

I'm trying to calculate the line-of-sight line in world space, which
involves mapping from window space. My approach works in principal,
however the resulting positions are allways off by a small amount.

Inside a osg::View I have:

Matrixd m;
m.preMult(getCamera()->getViewport()->computeWindowMatrix());
m.preMult(getCamera()->getProjectionMatrix());
m.preMult(getCamera()->getViewMatrix());
Matrixd inv;
inv.invert(m);


For example: I exspect
Vec3d( winWidth/2, winHeight/2, 0.0 ) * inv ;

to yield the camera/eye position. However the x,y,z coords differ in
about 0.5% from the eyepos of getCamera()->getViewMatrixAsLookAt().
(Unless the camera is positioned in world origin)


Do I miss something?


Regards
......Volker





_______________________________________________
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

Reply via email to