Hi,

Am 13.09.10 10:39, schrieb Robert Osfield:
> I kinda like this idea, it's not too intrusive w.r.t osgGA.  However,
> in terms of event handlers receiving events I would have thought you'd
> want to get all the events for a single multi-touch together, since if
> you are getting them one by one you'd need to have a start and stop
> event so you'd know how to accumulate.
> 
> How about a composite GUIEventType, or one that forms a linked list,
> and you just pass the head around.

Yes you are right, that's a problem with my last approach. Perhaps it's
best to add a ref_ptr to GuiEventAdapter holding a custom structure with
all touch-points with their positions, tapCounts and Ids.

(after a while)

So I tried that approach, I did not use a linked list of
GUIEventAdapters, as they would store too much information for a single
touchpoint (like scrolling and tablet-information, etc).

Instead I added a new class called TouchData which basically holds a
list of structs of { touch-id, touch-phase, x, y, tap-count}. The
GUIEventAdapter holds only a ref_ptr to this class, so the overhead for
osgGUIEventAdapter is not too much. I added some convenience-methods to
EventQueue and GUIEventAdapter.

To add multiple touch-points to a GUIEventAdapter you'll basically do
something along these lines:

osg::ref_ptr<osgGA::GUIEventAdapter> osg_event(NULL);

for(int i=0; i<numTouches; i++)
{
    float x = ...
    float y = ...
    float id = ...
    osgGA::GUIEventAdapter::TouchPhase phase = ...

    if (!osg_event) {
        // touchBegan, touchMoved, or touchEnded
        osg_event = _win->getEventQueue()->touchMoved(id, phase,x, y);
    } else {
        osg_event->addTouchPoint(id, phase, x, y);
    }
}

The current implementations set the x and y properties of the
GUIEventAdapter from the first touch point, so we get some basic
compatibility to existing manipulators (basically a one button mouse).

To get the touch-points from inside your event-handler:

if (ea.isMultiTouchEvent())
{
    osgGA::GUIEventAdapter::TouchData* data = ea.getTouchData();
    for(
        osgGA::GUIEventAdapter::TouchData::iterator i = data->begin();
        i != data->end();
        ++i)
    {
        std::cout
          << " id: " << i->id
          << " phase: " << i->phase
          << " pos: " << i->x << "/" << i->y
          << " tapCount:" << i->tapCount
          << std::endl;
     }
}

I hope this design makes more sense. You can find this approach in the
git-repository / iphone-branch.


cheers,
Stephan

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to