| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include "TUIOInputModule.h"
- #include <Polycode.h>
- TUIOInputModule::TUIOInputModule(int port) : PolycodeModule(), TuioListener() {
- tuioClient = new TuioClient(port);
- tuioClient->addTuioListener(this);
- tuioClient->connect();
-
- eventMutex = CoreServices::getInstance()->getCore()->createMutex();
- _requiresUpdate = true;
- }
- TUIOInputModule::~TUIOInputModule() {
- tuioClient->removeAllTuioListeners();
- tuioClient->disconnect();
- delete tuioClient;
- delete eventMutex;
- }
- void TUIOInputModule::addTuioObject(TuioObject *tobj) {
- }
- void TUIOInputModule::updateTuioObject(TuioObject *tobj) {
- }
- void TUIOInputModule::removeTuioObject(TuioObject *tobj) {
- }
- void TUIOInputModule::addTuioCursor(TuioCursor *tcur) {
- std::vector<TouchInfo> touches;
- std::list<TuioCursor*> cursorList = tuioClient->getTuioCursors();
- tuioClient->lockCursorList();
- for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) {
- TuioCursor *tuioCursor = (*iter);
- TouchInfo touch;
- touch.position.x = tuioCursor->getX();
- touch.position.y = tuioCursor->getY();
- touch.id= tuioCursor->getCursorID();
- touches.push_back(touch);
- }
- tuioClient->unlockCursorList();
- TUIOEvent event;
- event.type = InputEvent::EVENT_TOUCHES_BEGAN;
- event.touches = touches;
-
- CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
- events.push_back(event);
- CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
- }
- void TUIOInputModule::updateTuioCursor(TuioCursor *tcur) {
- std::vector<TouchInfo> touches;
- std::list<TuioCursor*> cursorList = tuioClient->getTuioCursors();
- tuioClient->lockCursorList();
- for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) {
- TuioCursor *tuioCursor = (*iter);
- TouchInfo touch;
- touch.position.x = tuioCursor->getX();
- touch.position.y = tuioCursor->getY();
- touch.id= tuioCursor->getCursorID();
- touches.push_back(touch);
- }
- tuioClient->unlockCursorList();
- TUIOEvent event;
- event.type = InputEvent::EVENT_TOUCHES_MOVED;
- event.touches = touches;
-
- CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
- events.push_back(event);
- CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
- }
- void TUIOInputModule::removeTuioCursor(TuioCursor *tcur) {
- std::vector<TouchInfo> touches;
- std::list<TuioCursor*> cursorList = tuioClient->getTuioCursors();
- tuioClient->lockCursorList();
- for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) {
- TuioCursor *tuioCursor = (*iter);
- TouchInfo touch;
- touch.position.x = tuioCursor->getX();
- touch.position.y = tuioCursor->getY();
- touch.id= tuioCursor->getCursorID();
- touches.push_back(touch);
- }
- tuioClient->unlockCursorList();
- TUIOEvent event;
- event.type = InputEvent::EVENT_TOUCHES_ENDED;
- event.touches = touches;
-
- CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
- events.push_back(event);
- CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
- }
- void TUIOInputModule::refresh(TuioTime frameTime) {
- }
- void TUIOInputModule::Update(Number elapsed) {
- CoreServices::getInstance()->getCore()->lockMutex(eventMutex);
- for(int i=0; i < events.size(); i++) {
- for(int j=0; j < events[i].touches.size(); j++) {
- events[i].touches[j].position.x = events[i].touches[j].position.x * CoreServices::getInstance()->getCore()->getXRes();
- events[i].touches[j].position.y = events[i].touches[j].position.y * CoreServices::getInstance()->getCore()->getYRes();
- }
- switch(events[i].type) {
- case InputEvent::EVENT_TOUCHES_BEGAN:
- CoreServices::getInstance()->getCore()->getInput()->touchesBegan(events[i].touches);
- break;
- case InputEvent::EVENT_TOUCHES_MOVED:
- CoreServices::getInstance()->getCore()->getInput()->touchesMoved(events[i].touches);
- break;
- case InputEvent::EVENT_TOUCHES_ENDED:
- CoreServices::getInstance()->getCore()->getInput()->touchesEnded(events[i].touches);
- break;
- }
- }
- events.clear();
- CoreServices::getInstance()->getCore()->unlockMutex(eventMutex);
- }
|