]> git.mxchange.org Git - simgear.git/commitdiff
Fix canvas mouse intersection test
authorThomas Geymayer <tomgey@gmail.com>
Fri, 4 Jan 2013 23:44:19 +0000 (00:44 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 4 Jan 2013 23:44:19 +0000 (00:44 +0100)
Bounding box of drawables use other coordinate frame
then bounding sphere of MatrixTransform...

simgear/canvas/CanvasEventVisitor.cxx
simgear/canvas/elements/CanvasElement.cxx
simgear/canvas/elements/CanvasElement.hxx

index 777434a4b055d49b0db19d283a236ff04c9de0f7..d931f40b10be357cabe1cdfc46b33e23506f0c70 100644 (file)
@@ -73,7 +73,7 @@ namespace canvas
       // Don't check collision with root element (2nd element in _target_path)
       // do event listeners attached to the canvas itself (its root group)
       // always get called even if no element has been hit.
-      if( _target_path.size() > 2 && !el.hitBound(local_pos) )
+      if( _target_path.size() > 2 && !el.hitBound(pos, local_pos) )
         return false;
 
       const osg::Vec2f& delta = _target_path.back().local_delta;
index 485c162d61de3192eb22837fee44bd25ffd16769..b0f84d558f1a4453c22672f69b6555b8717fa98e 100644 (file)
@@ -192,19 +192,20 @@ namespace canvas
   }
 
   //----------------------------------------------------------------------------
-  bool Element::hitBound(const osg::Vec2f& pos) const
+  bool Element::hitBound( const osg::Vec2f& pos,
+                          const osg::Vec2f& local_pos ) const
   {
     const osg::Vec3f pos3(pos, 0);
 
     // Drawables have a bounding box...
     if( _drawable )
     {
-      if( !_drawable->getBound().contains(pos3) )
+      if( !_drawable->getBound().contains(osg::Vec3f(local_pos, 0)) )
         return false;
     }
     // ... for other elements, i.e. groups only a bounding sphere is available
-    else if( !_transform->getBound().contains(pos3) )
-      return false;
+    else if( !_transform->getBound().contains(osg::Vec3f(pos, 0)) )
+        return false;
 
     return true;
   }
index 28a04e020a2ffa155f78402565f5fac392dbaa05..39bdd2bc4592d141ca3d7258630ea6ec1868bedb 100644 (file)
@@ -79,7 +79,8 @@ namespace canvas
 
       void callListeners(const canvas::EventPtr& event);
 
-      virtual bool hitBound(const osg::Vec2f& pos) const;
+      virtual bool hitBound( const osg::Vec2f& pos,
+                             const osg::Vec2f& local_pos ) const;
 
 
       osg::ref_ptr<osg::MatrixTransform> getMatrixTransform();