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
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
begin:vcard fn:Per Rosengren n:Rosengren;Per org:Royal Institute of Technology (KTH);Computational Vision and Active Perception Laboratory adr:;;Teknikringen 14, room 621;Stockholm;;11428;Sweden email;internet:[EMAIL PROTECTED] title:Ph.D. student tel;work:+46 8 7906203 note:PGP keyID: 0xD40DD8E0 x-mozilla-html:FALSE url:http://www.csc.kth.se/~perrose/ version:2.1 end:vcard
signature.asc
Description: OpenPGP digital signature
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

