Fix canvas mouse intersection test
Bounding box of drawables use other coordinate frame then bounding sphere of MatrixTransform...
This commit is contained in:
parent
724fba4af9
commit
8a9693a28e
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user