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

@@ -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;
};
}