Classification: UNCLASSIFIED
Caveats: NONE
I've done this in a couple different systems via a Cull callback.
Down thru the first 2 outputs, the math is correct, which was the
question.
However, I need to unproject, which breaks.
This allows me offsets in screen space, yet permits world space
callbacks, which I need.
Can someone point out why my unproject is inaccurate?
I suspect I'm missing something simple.
(disclaimer on typos as I had to type it into the email)
bool myCullCallback::cull(NodeVisitor *nodeVisitor, Drawable *drawable,
RenderInfo *renderInfo) const {
Camera *camera = renderInfo->getView()->getCamera();
Matrixd modelViewMtx = *((CullVisitor *)
nodeVisitor)->getModelViewMatrix(),
projectionMtx = camera->getProjectionMatrix(),
viewPortMtx = camera->getViewport()->computeWindowMatrix();
Vec3d modelPosition = modelViewMtx->getTrans();
cout << modelPosition[0] << " " << modelPosition[1] << " " <<
modelPosition[2] << endl;
Matrixd mtx(modelViewMtx * projectionMtx * viewPortMtx);
Vec3 v = Vec3() * mtx;
cout << v[0] << " " << v[1] << " " << v[2] << endl;
Matrixd iMtx;
iMtx.invert(mtx);
v = v * iMtx;
cout << v[0] << " " << v[1] << " " << v[2] << endl << endl;
return false;
}
I get this test output:
-1160.6 25013.1 -1.4e6
838.6 553.98 0.999331
16.2 -0.34 -0.334
Thanks
Bob Buckley
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Per
Rosengren
Sent: Thursday, July 03, 2008 1:32 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Converting model to screen coordinates
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
Classification: UNCLASSIFIED
Caveats: NONE
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org