Figured this out; I was unprojecting coordinates but not updating them
in the right order. So that this thread isn't completely useless, here's my
correct code for converting screen coordinates to world coordinates.
void calcNormDeviceCoords(int xScreen, int yScreen, double &xNorm,
double &yNorm)
{
xNorm = 2*double(xScreen)/double(MY_SCREEN_WIDTH) - 1;
yNorm = 1 - 2*double(yScreen)/double(MY_SCREEN_HEIGHT);
}
// dNorm = 0.0 for near plane on view frustum, dNorm = 1.0 for far plane
void convCoordScreenToWorld(double xNorm,double yNorm,
double dNorm,osg::Vec3d &worldPt)
{
osg::Camera * viewCam = MY_VIEWER->getCamera();
osg::Matrixd xfMVP(viewCam->getViewMatrix()*
viewCam->getProjectionMatrix());
osg::Matrixd xfInvMVP = osg::Matrixd::inverse(xfMVP);
worldPt = osg::Vec3d(xNorm,yNorm,dNorm) * xfInvMVP;
}
Sorry for the spam
Preet
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org