osgEarth 2.1.1
Public Member Functions | Protected Member Functions | Protected Attributes

osgEarth::Util::IntersectingDragger Class Reference

List of all members.

Public Member Functions

 IntersectingDragger ()
virtual void setupDefaultGeometry ()
virtual bool handle (const osgManipulator::PointerInfo &pi, const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
void setNode (osg::Node *node)
osg::Node * getNode () const
void setColor (const osg::Vec4 &color)
const osg::Vec4 & getColor () const
void setPickColor (const osg::Vec4 &color)
const osg::Vec4 & getPickColor () const
float getSize () const
void setSize (float size)
virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)

Protected Member Functions

bool getHit (const osg::Vec3d &start, const osg::Vec3d &end, osg::Vec3d &intersection)
void setDrawableColor (const osg::Vec4f &color)
virtual ~IntersectingDragger ()

Protected Attributes

osg::Vec4 _color
osg::Vec4 _pickColor
osg::Vec3d _startPoint
float _size
osg::Matrixd _localToWorld
osg::Matrixd _worldToLocal
osg::ref_ptr< osg::ShapeDrawable > _shapeDrawable
osg::ref_ptr< osg::Node > _node

Detailed Description

Definition at line 47 of file Draggers.


Constructor & Destructor Documentation

IntersectingDragger::IntersectingDragger ( )

Definition at line 58 of file Draggers.cpp.

                                        :
osgManipulator::Dragger(),
_size(5.0f)
{
    setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
    setPickColor(osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f));
}

Here is the call graph for this function:

IntersectingDragger::~IntersectingDragger ( ) [protected, virtual]

Definition at line 66 of file Draggers.cpp.

{
}

Member Function Documentation

const osg::Vec4& osgEarth::Util::IntersectingDragger::getColor ( ) const [inline]

Definition at line 63 of file Draggers.

{ return _color; }
bool IntersectingDragger::getHit ( const osg::Vec3d &  start,
const osg::Vec3d &  end,
osg::Vec3d &  intersection 
) [protected]

Definition at line 89 of file Draggers.cpp.

{
    if (_node.valid())
    {
        osg::ref_ptr<osgUtil::LineSegmentIntersector> lsi = new osgUtil::LineSegmentIntersector(start,end);

        osgUtil::IntersectionVisitor iv(lsi.get());

        _node->accept(iv);

        if (lsi->containsIntersections())
        {
            OE_DEBUG << "Got get hit at " << start << " to " << end << std::endl;
            intersection = lsi->getIntersections().begin()->getWorldIntersectPoint();
            return true;
        }
    }

    OE_DEBUG << "Warning:  Couldn't get hit at " << start << " to " << end << std::endl;
    return false;
}

Here is the caller graph for this function:

osg::Node* osgEarth::Util::IntersectingDragger::getNode ( ) const [inline]

Definition at line 58 of file Draggers.

{ return _node.get(); }
const osg::Vec4& osgEarth::Util::IntersectingDragger::getPickColor ( ) const [inline]

Definition at line 68 of file Draggers.

{ return _pickColor; }    
float osgEarth::Util::IntersectingDragger::getSize ( ) const [inline]

Gets the size of the dragger

Definition at line 73 of file Draggers.

{ return _size;}
bool IntersectingDragger::handle ( const osgManipulator::PointerInfo &  pi,
const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  us 
) [virtual]

Handle pick events on dragger and generate TranslateInLine commands.

Definition at line 117 of file Draggers.cpp.

