Skip to content

Commit 14dac2f

Browse files
FIX: TouchGestureManager 2-finger zoom
1 parent 6f75156 commit 14dac2f

File tree

2 files changed

+95
-6
lines changed

2 files changed

+95
-6
lines changed

include/omicron/TouchGestureManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**************************************************************************************************
22
* THE OMICRON PROJECT
33
*-------------------------------------------------------------------------------------------------
4-
* Copyright 2010-2014 Electronic Visualization Laboratory, University of Illinois at Chicago
4+
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
55
* Authors:
66
* Arthur Nishimoto [email protected]
77
*-------------------------------------------------------------------------------------------------
8-
* Copyright (c) 2010-2014, Electronic Visualization Laboratory, University of Illinois at Chicago
8+
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
99
* All rights reserved.
1010
* Redistribution and use in source and binary forms, with or without modification, are permitted
1111
* provided that the following conditions are met:
@@ -165,9 +165,9 @@ namespace omicron {
165165
void setNextID( int ID );
166166

167167
void generatePQServiceEvent(Event::Type eventType, TouchGroup* touchGroup, int advancedGesture);
168+
void generateZoomEvent(Event::Type eventType, TouchGroup* touchGroup, float deltaDistance);
168169
//void generatePQServiceEvent(Event::Type eventType, Touch touch, int advancedGesture);
169170
//void generatePQServiceEvent(Event::Type eventType, Touch mainTouch, map<int, Touch> touchList, int advancedGesture);
170-
//void generateZoomEvent(Event::Type eventType, Touch touch, map<int, Touch> touchList, float deltaDistance);
171171
private:
172172
Service* pqsInstance;
173173
Lock* touchListLock;

src/omicron/omicron/TouchGestureManager.cpp

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**************************************************************************************************
22
* THE OMICRON PROJECT
33
*-------------------------------------------------------------------------------------------------
4-
* Copyright 2010-2018 Electronic Visualization Laboratory, University of Illinois at Chicago
4+
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
55
* Authors:
66
* Arthur Nishimoto [email protected]
77
*-------------------------------------------------------------------------------------------------
8-
* Copyright (c) 2010-2018, Electronic Visualization Laboratory, University of Illinois at Chicago
8+
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
99
* All rights reserved.
1010
* Redistribution and use in source and binary forms, with or without modification, are permitted
1111
* provided that the following conditions are met:
@@ -333,11 +333,28 @@ void TouchGroup::process(){
333333

334334
// Don't update center if list is empty to preserve touch group's position
335335
// for double click detection
336-
if (touchList.size() > 0)
336+
if (getTouchCount() > 0)
337337
{
338338
centerTouch.xPos = newCenterX;
339339
centerTouch.yPos = newCenterY;
340340
}
341+
342+
// Determine the farthest point from the group center (thumb?)
343+
int farthestTouchID = -1;
344+
farthestTouchDistance = 0;
345+
346+
for (it = touchList.begin(); it != touchList.end(); it++)
347+
{
348+
Touch t = (*it).second;
349+
350+
float curDistance = sqrt(abs(centerTouch.xPos - t.xPos) * abs(centerTouch.xPos - t.xPos) + abs(centerTouch.yPos - t.yPos) * abs(centerTouch.yPos - t.yPos));
351+
if (curDistance > farthestTouchDistance) {
352+
farthestTouchDistance = curDistance;
353+
farthestTouchID = t.ID;
354+
}
355+
}
356+
357+
generateGestures();
341358
}
342359

343360
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -348,6 +365,38 @@ void TouchGroup::generateGestures(){
348365
ftime( &tb );
349366
int curTime = tb.millitm + (tb.time & 0xfffff) * 1000;
350367

368+
// Basic 2-touch zoom
369+
if (touchList.size() == 2 && idleTouchList.size() <= 1 && !zoomGestureTriggered) {
370+
zoomGestureTriggered = true;
371+
372+
initialZoomDistance = farthestTouchDistance;
373+
zoomDistance = farthestTouchDistance;
374+
zoomLastDistance = initialZoomDistance;
375+
376+
gestureManager->generateZoomEvent(Event::Down, this, 0);
377+
ofmsg("TouchGroup ID: %1% zoom start", %ID);
378+
}
379+
else if (touchList.size() < 2 && zoomGestureTriggered) {
380+
zoomGestureTriggered = false;
381+
382+
gestureManager->generateZoomEvent(Event::Up, this, 0);
383+
ofmsg("TouchGroup ID: %1% zoom end", %ID);
384+
}
385+
386+
if (zoomGestureTriggered)
387+
{
388+
zoomLastDistance = zoomDistance;
389+
zoomDistance = farthestTouchDistance;
390+
391+
float zoomDelta = (zoomDistance - zoomLastDistance) * zoomGestureMultiplier;
392+
393+
if (zoomDelta != 0)
394+
{
395+
gestureManager->generateZoomEvent(Event::Move, this, zoomDelta);
396+
//ofmsg("TouchGroup ID: %1% zoom delta: %2%", %ID %zoomDelta);
397+
}
398+
}
399+
351400
/*
352401
// Single finger gestures
353402
if( touchList.size() == 1 )
@@ -968,6 +1017,46 @@ void TouchGestureManager::generatePQServiceEvent(Event::Type eventType, TouchGro
9681017
touchGroup->unlockTouchList();
9691018

9701019

1020+
pqsInstance->unlockEvents();
1021+
1022+
}
1023+
else {
1024+
printf("TouchGestureManager: No PQService Registered\n");
1025+
}
1026+
}
1027+
1028+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1029+
void TouchGestureManager::generateZoomEvent(Event::Type eventType, TouchGroup* touchGroup, float zoomDelta)
1030+
{
1031+
if (pqsInstance) {
1032+
pqsInstance->lockEvents();
1033+
1034+
Event* evt = pqsInstance->writeHead();
1035+
1036+
Touch touch = touchGroup->getMainTouch();
1037+
Touch centerTouch = touchGroup->getCenterTouch();
1038+
map<int, Touch> groupTouchList = touchGroup->getTouchList();
1039+
1040+
evt->reset(Event::Zoom, Service::Pointer, touchGroup->getID());
1041+
evt->setPosition(Vector3f(touch.xPos, touch.yPos, 0));
1042+
evt->setOrientation(centerTouch.xPos, centerTouch.yPos, touchGroup->getDiameter(), touchGroup->getLongRangeDiameter());
1043+
evt->setFlags(GESTURE_ZOOM);
1044+
1045+
evt->setExtraDataType(Event::ExtraDataFloatArray);
1046+
evt->setExtraDataFloat(0, touch.xWidth);
1047+
evt->setExtraDataFloat(1, touch.yWidth);
1048+
evt->setExtraDataFloat(2, touch.initXPos);
1049+
evt->setExtraDataFloat(3, touch.initYPos);
1050+
1051+
switch (eventType)
1052+
{
1053+
case(Event::Down): evt->setExtraDataFloat(4, 1); break;
1054+
case(Event::Move): evt->setExtraDataFloat(4, 2); break;
1055+
case(Event::Up): evt->setExtraDataFloat(4, 3); break;
1056+
}
1057+
1058+
evt->setExtraDataFloat(5, zoomDelta);
1059+
9711060
pqsInstance->unlockEvents();
9721061

9731062
}

0 commit comments

Comments
 (0)