]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/CameraGroup.cxx
GUI picks only traverse nodes with PICK_BIT set.
[flightgear.git] / src / Viewer / CameraGroup.cxx
index 3d84717e5b8316e85c737c33e30afe337c8c6b97..7d903a5a179b6b0505fc21f4a0a320ee76ac6af5 100644 (file)
@@ -27,6 +27,8 @@
 #include "FGEventHandler.hxx"
 #include "WindowBuilder.hxx"
 #include "WindowSystemAdapter.hxx"
+
+#include <simgear/math/SGRect.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/structure/OSGUtils.hxx>
 #include <simgear/structure/OSGVersion.hxx>
@@ -754,6 +756,7 @@ CameraInfo* CameraGroup::buildCamera(SGPropertyNode* cameraNode)
         return 0;
     }
     Camera* camera = new Camera;
+    camera->setName("windowCamera");
     camera->setAllowEventFocus(false);
     camera->setGraphicsContext(window->gc.get());
     camera->setViewport(new Viewport);
@@ -1018,6 +1021,7 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode,
     const int cameraFlags = GUI | DO_INTERSECTION_TEST;
 
     CameraInfo* result = new CameraInfo(cameraFlags);
+    result->name = "GUI camera";
     // The camera group will always update the camera
     camera->setReferenceFrame(Transform::ABSOLUTE_RF);
 
@@ -1142,34 +1146,34 @@ Camera* getGUICamera(CameraGroup* cgroup)
     return info->getCamera(MAIN_CAMERA);
 }
 
-static bool computeCameraIntersection(const CameraInfo* cinfo,
-                                      const osgGA::GUIEventAdapter* ea,
+
+static bool computeCameraIntersection(const CameraInfo* cinfo, const osg::Vec2d& windowPos,
                                       osgUtil::LineSegmentIntersector::Intersections& intersections)
 {
   using osgUtil::Intersector;
   using osgUtil::LineSegmentIntersector;
-  double x, y;
-  eventToWindowCoords(ea, x, y);
-  
+
   if (!(cinfo->flags & CameraGroup::DO_INTERSECTION_TEST))
     return false;
   
   const Camera* camera = cinfo->getCamera(MAIN_CAMERA);
   if ( !camera )
     camera = cinfo->getCamera( GEOMETRY_CAMERA );
-  if (camera->getGraphicsContext() != ea->getGraphicsContext())
-    return false;
+  // if (camera->getGraphicsContext() != ea->getGraphicsContext())
+ //   return false;
   
   const Viewport* viewport = camera->getViewport();
+  SGRect<double> viewportRect(viewport->x(), viewport->y(),
+                              viewport->x() + viewport->width() - 1.0,
+                              viewport->y() + viewport->height()- 1.0);
+    
   double epsilon = 0.5;
-  if (!(x >= viewport->x() - epsilon
-        && x < viewport->x() + viewport->width() -1.0 + epsilon
-        && y >= viewport->y() - epsilon
-        && y < viewport->y() + viewport->height() -1.0 + epsilon))
+  if (!viewportRect.contains(windowPos.x(), windowPos.y(), epsilon))
     return false;
   
-  Vec4d start(x, y, 0.0, 1.0);
-  Vec4d end(x, y, 1.0, 1.0);
+  Vec4d start(windowPos.x(), windowPos.y(), 0.0, 1.0);
+  Vec4d end(windowPos.x(), windowPos.y(), 1.0, 1.0);
   Matrix windowMat = viewport->computeWindowMatrix();
   Matrix startPtMat = Matrix::inverse(camera->getProjectionMatrix()
                                       * windowMat);
@@ -1189,7 +1193,8 @@ static bool computeCameraIntersection(const CameraInfo* cinfo,
                                Vec3d(start.x(), start.y(), start.z()),
                                Vec3d(end.x(), end.y(), end.z()));
   osgUtil::IntersectionVisitor iv(picker.get());
-  iv.setTraversalMask( ~simgear::MODELLIGHT_BIT );
+  iv.setTraversalMask( simgear::PICK_BIT );
+    
   const_cast<Camera*>(camera)->accept(iv);
   if (picker->containsIntersections()) {
     intersections = picker->getIntersections();
@@ -1200,12 +1205,12 @@ static bool computeCameraIntersection(const CameraInfo* cinfo,
 }
   
 bool computeIntersections(const CameraGroup* cgroup,
-                          const osgGA::GUIEventAdapter* ea,
+                          const osg::Vec2d& windowPos,
                           osgUtil::LineSegmentIntersector::Intersections& intersections)
 {
     // test the GUI first
     const CameraInfo* guiCamera = cgroup->getGUICamera();
-    if (guiCamera && computeCameraIntersection(guiCamera, ea, intersections))
+    if (guiCamera && computeCameraIntersection(guiCamera, windowPos, intersections))
         return true;
     
     // Find camera that contains event
@@ -1217,7 +1222,7 @@ bool computeIntersections(const CameraGroup* cgroup,
         if (cinfo == guiCamera)
             continue;
         
-        if (computeCameraIntersection(cinfo, ea, intersections))
+        if (computeCameraIntersection(cinfo, windowPos, intersections))
             return true;
     }