{
    // Check if the dragger node is in the nodepath.
    //if (!pointer.contains(this)) return false; 


    switch (ea.getEventType())
    {
        // Pick start.
        case (osgGA::GUIEventAdapter::PUSH):
            {
                osg::NodePath nodePathToRoot;
                computeNodePathToRoot(*this,nodePathToRoot);
                _localToWorld = osg::computeLocalToWorld(nodePathToRoot);
                _worldToLocal.invert( _localToWorld );

                osg::Vec3d near, far, hit;
                pointer.getNearFarPoints(near, far);
                if (getHit(near, far, hit))
                {
                    _startPoint = hit;
                   
                    // Generate the motion command.
                    osg::ref_ptr<TranslateCommand> cmd = new TranslateCommand();
                    cmd->setTranslation(osg::Vec3d(0,0,0));
                    cmd->setStage(osgManipulator::MotionCommand::START);
                    cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);

                    // Dispatch command.
                    dispatch(*cmd);

                    cmd = new TranslateCommand();
                    hit = hit * _worldToLocal;
                    osg::Vec3d start = getMatrix().getTrans() * _worldToLocal;                    
                    osg::Vec3d translation = hit - start;
                    cmd->setTranslation(translation);
                    cmd->setStage(osgManipulator::MotionCommand::MOVE);
                    cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);

                    // Dispatch command.
                    dispatch(*cmd);

                    setDrawableColor( _pickColor );

                    aa.requestRedraw();
                }                 
                return true; 
            }
            
        // Pick move.
        case (osgGA::GUIEventAdapter::DRAG):
            {                
                osg::Vec3d near, far, hit;
                pointer.getNearFarPoints(near, far);
                if (getHit(near, far, hit))
                {
                    // Generate the motion command.
                    osg::ref_ptr<TranslateCommand> cmd = new TranslateCommand();
                    hit = hit * _worldToLocal;
                    osg::Vec3d start = _startPoint * _worldToLocal;
                    osg::Vec3d translation = hit - start;
                    cmd->setTranslation(translation);
                    cmd->setStage(osgManipulator::MotionCommand::MOVE);
                    cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);

                    // Dispatch command.
                    dispatch(*cmd);

                    aa.requestRedraw();
                }           
                return true; 
            }
            
        // Pick finish.
        case (osgGA::GUIEventAdapter::RELEASE):
            {             
                osg::ref_ptr<TranslateCommand> cmd = new TranslateCommand();
                cmd->setStage(osgManipulator::MotionCommand::FINISH);
                cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);

                // Dispatch command.
                dispatch(*cmd);

                // Reset color.
                setDrawableColor(_color);

                aa.requestRedraw();

                return true;
            }
        default:
            return false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IntersectingDragger::handle ( const osgGA::GUIEventAdapter &  ea,
osgGA::GUIActionAdapter &  aa 
) [virtual]

Definition at line 212 of file Draggers.cpp.

{
    //This is essentialy the same as the original Dragger handle code except for it checks for "all" intersections and not just the first one.
    //This allows you to turn depth testing off and have control points that might be obstructed by a mountain still be clickable.
    if (ea.getHandled()) return false;

    osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
    if (!view) return false;

    bool handled = false;

    bool activationPermitted = true;
    if (_activationModKeyMask!=0 || _activationKeyEvent!=0)
    {
        _activationPermittedByModKeyMask = (_activationModKeyMask!=0) ?
            ((ea.getModKeyMask() & _activationModKeyMask)!=0) :
            false;

        if (_activationKeyEvent!=0)
        {
            switch (ea.getEventType())
            {
                case osgGA::GUIEventAdapter::KEYDOWN:
                {
                    if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = true;
                    break;
                }
                case osgGA::GUIEventAdapter::KEYUP:
                {
                    if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = false;
                    break;
                }
                default:
                    break;
            }
        }

        activationPermitted =  _activationPermittedByModKeyMask || _activationPermittedByKeyEvent;

    }

    if (activationPermitted || _draggerActive)
    {
        switch (ea.getEventType())
        {
            case osgGA::GUIEventAdapter::PUSH:
            {
                osgUtil::LineSegmentIntersector::Intersections intersections;

                _pointer.reset();

                if (view->computeIntersections(ea.getX(),ea.getY(),intersections))
                {
                    for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
                        hitr != intersections.end();
                        ++hitr)
                    {
                        _pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
                    }
                    
                    for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
                        hitr != intersections.end();
                        ++hitr)
                    {
                        for (osg::NodePath::const_iterator itr = hitr->nodePath.begin();
                            itr != hitr->nodePath.end();
                            ++itr)
                        {
                            osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
                            if (dragger)
                            {
                                if (dragger==this)
                                {
                                    osg::Camera *rootCamera = view->getCamera();
                                    osg::NodePath nodePath = _pointer._hitList.front().first;
                                    osg::NodePath::reverse_iterator ritr;
                                    for(ritr = nodePath.rbegin();
                                        ritr != nodePath.rend();
                                        ++ritr)
                                    {
                                        osg::Camera* camera = dynamic_cast<osg::Camera*>(*ritr);
                                        if (camera && (camera->getReferenceFrame()!=osg::Transform::RELATIVE_RF || camera->getParents().empty()))
                                        {
                                            rootCamera = camera;
                                            break;
                                        }
                                    }

                                    _pointer.setCamera(rootCamera);
                                    _pointer.setMousePosition(ea.getX(), ea.getY());

                                    dragger->handle(_pointer, ea, aa);
                                    dragger->setDraggerActive(true);
                                    handled = true;
                                }
                            }
                        }
                    }
                }
            }
            case osgGA::GUIEventAdapter::DRAG:
            case osgGA::GUIEventAdapter::RELEASE:
            {
                if (_draggerActive)
                {
                    _pointer._hitIter = _pointer._hitList.begin();
//                    _pointer.setCamera(view->getCamera());
                    _pointer.setMousePosition(ea.getX(), ea.getY());

                    handle(_pointer, ea, aa);

                    handled = true;
                }
                break;
            }
            default:
                break;
        }

        if (_draggerActive && ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
        {
            setDraggerActive(false);
            _pointer.reset();
        }
    }

    return handled;
}

