root/OpenSceneGraph/trunk/src/osgGA/GUIEventAdapter.cpp @ 11934

Revision 11934, 3.3 kB (checked in by robert, 4 years ago)

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 )"

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgGA/GUIEventAdapter>
15
16using namespace osgGA;
17
18
19osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
20{
21    static osg::ref_ptr<GUIEventAdapter> s_eventState = new GUIEventAdapter;
22    return s_eventState;
23}
24
25GUIEventAdapter::GUIEventAdapter():
26    _handled(false),
27    _eventType(NONE),
28    _time(0.0),
29    _windowX(0),
30    _windowY(0),
31    _windowWidth(1280),
32    _windowHeight(1024),
33    _key(0),
34    _button(0),
35    _Xmin(-1.0),
36    _Xmax(1.0),
37    _Ymin(-1.0),
38    _Ymax(1.0),
39    _mx(0.0),
40    _my(0.0),
41    _buttonMask(0),
42    _modKeyMask(0),
43    _mouseYOrientation(Y_INCREASING_DOWNWARDS),
44    _scrolling(),
45    _tabletPen(),
46    _touchData(NULL)
47{}
48
49GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
50    osg::Object(rhs,copyop),
51    _handled(rhs._handled),
52    _eventType(rhs._eventType),
53    _time(rhs._time),
54    _context(rhs._context),
55    _windowX(rhs._windowX),
56    _windowY(rhs._windowY),
57    _windowWidth(rhs._windowWidth),
58    _windowHeight(rhs._windowHeight),
59    _key(rhs._key),
60    _button(rhs._button),
61    _Xmin(rhs._Xmin),
62    _Xmax(rhs._Xmax),
63    _Ymin(rhs._Ymin),
64    _Ymax(rhs._Ymax),
65    _mx(rhs._mx),
66    _my(rhs._my),
67    _buttonMask(rhs._buttonMask),
68    _modKeyMask(rhs._modKeyMask),
69    _mouseYOrientation(rhs._mouseYOrientation),
70    _scrolling(rhs._scrolling),
71    _tabletPen(rhs._tabletPen),
72    _touchData(rhs._touchData)
73{}
74
75GUIEventAdapter::~GUIEventAdapter()
76{
77}
78
79void GUIEventAdapter::setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange)
80{
81    _windowX = x;
82    _windowY = y;
83    _windowWidth = width;
84    _windowHeight = height;
85   
86    if (updateMouseRange)
87    {
88        setInputRange(0, 0, width, height);
89    }
90   
91}
92
93void GUIEventAdapter::setInputRange(float Xmin, float Ymin, float Xmax, float Ymax)
94{
95    _Xmin = Xmin;
96    _Ymin = Ymin;
97    _Xmax = Xmax;
98    _Ymax = Ymax;
99}
100
101const osg::Matrix GUIEventAdapter::getPenOrientation() const
102{
103    float xRad = osg::DegreesToRadians ( getPenTiltY() );
104    float yRad = osg::DegreesToRadians ( getPenTiltX() );
105    float zRad = osg::DegreesToRadians ( getPenRotation() );
106    osg::Matrix xrot = osg::Matrix::rotate ( xRad, osg::Vec3f(1.0f, 0.0f, 0.0f) );
107    osg::Matrix yrot = osg::Matrix::rotate ( yRad, osg::Vec3f(0.0f, 0.0f, 1.0f) );
108    osg::Matrix zrot = osg::Matrix::rotate ( zRad, osg::Vec3f(0.0f, 1.0f, 0.0f) );
109   
110    return ( zrot * yrot * xrot );
111}
112
113void GUIEventAdapter::addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount)
114{
115    if (!_touchData.valid()) {
116        _touchData = new TouchData();
117        setX(x);
118        setY(y);
119    }
120   
121    _touchData->addTouchPoint(id, phase, x, y, tapCount);
122}
Note: See TracBrowser for help on using the browser.