[osg-users] Converting model to screen coordinates
Per Rosengren
perrose at kth.se
Thu Jul 3 00:31:58 PDT 2008
I use an IntersectionVisitor with a customized Intersector.
The intersect function of the Intersector is called with the IntersectionVisitor
as argument. The IntersectionVisitor has all the matrices I need:
I call this function from the intersect function:
/** compute the matrix that takes this Intersector from its
* CoordinateFrame into the local MODEL coordinate frame
* that geometry in the scene graph will always be in.
*/
void EdgeFinderProjectFind::locateCamera( osgUtil::IntersectionVisitor &iv,
osg::Geometry* geometry )
{
_modelToWindowMatrix.identity();
if (iv.getWindowMatrix())
_modelToWindowMatrix.preMult( *iv.getWindowMatrix() );
if (iv.getProjectionMatrix())
_modelToWindowMatrix.preMult( *iv.getProjectionMatrix() );
if (iv.getViewMatrix())
_modelToWindowMatrix.preMult( *iv.getViewMatrix() );
if (iv.getModelMatrix())
_modelToWindowMatrix.preMult( *iv.getModelMatrix() );
}
Later I use this to get the window coordinates:
pWindow0 = p0 * _modelToWindowMatrix;
Per Rosengren
Helbig, Yuen wrote:
> Hello,
>
> I'm trying to convert from model coordinates to screen coordinates with
> the following code:
>
> // Compute the model to screen transformation matrix
> osgUtil::SceneView* sv = m_sHandler->getSceneView();
> osg::Matrix modelView = sv->getViewMatrix();
> osg::Matrix projection = sv->getProjectionMatrix();
> osg::Matrix window = sv->getViewport()->computeWindowMatrix();
> osg::Matrix MVPW = modelView * projection * window;
>
> // convert a point in model coordinates to screen coordinates
> osg::Vec3 screenPoint = modelPoint * MVPW;
>
>
> The resulting screen coordinate point is correct in the x-dimension, but
> scaled down incorrectly in the y-dimension. The only point that is
> correct is the center point of the model.
>
> Am I missing a matrix somewhere? or does anyone have an alternate
> method of doing this?
>
>
> Yuen Helbig
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: perrose.vcf
Type: text/x-vcard
Size: 375 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080703/eb737ee0/attachment-0003.vcf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080703/eb737ee0/attachment-0003.pgp>
More information about the osg-users
mailing list