Skip to content

Commit

Permalink
EarthManip: another tweak to the tether chasing code
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 2, 2015
1 parent b965a4f commit 00a5bd6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/osgEarthUtil/EarthManipulator
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,8 @@ namespace osgEarth { namespace Util
bool _is_geocentric;
bool _srs_lookup_failed;

osg::observer_ptr<osg::Node> _tether_node;
osg::observer_ptr<osg::Node> _tether_node;
bool _tether_completed;

double _time_s_last_frame;
double _time_s_now;
Expand Down Expand Up @@ -947,7 +948,7 @@ namespace osgEarth { namespace Util
double _pending_viewpoint_duration_s;

bool _setting_viewpoint;
bool _set_viewpoint_started_while_tethered;
//bool _set_viewpoint_started_while_tethered;
Viewpoint _start_viewpoint;
double _delta_heading, _delta_pitch, _delta_range, _arc_height;
osg::Vec3d _delta_focal_point;
Expand Down
20 changes: 12 additions & 8 deletions src/osgEarthUtil/EarthManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,6 @@ EarthManipulator::setViewpoint( const Viewpoint& vp, double duration_s )
vp.getSRS()->transform( vp.getFocalPoint(), _cached_srs.get(), vpFocalPoint );
}

// if we are currently tethered, make a note of it.
_set_viewpoint_started_while_tethered = _tether_node.valid();

_start_viewpoint = getViewpoint();

_delta_heading = vp.getHeading() - _start_viewpoint.getHeading(); //TODO: adjust for crossing -180
Expand Down Expand Up @@ -991,8 +988,9 @@ EarthManipulator::updateSetViewpoint()

if ( t >= 1.0 )
{
t = tp = 1.0;
t = tp = 1.0;
_setting_viewpoint = false;
_tether_completed = true;
}
else if ( _arc_height > 0.0 )
{
Expand Down Expand Up @@ -1072,6 +1070,8 @@ EarthManipulator::getViewpoint() const
void
EarthManipulator::setTetherNode( osg::Node* node, double duration_s )
{
_tether_completed = true;

if (_tether_node != node)
{
_offset_x = 0.0;
Expand Down Expand Up @@ -1103,6 +1103,7 @@ EarthManipulator::setTetherNode( osg::Node* node, double duration_s )

if (_tether_node.valid() && duration_s > 0.0)
{
_tether_completed = false;
Viewpoint destVP = getTetherNodeViewpoint();
setViewpoint( destVP, duration_s );
}
Expand Down Expand Up @@ -1446,9 +1447,12 @@ EarthManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapt
if ( _frame_count < 2 )
_time_s_set_viewpoint = _time_s_now;

// if we're tethered, we need to update the viewpoint in the post-update
// phase to pre
if ( !_tether_node.valid() || !_set_viewpoint_started_while_tethered )
// if we're not tethered, OR if we are tethered and the tethering process
// is complete, we can update the camera now. Otherwise we have to update
// it in the post-update phase to maintain frame synchronization between
// the camera and the tether target.
if ((!_tether_node.valid()) ||
(_tether_node.valid() && !_tether_completed))
{
updateSetViewpoint();
}
Expand Down Expand Up @@ -1778,7 +1782,7 @@ EarthManipulator::updateTether()
vp.getSRS()->transform( vp.getFocalPoint(), _cached_srs.get(), vpFocalPoint );
}

if ( _set_viewpoint_started_while_tethered )
if ( _tether_completed )
{
_start_viewpoint.setFocalPoint( vpFocalPoint );
_delta_focal_point.set(0,0,0);
Expand Down

0 comments on commit 00a5bd6

Please sign in to comment.