@@ -1013,34 +1013,24 @@ namespace MWRender
1013
1013
mScreenshotManager ->screenshot (image, w, h);
1014
1014
}
1015
1015
1016
- osg::Vec4f RenderingManager::getScreenBounds (const osg::BoundingBox& worldbb )
1016
+ osg::Vec2f RenderingManager::getScreenCoords (const osg::BoundingBox& bb )
1017
1017
{
1018
- if (!worldbb.valid ())
1019
- return osg::Vec4f ();
1020
- osg::Matrix viewProj = mViewer ->getCamera ()->getViewMatrix () * mViewer ->getCamera ()->getProjectionMatrix ();
1021
- float min_x = 1 .0f , max_x = 0 .0f , min_y = 1 .0f , max_y = 0 .0f ;
1022
- for (int i = 0 ; i < 8 ; ++i)
1018
+ if (bb.valid ())
1023
1019
{
1024
- osg::Vec3f corner = worldbb.corner (i);
1025
- corner = corner * viewProj;
1026
-
1027
- float x = (corner.x () + 1 .f ) * 0 .5f ;
1028
- float y = (corner.y () - 1 .f ) * (-0 .5f );
1029
-
1030
- if (x < min_x)
1031
- min_x = x;
1032
-
1033
- if (x > max_x)
1034
- max_x = x;
1035
-
1036
- if (y < min_y)
1037
- min_y = y;
1038
-
1039
- if (y > max_y)
1040
- max_y = y;
1020
+ const osg::Matrix viewProj
1021
+ = mViewer ->getCamera ()->getViewMatrix () * mViewer ->getCamera ()->getProjectionMatrix ();
1022
+ const osg::Vec3f worldPoint ((bb.xMin () + bb.xMax ()) * 0 .5f , (bb.yMin () + bb.yMax ()) * 0 .5f , bb.zMax ());
1023
+ const osg::Vec4f clipPoint = osg::Vec4f (worldPoint, 1 .0f ) * viewProj;
1024
+ if (clipPoint.w () > 0 .f )
1025
+ {
1026
+ const float screenPointX = (clipPoint.x () / clipPoint.w () + 1 .f ) * 0 .5f ;
1027
+ const float screenPointY = (clipPoint.y () / clipPoint.w () - 1 .f ) * (-0 .5f );
1028
+ if (screenPointX >= 0 .f && screenPointX <= 1 .f && screenPointY >= 0 .f && screenPointY <= 1 .f )
1029
+ return osg::Vec2f (screenPointX, screenPointY);
1030
+ }
1041
1031
}
1042
1032
1043
- return osg::Vec4f (min_x, min_y, max_x, max_y );
1033
+ return osg::Vec2f ( 0 . 5f , 0 . f );
1044
1034
}
1045
1035
1046
1036
RenderingManager::RayResult getIntersectionResult (osgUtil::LineSegmentIntersector* intersector,
0 commit comments