Skip to content

Commit

Permalink
EarthManip: add a TetherCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 13, 2015
1 parent 65d4812 commit bbbd931
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/applications/osgearth_manip/osgearth_manip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ using namespace osgEarth::Annotation;

namespace
{
/**
* Tether callback test.
*/
struct TetherCB : public EarthManipulator::TetherCallback
{
void operator()(osg::Node* node)
{
if ( node ) {
OE_WARN << "Tether on\n";
}
else {
OE_WARN << "Tether off\n";
}
}
};

/**
* Builds our help menu UI.
*/
Expand Down Expand Up @@ -429,6 +445,8 @@ int main(int argc, char** argv)
osgGA::GUIEventAdapter::MODKEY_SHIFT );

manip->getSettings()->setArcViewpointTransitions( true );

manip->setTetherCallback( new TetherCB() );

viewer.addEventHandler(new FlyToViewpointHandler( manip ));
viewer.addEventHandler(new LockAzimuthHandler('u', manip));
Expand Down
16 changes: 15 additions & 1 deletion src/osgEarthUtil/EarthManipulator
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,18 @@ namespace osgEarth { namespace Util
*/
void setTetherNode( osg::Node* node, double duration_s =0.0 );

/**
* Sets a callback to be invoked upon a tether or tether break
*/
class TetherCallback : public osg::Referenced {
public:
virtual void operator()(osg::Node* tetherNode) { }
protected:
virtual ~TetherCallback() { }
};
void setTetherCallback(TetherCallback* cb) { _tetherCallback = cb; }
TetherCallback* getTetherCallback() { return _tetherCallback.get(); }

/**
* Gets the node to which the camera is tethered, or NULL if tethering is
* disabled.
Expand Down Expand Up @@ -689,7 +701,7 @@ namespace osgEarth { namespace Util
*/
void setFindNodeTraversalMask( const osg::Node::NodeMask & nodeMask ) { _findNodeTraversalMask = nodeMask; }

public: // osgGA::MatrixManipulator
public: // osgGA::CameraManipulator

virtual const char* className() const { return "EarthManipulator"; }

Expand Down Expand Up @@ -1000,6 +1012,8 @@ namespace osgEarth { namespace Util
// Traversal mask used in established and dtor methods to find MapNode and CoordinateSystemNode
osg::Node::NodeMask _findNodeTraversalMask;

osg::ref_ptr<TetherCallback> _tetherCallback;

void collisionDetect();
};

Expand Down
6 changes: 6 additions & 0 deletions src/osgEarthUtil/EarthManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,12 @@ EarthManipulator::setTetherNode( osg::Node* node, double duration_s )
Viewpoint destVP = getTetherNodeViewpoint();
setViewpoint( destVP, duration_s );
}

// invoke the callback if set
if ( _tetherCallback.valid() )
{
(*_tetherCallback.get())( _tether_node.get() );
}
}


Expand Down

0 comments on commit bbbd931

Please sign in to comment.