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 <[email protected]>
> *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

Reply via email to