From Stephan Huber, "attached you'll find a proposal for handling multi-touch-events with

osgGA. My approach is to bundle all touchpoints into one custom data
structure which is attached to an GUIEventAdapter.

The current approach simulates a moving mouse for the first touch-point,
so basic manipulators do work, sort of.

I created a MultiTouchTrackballManipulator-class, one touch-point does
rotate the view, two touch-points pan and zoom the view as known from
the iphone or other similar multi-touch-devices. A double-tap (similar
to a double-click) resets the manipulator to its home-position.

The multi-touch-trackball-implementation is not the best, see it as a
first starting point. (there's a demo-video at http://vimeo.com/15017377 )"
This commit is contained in:
Robert Osfield
2010-11-22 17:30:44 +00:00
parent 27afe58f77
commit e36c4d3a3b
7 changed files with 325 additions and 4 deletions

View File

@@ -157,6 +157,22 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
/** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings, with specified time.*/
void keyRelease(int key, double time);
GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y) {
return touchBegan(id, phase, x, y, getTime());
}
GUIEventAdapter* touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
GUIEventAdapter* touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y) {
return touchMoved(id, phase, x, y, getTime());
}
GUIEventAdapter* touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count, double time);
GUIEventAdapter* touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count) {
return touchEnded(id, phase, x, y, tap_count, getTime());
}
/** Method for adapting close window events.*/

View File

@@ -255,6 +255,62 @@ public:
ERASER
};
enum TouchPhase
{
TOUCH_UNKNOWN,
TOUCH_BEGAN,
TOUCH_MOVED,
TOUCH_STATIONERY,
TOUCH_ENDED
};
class TouchData : public osg::Referenced {
public:
struct TouchPoint {
unsigned int id;
TouchPhase phase;
float x, y;
unsigned int tapCount;
TouchPoint() : id(0), phase(TOUCH_UNKNOWN), x(0.0f), y(0.0f), tapCount(0) {}
TouchPoint(unsigned int in_id, TouchPhase in_phase, float in_x, float in_y, unsigned int in_tap_count)
: id(in_id),
phase(in_phase),
x(in_x),
y(in_y),
tapCount(in_tap_count)
{
}
};
typedef std::vector<TouchPoint> TouchSet;
typedef TouchSet::iterator iterator;
typedef TouchSet::const_iterator const_iterator;
TouchData() : osg::Referenced() {}
unsigned int getNumTouchPoints() const { return _touches.size(); }
iterator begin() { return _touches.begin(); }
const_iterator begin() const { return _touches.begin(); }
iterator end() { return _touches.end(); }
const_iterator end() const { return _touches.end(); }
const TouchPoint get(unsigned int i) const { return _touches[i]; }
protected:
void addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tap_count) {
_touches.push_back(TouchPoint(id, phase, x, y, tap_count));
}
TouchSet _touches;
friend class GUIEventAdapter;
};
public:
GUIEventAdapter();
@@ -443,7 +499,11 @@ public:
/// set the orientation from a tablet input device as a matrix.
const osg::Matrix getPenOrientation() const;
void addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount = 0);
TouchData* getTouchData() const { return _touchData; }
bool isMultiTouchEvent() const { return (_touchData.valid()); }
protected:
/** Force users to create on heap, so that multiple referencing is safe.*/
@@ -489,7 +549,8 @@ public:
TabletPen(const TabletPen& rhs) : pressure(rhs.pressure), tiltX(rhs.tiltX), tiltY(rhs.tiltY), rotation(rhs.rotation), tabletPointerType(rhs.tabletPointerType) {}
};
TabletPen _tabletPen;
osg::ref_ptr<TouchData> _touchData;
};
}

View File

@@ -0,0 +1,47 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGGA_MULTITOUCH_TRACKBALL_MANIPULATOR
#define OSGGA_MULTITOUCH_TRACKBALL_MANIPULATOR 1
#include <osgGA/TrackballManipulator>
namespace osgGA {
class OSGGA_EXPORT MultiTouchTrackballManipulator : public TrackballManipulator
{
typedef TrackballManipulator inherited;
public:
MultiTouchTrackballManipulator( int flags = DEFAULT_SETTINGS );
MultiTouchTrackballManipulator( const MultiTouchTrackballManipulator& tm,
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
META_Object( osgGA, MultiTouchTrackballManipulator );
bool handle( const GUIEventAdapter& ea, GUIActionAdapter& us );
protected:
void handleMultiTouchDrag(GUIEventAdapter::TouchData* now, GUIEventAdapter::TouchData* last, const double eventTimeDelta);
osg::ref_ptr<GUIEventAdapter::TouchData> _lastTouchData;
};
}
#endif /* OSGGA_MULTITOUCH_TRACKBALL_MANIPULATOR */