From: Thomas Geymayer Date: Fri, 4 Jan 2013 23:44:19 +0000 (+0100) Subject: Fix canvas mouse intersection test X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8a9693a28e88739aff5a22e17a4adec70ae71746;p=simgear.git Fix canvas mouse intersection test Bounding box of drawables use other coordinate frame then bounding sphere of MatrixTransform... --- diff --git a/simgear/canvas/CanvasEventVisitor.cxx b/simgear/canvas/CanvasEventVisitor.cxx index 777434a4..d931f40b 100644 --- a/simgear/canvas/CanvasEventVisitor.cxx +++ b/simgear/canvas/CanvasEventVisitor.cxx @@ -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; diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 485c162d..b0f84d55 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -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; } diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 28a04e02..39bdd2bc 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -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 getMatrixTransform();