TuioEar can now detect a tap, implemented picking feature. If a selectable node is tapped at that is set as the new focusNode and the camera does a panning to that direction. If not will the camera zoom in towards the focusNode

This commit is contained in:
Jonathan Bosson
2017-03-31 14:39:05 -06:00
parent a5873c3002
commit 7b23c17b10
5 changed files with 69 additions and 15 deletions

View File

@@ -65,15 +65,22 @@ class TuioEar : public TUIO::TuioListener {
void refresh(TUIO::TuioTime frameTime);
std::vector<TUIO::TuioCursor> getInput();
bool tap();
TUIO::TuioCursor getTap();
void clearInput();
private:
bool _tap;
TUIO::TuioCursor _tapCo = TUIO::TuioCursor(-1, -1, -1.0f, -1.0f);
std::mutex _mx;
TUIO::TuioClient *_tuioClient;
TUIO::OscReceiver *_oscReceiver;
std::vector<TUIO::TuioCursor> _list;
std::vector<int> _removeList;
std::mutex _mx;
};
#endif // __OPENSPACE_MODULE_TOUCH___TOUCHWRAPPER___H__

View File

@@ -84,6 +84,8 @@ void TouchInteraction::update(const std::vector<TuioCursor>& list, std::vector<P
_directTouchMode = false;
trace(list);
interpret(list, lastProcessed);
accelerate(list, lastProcessed);
}
@@ -168,14 +170,23 @@ void TouchInteraction::interpret(const std::vector<TuioCursor>& list, const std:
}
}
if (list.size() == 1) {
if (!cursor.isMoving())
std::cout << "cursor was moving but has now stopped\n";
_action.rot = true;
_action.pinch = false;
_action.pan = false;
_action.roll = false;
_action.pick = false;
//std::cout << "Tap: " << cursor.getSessionID() << ". (" << cursor.getX() << "," << cursor.getY() << "), Speed: "
//<< cursor.getMotionSpeed() << ", Path: " << cursor.getPath().size() << ", Time: " << cursor.getPath().back().getTuioTime().getTotalMilliseconds()
//<< ", lastTime: " << lastProcessed.at(0).second.getTuioTime().getTotalMilliseconds() << "\n";
if (!cursor.isMoving() && cursor.getPath().size() == 1) { // tap
_action.rot = false;
_action.pinch = false;
_action.pan = false;
_action.roll = false;
_action.pick = true;
}
else {
_action.rot = true;
_action.pinch = false;
_action.pan = false;
_action.roll = false;
_action.pick = false;
}
}
else {
if (std::abs(dist - lastDist)/list.at(0).getMotionSpeed() < 0.01 && list.size() == 2) {
@@ -204,7 +215,7 @@ void TouchInteraction::interpret(const std::vector<TuioCursor>& list, const std:
void TouchInteraction::accelerate(const std::vector<TuioCursor>& list, const std::vector<Point>& lastProcessed) {
TuioCursor cursor = list.at(0);
if (!_action.rot) {
if (!_action.rot || !_action.pick) {
_centroid.x = std::accumulate(list.begin(), list.end(), 0.0f, [](double x, const TuioCursor& c) { return x + c.getX(); }) / list.size();
_centroid.y = std::accumulate(list.begin(), list.end(), 0.0f, [](double y, const TuioCursor& c) { return y + c.getY(); }) / list.size();
}
@@ -243,7 +254,19 @@ void TouchInteraction::accelerate(const std::vector<TuioCursor>& list, const std
_vel.localRoll += -rollFactor * _sensitivity.localRoll;
}
if (_action.pick) { // pick something in the scene as focus node
if (_selected.size() == 1 && _selected.at(0).second != _focusNode) {
_focusNode = _selected.at(0).second; // rotate camera to look at new focus
OsEng.interactionHandler().setFocusNode(_focusNode);
glm::dvec3 camToFocus = glm::normalize(_camera->positionVec3() - _focusNode->worldPosition());
double angleX = glm::orientedAngle(_camera->viewDirectionWorldSpace(), camToFocus, _camera->lookUpVectorWorldSpace());
double angleY = glm::orientedAngle(_camera->viewDirectionWorldSpace(), camToFocus, glm::normalize(_camera->rotationQuaternion() * glm::dvec3(1,0,0)));
std::cout << "x: " << angleX << ", y: " << angleY << "\n";
_vel.localRot = 3.0 * _sensitivity.localRot * glm::dvec2(-angleX, -angleY);
}
else {
_vel.zoom = _sensitivity.zoom * glm::distance(_camera->positionVec3(), _camera->focusPositionVec3());
}
}
}

View File

@@ -48,7 +48,6 @@ void TuioEar::removeTuioObject(TuioObject *tobj) { }
void TuioEar::addTuioCursor(TuioCursor *tcur) {
_mx.lock();
// find same id in _list if it exists in _removeList (new input with same ID as a previously stored)
int i = tcur->getSessionID();
std::vector<int>::iterator foundID = std::find_if(
@@ -74,6 +73,7 @@ void TuioEar::addTuioCursor(TuioCursor *tcur) {
void TuioEar::updateTuioCursor(TuioCursor *tcur) {
_mx.lock();
_tap = false;
int i = tcur->getSessionID();
std::find_if(
_list.begin(),
@@ -87,8 +87,12 @@ void TuioEar::updateTuioCursor(TuioCursor *tcur) {
// save id to be removed and remove it in clearInput
void TuioEar::removeTuioCursor(TuioCursor *tcur) {
_mx.lock();
if (tcur->getPath().size() < 3 && tcur->getMotionSpeed() < 0.05) {
_tapCo = TuioCursor(*tcur);
_tap = true;
}
_removeList.push_back(tcur->getSessionID());
//LINFO("To be removed: " << _removeFromList.size() << "\n");
_mx.unlock();
}
@@ -105,6 +109,20 @@ std::vector<TuioCursor> TuioEar::getInput() {
return _list;
}
bool TuioEar::tap() {
std::lock_guard<std::mutex> lock(_mx);
if (_tap) {
_tap = false;
return !_tap;
}
else
return _tap;
}
TuioCursor TuioEar::getTap() {
return _tapCo;
}
void TuioEar::clearInput() {
_mx.lock();
_list.erase(

View File

@@ -71,8 +71,15 @@ bool TouchModule::gotNewInput() {
) == list.end(); }),
lastProcessed.end());
// Return true if we got new input
// Tap
if (list.size() == 0 && lastProcessed.size() == 0 && ear->tap()) {
TuioCursor c = ear->getTap();
list.push_back(c);
lastProcessed.push_back(std::make_pair(c.getSessionID(), c.getPath().back()));
return true;
}
// Return true if we got new input
if (list.size() == lastProcessed.size() && list.size() > 0) {
bool newInput = true;
for_each(lastProcessed.begin(), lastProcessed.end(), [this, &newInput](Point& p) {

View File

@@ -41,7 +41,6 @@ public:
bool gotNewInput();
//TouchInteraction touch;
TuioEar* ear;