Hi Harold,
> osg::Vec3d screen Coords = _refPoint * viewMatrix * projectionMatrix *
> windowMatrix;
If model matrix is identity, above formula should work. Are you sure your point
is in the frustum ? Do you see it ? If you do, then maybe you skipped model
matrix (are there any Transforms set as ancestors?) Or maybe one of the
matrices in your formula (most probably view or projection) has changed since
you retrieved it ? View matrix is updated by manipulators in event traversal,
if you read it before there is a chance it got updated. I guess auto NEAR/FAR
projection adjustment should not matter here, but to be really safe, check if
DO_NOT_COMPUTE_NEAR_FAR camera flag changes anything. Also, to be 100% sure I
would check windowMatrix under debugger if it really corresponds to your
expected viewport.
You should get the same results with vec4 and vec3. If you use 4d coords make
sure to divide xyz by w before retrieving 3d coord part.
Wojtek
----- Original Message -----
From: Harold Comere
To: OpenSceneGraph Users
Sent: Friday, September 04, 2009 2:45 PM
Subject: Re: [osg-users] world space to screen space & matrices understanding
Hi Wojciech,
Thanks for your answer.
I did what you suggest at my first try following an old topic about this
subject. But as i had not understand why it uses a premult i changed it, thanks
for explanation.
If i use this code, i get near good result, using Vec3d instead of Vec4d with
homogeneous coordinates
osg::Vec3d screenCoords = _refPoint * viewMatrix * projectionMatrix *
windowMatrix;
i get screen coords ( 1069, 970, 1. ) but my viewport is ( 0, 0, 1024, 768
).
The refPoint is in the view frustum so this result is not valid too :-x
If i use a Vec4d to have homogeneous coordinates, i get a worth result ...
i'm a bit confused.
Regards,
Harold
2009/9/4 Wojciech Lewandowski <[email protected]>
Hi Harold,
OSG uses standard C arrays to store matrices. Which means these are row
major matrices. This changes order of operands. You should multiply point by
matrix not matrix by point. In your code you should rather preMultiply the
matrices.
example:
osg::Matrix viewMatrix = camera->getViewMatrix();
osg::Vec3d viewSpacePoint = worldSpacePoint * viewMatrix;
Cheers,
Wojtek Lewandowski
----- Original Message -----
From: Harold Comere
To: [email protected]
Sent: Friday, September 04, 2009 1:30 PM
Subject: [osg-users] world space to screen space & matrices understanding
Hi all,
I'm trying to simply project any 3D point ,which is already in world
space, into screen space.
I know how to do it without osg :
screen space coords = bias matrix * camera projection matrix * camera
view matrix * world space coordinates
Those coordinates are in [0, 1] range, so multiply by viewport dimensions
to get window coordinates.
but i do not succeed doing it with osg because i m still not familiar
with it...
My current code is
osg::Camera * cam = _view->getCamera();
osg::Matrix viewMatrix = cam->getViewMatrix();
osg::Matrix projectionMatrix = cam->getProjectionMatrix();
osg::Matrix windowMatrix = cam->getViewport()->computeWindowMatrix();
osg::Vec4d screenCoords = windowMatrix.postMult
(projectionMatrix.postMult (viewMatrix.postMult (_refPoint)));
I saw windowMatrix is the bias matrix and the viewport scale.
refPoint is a Vec4d with w = 1. ( the 3D point i want to project into
screen space ) and as operator * is not defined to multiply a Matrix with an
Vec4d, i use postMult function.
But i dont get a valid result... what did i missed ? :-x
Thanks for your attention
Regards,
Harold
--------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
------------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org