Here is the call graph for this function:

void osgEarth::Util::IntersectingDragger::setColor ( const osg::Vec4 &  color) [inline]

Set/Get color for dragger.

Definition at line 61 of file Draggers.

{ _color = color; }

Here is the caller graph for this function:

void IntersectingDragger::setDrawableColor ( const osg::Vec4f &  color) [protected]

Definition at line 112 of file Draggers.cpp.

{
    if (_shapeDrawable.valid()) _shapeDrawable->setColor( color );
};

Here is the caller graph for this function:

void osgEarth::Util::IntersectingDragger::setNode ( osg::Node *  node) [inline]

Definition at line 57 of file Draggers.

{ _node = node;}

Here is the caller graph for this function:

void osgEarth::Util::IntersectingDragger::setPickColor ( const osg::Vec4 &  color) [inline]

Set/Get pick color for dragger. Pick color is color of the dragger when picked. It gives a visual feedback to show that the dragger has been picked.

Definition at line 67 of file Draggers.

{ _pickColor = color; }

Here is the caller graph for this function:

void osgEarth::Util::IntersectingDragger::setSize ( float  size) [inline]

Sets the size of the dragger

Definition at line 78 of file Draggers.

{ _size = size; }

Here is the caller graph for this function:

void IntersectingDragger::setupDefaultGeometry ( ) [virtual]

Definition at line 71 of file Draggers.cpp.

{
    //Build the handle
    osg::Sphere* shape = new osg::Sphere(osg::Vec3(0,0,0), _size);   
    osg::Geode* geode = new osg::Geode();
    _shapeDrawable = new osg::ShapeDrawable( shape );    
    geode->addDrawable( _shapeDrawable.get() );
    setDrawableColor( _color );

    geode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
    geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    osg::AutoTransform* at = new osg::AutoTransform;
    at->setAutoScaleToScreen( true );
    at->addChild( geode );
    addChild( at );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 89 of file Draggers.

Definition at line 93 of file Draggers.

osg::ref_ptr< osg::Node > osgEarth::Util::IntersectingDragger::_node [protected]

Definition at line 98 of file Draggers.

Definition at line 90 of file Draggers.

osg::ref_ptr< osg::ShapeDrawable > osgEarth::Util::IntersectingDragger::_shapeDrawable [protected]

Definition at line 96 of file Draggers.

Definition at line 92 of file Draggers.

Definition at line 91 of file Draggers.

Definition at line 94 of file Draggers.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines