Skip to content

Commit

Permalink
Added option of allowing multi-touch drag in combination with pinch/t…
Browse files Browse the repository at this point in the history
…wist gestures.

This feels more natural if you allow multi-touch-drag to be pan or drag.
  • Loading branch information
Daniel Allen committed Sep 26, 2023
1 parent 4158e67 commit e2969c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/osgEarth/EarthManipulator
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ namespace osgEarth { namespace Util
void setZoomToMouse(bool value) { _zoomToMouse = value; }
bool getZoomToMouse() const { return _zoomToMouse; }

/** Allow multitouch drag events to be combined with pinch/twist in the same gesture */
void setAllowTouchDragCombos(bool value) { _allowTouchDragCombos = value; }
bool getAllowTouchDragCombos() const { return _allowTouchDragCombos; }

private:

friend class EarthManipulator;
Expand Down Expand Up @@ -561,6 +565,7 @@ namespace osgEarth { namespace Util
double _throwDecayRate;

bool _zoomToMouse;
bool _allowTouchDragCombos;
};

public:
Expand Down
19 changes: 13 additions & 6 deletions src/osgEarth/EarthManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ _terrainAvoidanceEnabled ( true ),
_terrainAvoidanceMinDistance ( 1.0 ),
_throwingEnabled ( false ),
_throwDecayRate ( 0.05 ),
_zoomToMouse ( false )
_zoomToMouse ( false ),
_allowTouchDragCombos ( false )
{
//NOP
}
Expand Down Expand Up @@ -329,7 +330,8 @@ _terrainAvoidanceEnabled( rhs._terrainAvoidanceEnabled ),
_terrainAvoidanceMinDistance( rhs._terrainAvoidanceMinDistance ),
_throwingEnabled( rhs._throwingEnabled ),
_throwDecayRate( rhs._throwDecayRate ),
_zoomToMouse( rhs._zoomToMouse )
_zoomToMouse( rhs._zoomToMouse ),
_allowTouchDragCombos( rhs._allowTouchDragCombos )
{
//NOP
}
Expand Down Expand Up @@ -2188,10 +2190,13 @@ EarthManipulator::parseTouchEvents( TouchEvents& output )

// Threshold in pixels for determining if a two finger drag happened.
float dragThres = 1.0f;
bool doMultiDrag = ( osg::equivalent(vec0.x(), vec1.x(), dragThres) &&
osg::equivalent(vec0.y(), vec1.y(), dragThres) ) ||
_settings->getAllowTouchDragCombos();

// now see if that corresponds to any touch events:
if (osg::equivalent(vec0.x(), vec1.x(), dragThres) &&
osg::equivalent(vec0.y(), vec1.y(), dragThres))
// First check if we should be doing the multidrag event, either because
// it was a pure drag, or because we allow it in combination with pinch/twise
if( doMultiDrag )
{
// two-finger drag.
output.push_back(TouchEvent());
Expand All @@ -2200,7 +2205,9 @@ EarthManipulator::parseTouchEvents( TouchEvents& output )
ev._dx = 0.5 * (dx[0] + dx[1]) * sens;
ev._dy = 0.5 * (dy[0] + dy[1]) * sens;
}
else

// If it wasn't a drag event, or if we allow drag combinations, do the pinch/twist
if( !doMultiDrag || _settings->getAllowTouchDragCombos() )
{
// otherwise it's a pinch and/or a zoom. You can do them together.
if (fabs(deltaDistance) > (1.0 * 0.0005 / sens))
Expand Down

0 comments on commit e2969c7

Please sign in to comment.