mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-29 07:19:28 -05:00
registerModuleCallback from touchmodule to call interaction handler
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
#include <modules/touch/ext/libTUIO2/TUIO2/TcpReceiver.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
using namespace TUIO2;
|
||||
|
||||
@@ -40,9 +40,9 @@ class TuioEar : public TuioListener {
|
||||
public:
|
||||
TuioEar();
|
||||
~TuioEar() {
|
||||
tuioClient->disconnect();
|
||||
delete tuioClient;
|
||||
delete oscReceiver;
|
||||
_tuioClient->disconnect();
|
||||
delete _tuioClient;
|
||||
delete _oscReceiver;
|
||||
}
|
||||
|
||||
void tuioAdd(TuioObject *tobj);
|
||||
@@ -50,13 +50,15 @@ class TuioEar : public TuioListener {
|
||||
void tuioRemove(TuioObject *tobj);
|
||||
void tuioRefresh(TuioTime frameTime);
|
||||
|
||||
std::vector<TuioPointer>* getInput() { return &list; }
|
||||
std::vector<TuioObject*> getInput();
|
||||
void clearInput();
|
||||
|
||||
private:
|
||||
TuioClient *tuioClient;
|
||||
OscReceiver *oscReceiver;
|
||||
std::vector<TuioPointer> list;
|
||||
std::vector<TuioPointer>::iterator it;
|
||||
TuioClient *_tuioClient;
|
||||
OscReceiver *_oscReceiver;
|
||||
|
||||
std::vector<TuioObject*> _list;
|
||||
boost::mutex _mx;
|
||||
};
|
||||
|
||||
#endif // __OPENSPACE_MODULE_TOUCH___TOUCHWRAPPER___H__
|
||||
|
||||
@@ -24,66 +24,75 @@
|
||||
|
||||
#include <modules/touch/include/TuioEar.h>
|
||||
#include <vector>
|
||||
#include <algorithm> // std::find
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/settingsengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "TuioEar";
|
||||
}
|
||||
|
||||
void TuioEar::tuioAdd(TuioObject *tobj) {
|
||||
|
||||
if (tobj->containsNewTuioToken()) LINFO("add tok " << tobj->getTuioToken()->getSessionID() << "\n");
|
||||
if (tobj->containsNewTuioPointer()) {
|
||||
list.push_back(tobj->getTuioPointer());
|
||||
LINFO("add ptr " << tobj->getTuioPointer()->getSessionID() << ", Fingers: " << list.size() << "\n");
|
||||
boost::lock_guard<boost::mutex> lock(_mx);
|
||||
_list.push_back(tobj);
|
||||
|
||||
LINFO("add ptr " << tobj->getTuioPointer()->getSessionID() << ", size: " << _list.size() << "\n");
|
||||
}
|
||||
if (tobj->containsNewTuioToken()) LINFO("add tok " << tobj->getTuioToken()->getSessionID() << "\n");
|
||||
if(tobj->containsNewTuioBounds()) LINFO("add bnd " << tobj->getTuioBounds()->getSessionID() << "\n");
|
||||
if(tobj->containsNewTuioSymbol()) LINFO("add sym " << tobj->getTuioSymbol()->getSessionID() << "\n");
|
||||
//std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/"<< tobj->getTuioSourceID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;
|
||||
//std::cout << std::flush;
|
||||
}
|
||||
|
||||
void TuioEar::tuioUpdate(TuioObject *tobj) {
|
||||
if (tobj->containsTuioPointer()) {
|
||||
boost::lock_guard<boost::mutex> lock(_mx);
|
||||
_list.push_back(tobj);
|
||||
|
||||
LINFO("set ptr " << tobj->getTuioPointer()->getSessionID() << ", size: " << _list.size() << "\n");
|
||||
}
|
||||
if (tobj->containsTuioToken()) LINFO("set tok " << tobj->getTuioToken()->getSessionID() << "\n");
|
||||
if (tobj->containsTuioPointer()) LINFO("set ptr " << tobj->getTuioPointer()->getSessionID() << "\n");
|
||||
if (tobj->containsTuioBounds()) LINFO("set bnd " << tobj->getTuioBounds()->getSessionID() << "\n");
|
||||
if (tobj->containsTuioSymbol()) LINFO("set sym " << tobj->getTuioSymbol()->getSessionID() << "\n");
|
||||
//std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/"<< tobj->getTuioSourceID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << " " << tobj->getMotionSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
|
||||
//std::cout << std::flush;
|
||||
}
|
||||
|
||||
void TuioEar::tuioRemove(TuioObject *tobj) {
|
||||
if (tobj->containsTuioToken()) LINFO("del tok " << tobj->getTuioToken()->getSessionID() << "\n");
|
||||
|
||||
if (tobj->containsTuioPointer()) {
|
||||
it = list.begin();
|
||||
for (; it != list.end(); ++it) {
|
||||
if (it->getSessionID() == tobj->getTuioPointer()->getSessionID()) {
|
||||
list.erase(it);
|
||||
LINFO("del ptr " << tobj->getTuioPointer()->getSessionID() << ", Fingers: " << list.size() << "\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
LINFO("del ptr " << tobj->getTuioPointer()->getSessionID() << ", size: " << _list.size() << "\n");
|
||||
}
|
||||
|
||||
if (tobj->containsTuioToken()) LINFO("del tok " << tobj->getTuioToken()->getSessionID() << "\n");
|
||||
if (tobj->containsTuioBounds()) LINFO("del bnd " << tobj->getTuioBounds()->getSessionID() << "\n");
|
||||
if (tobj->containsTuioSymbol()) LINFO("del sym " << tobj->getTuioSymbol()->getSessionID() << "\n");
|
||||
//std::cout << "del obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << "/"<< tobj->getTuioSourceID() << ")" << std::endl;
|
||||
//std::cout << std::flush;
|
||||
}
|
||||
|
||||
void TuioEar::tuioRefresh(TuioTime frameTime) {
|
||||
LINFO("refresh " << frameTime.getFrameID() << " "<< frameTime.getTotalMilliseconds() << "\n");
|
||||
}
|
||||
|
||||
TuioEar::TuioEar() {
|
||||
oscReceiver = new UdpReceiver(3333);
|
||||
//oscReceiver = new TcpReceiver("127.0.0.1",3333);
|
||||
tuioClient = new TuioClient(oscReceiver);
|
||||
tuioClient->addTuioListener(this);
|
||||
tuioClient->connect();
|
||||
std::vector<TuioObject*> TuioEar::getInput() {
|
||||
boost::lock_guard<boost::mutex> lock(_mx);
|
||||
return _list;
|
||||
}
|
||||
|
||||
void TuioEar::clearInput() {
|
||||
boost::lock_guard<boost::mutex> lock(_mx);
|
||||
_list.clear();
|
||||
}
|
||||
|
||||
TuioEar::TuioEar() {
|
||||
_oscReceiver = new UdpReceiver(3333);
|
||||
//oscReceiver = new TcpReceiver("127.0.0.1",3333);
|
||||
_tuioClient = new TuioClient(_oscReceiver);
|
||||
_tuioClient->addTuioListener(this);
|
||||
_tuioClient->connect();
|
||||
}
|
||||
|
||||
@@ -23,11 +23,91 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/touch/touchmodule.h>
|
||||
#include <modules/touch/include/TuioEar.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/settingsengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/interaction/interactionhandler.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
TuioEar TouchModule::*ear;
|
||||
|
||||
TouchModule::TouchModule()
|
||||
: OpenSpaceModule("Touch")
|
||||
{}
|
||||
{
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::Initialize,
|
||||
[]() {
|
||||
LDEBUGC("TouchModule", "Initializing TuioEar");
|
||||
ear = new TuioEar();
|
||||
}
|
||||
);
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::Deinitialize,
|
||||
[]() {
|
||||
LDEBUGC("TouchModule", "Deinitialize TuioEar");
|
||||
delete ear;
|
||||
}
|
||||
);
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::PostSyncPreDraw,
|
||||
[]() {
|
||||
WindowWrapper& wrapper = OsEng.windowWrapper();
|
||||
if (OsEng.isMaster() && wrapper.isRegularRendering()) {
|
||||
std::vector<TuioObject*> list = ear->getInput();
|
||||
std::vector<TuioObject*>::iterator it = list.begin();
|
||||
|
||||
// step through the list (from the start) and find each unique id tuioobject
|
||||
std::vector<TuioObject*> group;
|
||||
|
||||
for (auto &&i : list) {
|
||||
bool sameId = false;
|
||||
glm::vec2 centroid = glm::vec2(0.0f, 0.0f);
|
||||
if (i->containsTuioPointer()) {
|
||||
int id = i->getSessionID();
|
||||
for (auto &&j : group) // change to lambda/find function
|
||||
if (j->getSessionID() == id)
|
||||
sameId = true; // step out of for
|
||||
if (sameId) { // calculate a centroid
|
||||
for (auto &&j : group) {
|
||||
centroid.x += j->getTuioPointer()->getX();
|
||||
centroid.y += j->getTuioPointer()->getY();
|
||||
}
|
||||
centroid.x /= group.size();
|
||||
centroid.y /= group.size();
|
||||
}
|
||||
else
|
||||
group.push_back(i);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// group
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
OsEng.registerModuleCallback(
|
||||
OpenSpaceEngine::CallbackOption::PostDraw,
|
||||
[]() {
|
||||
WindowWrapper& wrapper = OsEng.windowWrapper();
|
||||
if (OsEng.isMaster() && wrapper.isRegularRendering()) {
|
||||
ear->clearInput();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -26,12 +26,15 @@
|
||||
#define __OPENSPACE_MODULE_TOUCH___TOUCHMODULE___H__
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
#include <modules/touch/include/TuioEar.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class TouchModule : public OpenSpaceModule {
|
||||
public:
|
||||
TouchModule();
|
||||
|
||||
static TuioEar *ear;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user