]> git.mxchange.org Git - flightgear.git/commitdiff
Adjustments to mouse picking API
authorJames Turner <zakalawe@mac.com>
Sun, 31 Jul 2016 21:30:58 +0000 (22:30 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:48 +0000 (23:27 +0200)
src/Input/FGMouseInput.cxx
src/Viewer/renderer.cxx
src/Viewer/renderer.hxx

index 90a5efde93bebafc0baa9a398798a05ccfc5b038..ccef542bf8631ec784f0a18305680dee1f327936 100644 (file)
@@ -77,8 +77,8 @@ void ActivePickCallbacks::init( int button, const osgGA::GUIEventAdapter* ea )
   // That is they get sorted by distance and by scenegraph depth.
   // The nearest one is the first one and the deepest
   // (the most specialized one in the scenegraph) is the first.
-  SGSceneryPicks pickList;
-  if (!globals->get_renderer()->pick(pickList, windowPos)) {
+  SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos);
+  if (pickList.empty()) {
     return;
   }
 
@@ -223,8 +223,7 @@ public:
         bool didPick = false;
 
         SGPickCallback::Priority priority = SGPickCallback::PriorityScenery;
-        SGSceneryPicks pickList;
-        globals->get_renderer()->pick(pickList, windowPos);
+        SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos);
 
         SGSceneryPicks::const_iterator i;
         for( i = pickList.begin(); i != pickList.end(); ++i )
@@ -276,8 +275,8 @@ public:
         osg::Vec2d windowPos;
         flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
 
-        SGSceneryPicks pickList;
-        if( !globals->get_renderer()->pick(pickList, windowPos) )
+        SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos);
+        if(pickList.empty())
           return;
 
         for( ActivePickCallbacks::iterator mi = activePickCallbacks.begin();
@@ -579,8 +578,7 @@ void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindo
   osg::Vec2d windowPos;
   flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
 
-  SGSceneryPicks pickList;
-  globals->get_renderer()->pick(pickList, windowPos);
+  SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos);
 
   if( updown != MOUSE_BUTTON_DOWN )
   {
index 6d18f1c8240ac6bc4d726386f4f9ca4690d0168a..e25cc417e69cecc3e7c42f913e5e54a8b06c2608 100644 (file)
@@ -1785,16 +1785,15 @@ SGVec2d uvFromIntersection(const Intersection& hit)
   return toSG( osg::Vec2d(tc1 * r1 + tc2 * r2 + tc3 * r3) );
 }
 
-bool
-FGRenderer::pick(std::vector<SGSceneryPick>& pickList, const osg::Vec2& windowPos)
+PickList FGRenderer::pick(const osg::Vec2& windowPos)
 {
-    // wipe out the return ...
-    pickList.clear();
+    PickList result;
+
     typedef osgUtil::LineSegmentIntersector::Intersections Intersections;
     Intersections intersections;
 
     if (!computeIntersections(CameraGroup::getDefault(), windowPos, intersections))
-        return false;
+        return result;
     for (Intersections::iterator hit = intersections.begin(),
              e = intersections.end();
          hit != e;
@@ -1819,12 +1818,12 @@ FGRenderer::pick(std::vector<SGSceneryPick>& pickList, const osg::Vec2& windowPo
                   sceneryPick.info.uv = uvFromIntersection(*hit);
 
                 sceneryPick.callback = pickCallback;
-                pickList.push_back(sceneryPick);
+                result.push_back(sceneryPick);
             } // of installed pick callbacks iteration
         } // of reverse node path walk
     }
     
-    return !pickList.empty();
+    return result;
 }
 
 void
index 6f560672491b4ddadf2b9bf2364e830d0ebe327d..d203df94f463f1efe5fbb40670f72f6fb6993f11 100644 (file)
@@ -44,6 +44,8 @@ class CameraGroup;
 class SGSky;
 class SGUpdateVisitor;
 
+typedef std::vector<SGSceneryPick> PickList;
+
 class FGRenderer {
 
 public:
@@ -62,7 +64,7 @@ public:
   
     /** Just pick into the scene and return the pick callbacks on the way ...
      */
-    bool pick( std::vector<SGSceneryPick>& pickList, const osg::Vec2& windowPos);
+    PickList pick(const osg::Vec2& windowPos);
 
     /** Get and set the OSG Viewer object, if any.
      */