Show
Ignore:
Timestamp:
11/02/06 18:05:46 (8 years ago)
Author:
robert
Message:

Added convinience constructors to help support picking with the new osgUtil::Intersector classes.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgkeyboardmouse/osgkeyboardmouse.cpp

    r5683 r5684  
    192192        if (usePolytopePicking) 
    193193        { 
     194 
     195#if 0 
    194196            // use window coordinates 
    195197            // remap the mouse x,y into viewport coordinates. 
    196198            osg::Viewport* viewport = viewer->getCamera()->getViewport(); 
    197             float mx = viewport->x() + (int)((float)viewport->width()*(ea.getXnormalized()*0.5f+0.5f)); 
    198             float my = viewport->y() + (int)((float)viewport->height()*(ea.getYnormalized()*0.5f+0.5f)); 
    199  
    200             float width = 10.0f; 
    201             float height = 10.0f; 
    202  
    203             float min_x = mx - width*0.5; 
    204             float max_x = mx + width*0.5; 
    205             float min_y = my - height*0.5; 
    206             float max_y = my + height*0.5; 
    207  
    208             osg::Polytope polytope; 
    209             polytope.add(osg::Plane(1,0,0,-min_x)); 
    210             polytope.add(osg::Plane(-1,0,0,max_x)); 
    211             polytope.add(osg::Plane(0,1,0,-min_y)); 
    212             polytope.add(osg::Plane(0,-1,0,max_y)); 
    213             polytope.add(osg::Plane(0,0,1,0)); 
    214  
    215             osgUtil::PolytopeIntersector* picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, polytope ); 
    216  
     199            double mx = viewport->x() + (int)((double )viewport->width()*(ea.getXnormalized()*0.5+0.5)); 
     200            double my = viewport->y() + (int)((double )viewport->height()*(ea.getYnormalized()*0.5+0.5)); 
     201 
     202            // half width, height. 
     203            double w = 5.0f; 
     204            double h = 5.0f; 
     205            osgUtil::PolytopeIntersector* picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, mx-w, my-h, mx+w, my+h ); 
     206#else 
     207            double mx = ea.getXnormalized(); 
     208            double my = ea.getYnormalized(); 
     209            double w = 0.05; 
     210            double h = 0.05; 
     211            osgUtil::PolytopeIntersector* picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::PROJECTION, mx-w, my-h, mx+w, my+h ); 
     212#endif 
    217213            osgUtil::IntersectionVisitor iv(picker); 
    218214 
     
    236232 
    237233            #if 0 
    238             // use non dimension coordinates - in projection/clip space 
    239             osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::PROJECTION, osg::Vec3d(ea.getXnormalized(),ea.getYnormalized(),-1.0), osg::Vec3d(ea.getXnormalized(),ea.getYnormalized(),1.0) ); 
     234            // use non dimensional coordinates - in projection/clip space 
     235            osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector( osgUtil::Intersector::PROJECTION, ea.getXnormalized(),ea.getYnormalized() ); 
    240236            #else 
    241237            // use window coordinates 
     
    244240            float mx = viewport->x() + (int)((float)viewport->width()*(ea.getXnormalized()*0.5f+0.5f)); 
    245241            float my = viewport->y() + (int)((float)viewport->height()*(ea.getYnormalized()*0.5f+0.5f)); 
    246             osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, osg::Vec3d(mx,my,0.0), osg::Vec3d(mx,my,1.0) ); 
     242            osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector( osgUtil::Intersector::WINDOW, mx, my ); 
    247243            #endif 
    248244