Skip to content

Commit

Permalink
FIX: TouchGestureManager 2-finger zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnishimoto committed Apr 7, 2019
1 parent 6f75156 commit 14dac2f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/omicron/TouchGestureManager.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**************************************************************************************************
* THE OMICRON PROJECT
*-------------------------------------------------------------------------------------------------
* Copyright 2010-2014 Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
* Authors:
* Arthur Nishimoto [email protected]
*-------------------------------------------------------------------------------------------------
* Copyright (c) 2010-2014, Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
Expand Down Expand Up @@ -165,9 +165,9 @@ namespace omicron {
void setNextID( int ID );

void generatePQServiceEvent(Event::Type eventType, TouchGroup* touchGroup, int advancedGesture);
void generateZoomEvent(Event::Type eventType, TouchGroup* touchGroup, float deltaDistance);
//void generatePQServiceEvent(Event::Type eventType, Touch touch, int advancedGesture);
//void generatePQServiceEvent(Event::Type eventType, Touch mainTouch, map<int, Touch> touchList, int advancedGesture);
//void generateZoomEvent(Event::Type eventType, Touch touch, map<int, Touch> touchList, float deltaDistance);
private:
Service* pqsInstance;
Lock* touchListLock;
Expand Down
95 changes: 92 additions & 3 deletions src/omicron/omicron/TouchGestureManager.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**************************************************************************************************
* THE OMICRON PROJECT
*-------------------------------------------------------------------------------------------------
* Copyright 2010-2018 Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright 2010-2019 Electronic Visualization Laboratory, University of Illinois at Chicago
* Authors:
* Arthur Nishimoto [email protected]
*-------------------------------------------------------------------------------------------------
* Copyright (c) 2010-2018, Electronic Visualization Laboratory, University of Illinois at Chicago
* Copyright (c) 2010-2019, Electronic Visualization Laboratory, University of Illinois at Chicago
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
Expand Down Expand Up @@ -333,11 +333,28 @@ void TouchGroup::process(){

// Don't update center if list is empty to preserve touch group's position
// for double click detection
if (touchList.size() > 0)
if (getTouchCount() > 0)
{
centerTouch.xPos = newCenterX;
centerTouch.yPos = newCenterY;
}

// Determine the farthest point from the group center (thumb?)
int farthestTouchID = -1;
farthestTouchDistance = 0;

for (it = touchList.begin(); it != touchList.end(); it++)
{
Touch t = (*it).second;

float curDistance = sqrt(abs(centerTouch.xPos - t.xPos) * abs(centerTouch.xPos - t.xPos) + abs(centerTouch.yPos - t.yPos) * abs(centerTouch.yPos - t.yPos));
if (curDistance > farthestTouchDistance) {
farthestTouchDistance = curDistance;
farthestTouchID = t.ID;
}
}

generateGestures();
}

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

// Basic 2-touch zoom
if (touchList.size() == 2 && idleTouchList.size() <= 1 && !zoomGestureTriggered) {
zoomGestureTriggered = true;

initialZoomDistance = farthestTouchDistance;
zoomDistance = farthestTouchDistance;
zoomLastDistance = initialZoomDistance;

gestureManager->generateZoomEvent(Event::Down, this, 0);
ofmsg("TouchGroup ID: %1% zoom start", %ID);
}
else if (touchList.size() < 2 && zoomGestureTriggered) {
zoomGestureTriggered = false;

gestureManager->generateZoomEvent(Event::Up, this, 0);
ofmsg("TouchGroup ID: %1% zoom end", %ID);
}

if (zoomGestureTriggered)
{
zoomLastDistance = zoomDistance;
zoomDistance = farthestTouchDistance;

float zoomDelta = (zoomDistance - zoomLastDistance) * zoomGestureMultiplier;

if (zoomDelta != 0)
{
gestureManager->generateZoomEvent(Event::Move, this, zoomDelta);
//ofmsg("TouchGroup ID: %1% zoom delta: %2%", %ID %zoomDelta);
}
}

/*
// Single finger gestures
if( touchList.size() == 1 )
Expand Down Expand Up @@ -968,6 +1017,46 @@ void TouchGestureManager::generatePQServiceEvent(Event::Type eventType, TouchGro
touchGroup->unlockTouchList();


pqsInstance->unlockEvents();

}
else {
printf("TouchGestureManager: No PQService Registered\n");
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void TouchGestureManager::generateZoomEvent(Event::Type eventType, TouchGroup* touchGroup, float zoomDelta)
{
if (pqsInstance) {
pqsInstance->lockEvents();

Event* evt = pqsInstance->writeHead();

Touch touch = touchGroup->getMainTouch();
Touch centerTouch = touchGroup->getCenterTouch();
map<int, Touch> groupTouchList = touchGroup->getTouchList();

evt->reset(Event::Zoom, Service::Pointer, touchGroup->getID());
evt->setPosition(Vector3f(touch.xPos, touch.yPos, 0));
evt->setOrientation(centerTouch.xPos, centerTouch.yPos, touchGroup->getDiameter(), touchGroup->getLongRangeDiameter());
evt->setFlags(GESTURE_ZOOM);

evt->setExtraDataType(Event::ExtraDataFloatArray);
evt->setExtraDataFloat(0, touch.xWidth);
evt->setExtraDataFloat(1, touch.yWidth);
evt->setExtraDataFloat(2, touch.initXPos);
evt->setExtraDataFloat(3, touch.initYPos);

switch (eventType)
{
case(Event::Down): evt->setExtraDataFloat(4, 1); break;
case(Event::Move): evt->setExtraDataFloat(4, 2); break;
case(Event::Up): evt->setExtraDataFloat(4, 3); break;
}

evt->setExtraDataFloat(5, zoomDelta);

pqsInstance->unlockEvents();

}
Expand Down

0 comments on commit 14dac2f

Please sign in to comment.