Hi,
I have a question regarding the implementation of the multi-touch events. I am
adding multi-touch cursors through the TUIO library and handling them via a
custom osga::GUIEventHandler, which I have found from the osg recipes. The
overloaded handle() function is as follows:
Code:
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&
aa )
{
osgViewer::View* view = dynamic_cast<osgViewer::View*>( &aa );
if ( !view )
return false;
osgGA::EventQueue* queue = view->getEventQueue();
switch ( ea.getEventType() )
{
case osgGA::GUIEventAdapter::FRAME:
if ( _listener->active )
{
_listener->active = false; // FIXME: is that safe enough for
multithreading?
std::map<unsigned int, osg::Vec2d> lastIDs = _clientIDs;
std::list<TUIO::TuioCursor*> cursors = _client->getTuioCursors();
osg::ref_ptr<osgGA::GUIEventAdapter> touched;
for ( std::list<TUIO::TuioCursor*>::iterator itr=cursors.begin();
itr!=cursors.end(); ++itr )
{
TUIO::TuioCursor* c = *itr;
if ( !c ) continue;
unsigned int id = c->getCursorID();
double x = c->getX() * ea.getWindowWidth() + ea.getWindowX();
double y = (1 - c->getY()) * ea.getWindowHeight() + ea.getWindowY();
if ( _clientIDs.find(id)!=_clientIDs.end() )
{
if ( !touched ) touched = queue->touchMoved(id,
osgGA::GUIEventAdapter::TOUCH_MOVED, x, y);
else touched->addTouchPoint(id,
osgGA::GUIEventAdapter::TOUCH_MOVED, x, y);
_master->MoveCursor(id, x, y);
lastIDs.erase( id );
}
else
{
if ( !touched ) touched = queue->touchBegan(id,
osgGA::GUIEventAdapter::TOUCH_BEGAN, x, y);
else touched->addTouchPoint(id,
osgGA::GUIEventAdapter::TOUCH_BEGAN, x, y);
_master->AddCursor(id, x, y);
}
_clientIDs[id] = osg::Vec2d(x, y);
}
for ( std::map<unsigned int, osg::Vec2d>::iterator
itr=lastIDs.begin(); itr!=lastIDs.end(); ++itr )
{
// Unset IDs are going to be removed this time
double x = itr->second.x(), y = itr->second.y();
if ( !touched ) touched = queue->touchEnded(itr->first,
osgGA::GUIEventAdapter::TOUCH_ENDED, x, y, 1);
else touched->addTouchPoint(itr->first,
osgGA::GUIEventAdapter::TOUCH_ENDED, x, y, 1);
_master->EraseCursor(itr->first);
_clientIDs.erase( itr->first );
}
}
break;
default: break;
}
return false;
}
In my scene, I also have custom buttons that inherit from the osgWidget::Label
class. I overloaded its mouseOver() function and verified that the event fires
with the mouse cursor.
As far as I have understood from the previous forum posts, when there is only
one multi-touch cursor, osg treats it as a regular mouse cursor. But, I do not
observe this behavior. When I bring my single cursor on the button, the events
do not fire.
Has anybody tried to do anything similar? Am I missing something? Do I need to
update osgga implementation?
Thank you!
Cheers,
Rifat
PS. Sorry for the code formatting
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=52797#52797
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org