Skip to content
Browse files

tweak tap function

  • Loading branch information...
1 parent f201959 commit 5461ab7e5c9a26493f3adb464cfc6bdfc200b5f0 @hideyukisaito hideyukisaito committed Mar 12, 2013
Showing with 120 additions and 23 deletions.
  1. +23 −0 arsUI.xcodeproj/project.pbxproj
  2. +20 −8 src/ArsUIButton.cpp
  3. +7 −3 src/ArsUIButton.h
  4. +50 −3 src/ArsUIMapControlState.cpp
  5. +10 −2 src/ArsUIMapControlState.h
  6. +10 −7 src/ArsUIRoboCam.cpp
View
23 arsUI.xcodeproj/project.pbxproj
@@ -45,6 +45,7 @@
AB27023516EECF4C000AC44E /* ofxEasingQuint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB27022116EECF4C000AC44E /* ofxEasingQuint.cpp */; };
AB27023616EECF4C000AC44E /* ofxEasingSine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB27022316EECF4C000AC44E /* ofxEasingSine.cpp */; };
AB27023716EECF4C000AC44E /* ofxTween.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB27022516EECF4C000AC44E /* ofxTween.cpp */; };
+ AB27024316EF62F6000AC44E /* ofxTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB27024116EF62F6000AC44E /* ofxTimer.cpp */; };
AB47ADA016D73C9C00C50356 /* ArsUIButton.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB47AD9E16D73C9C00C50356 /* ArsUIButton.cpp */; };
AB47ADFD16DB355500C50356 /* ArsUIRoboCam.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB47ADFB16DB355500C50356 /* ArsUIRoboCam.cpp */; };
BBAB23CB13894F3D00AA2426 /* GLUT.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = BBAB23BE13894E4700AA2426 /* GLUT.framework */; };
@@ -245,6 +246,8 @@
AB27022416EECF4C000AC44E /* ofxEasingSine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxEasingSine.h; sourceTree = "<group>"; };
AB27022516EECF4C000AC44E /* ofxTween.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxTween.cpp; sourceTree = "<group>"; };
AB27022616EECF4C000AC44E /* ofxTween.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxTween.h; sourceTree = "<group>"; };
+ AB27024116EF62F6000AC44E /* ofxTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxTimer.cpp; sourceTree = "<group>"; };
+ AB27024216EF62F6000AC44E /* ofxTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxTimer.h; sourceTree = "<group>"; };
AB47AD9E16D73C9C00C50356 /* ArsUIButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArsUIButton.cpp; sourceTree = "<group>"; };
AB47AD9F16D73C9C00C50356 /* ArsUIButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArsUIButton.h; sourceTree = "<group>"; };
AB47ADFB16DB355500C50356 /* ArsUIRoboCam.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArsUIRoboCam.cpp; sourceTree = "<group>"; };
@@ -680,9 +683,28 @@
path = Easings;
sourceTree = "<group>";
};
+ AB27023F16EF62F6000AC44E /* ofxTimer */ = {
+ isa = PBXGroup;
+ children = (
+ AB27024016EF62F6000AC44E /* src */,
+ );
+ name = ofxTimer;
+ path = ../../../addons/ofxTimer;
+ sourceTree = "<group>";
+ };
+ AB27024016EF62F6000AC44E /* src */ = {
+ isa = PBXGroup;
+ children = (
+ AB27024116EF62F6000AC44E /* ofxTimer.cpp */,
+ AB27024216EF62F6000AC44E /* ofxTimer.h */,
+ );
+ path = src;
+ sourceTree = "<group>";
+ };
BB4B014C10F69532006C3DED /* addons */ = {
isa = PBXGroup;
children = (
+ AB27023F16EF62F6000AC44E /* ofxTimer */,
421D843316EF59680067F004 /* ofxUI */,
421D83D416EF59550067F004 /* ofxJSON */,
AB2701F216EECF4B000AC44E /* ofxTween */,
@@ -914,6 +936,7 @@
421D842716EF59550067F004 /* json_value.cpp in Sources */,
421D842816EF59550067F004 /* json_writer.cpp in Sources */,
421D842916EF59550067F004 /* ofxJSONElement.cpp in Sources */,
+ AB27024316EF62F6000AC44E /* ofxTimer.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
28 src/ArsUIButton.cpp
@@ -34,24 +34,24 @@ void ArsUIButton::draw(){
ofColor c1(255,255,255,255);
ofColor c2(0,0,0,200);
- float distanceToFuji = sqrt((x-fuji.x)*(x-fuji.x) + (y-fuji.y)*(y-fuji.y));
- distanceToFuji +=100;
+ float distanceToFuji = sqrt((x - fuji.x) * (x - fuji.x) + (y - fuji.y) * (y - fuji.y));
+ distanceToFuji += 100;
ofPath path;
path.setCurveResolution(120);
path.setColor( ofColor(50, 200, 255,40));
path.moveTo(x,y);
- float angle1 = 360 -( 360 * currentDirection/(PI*2) + viewAngle/2) ;
- float angle2 = 360 - (360 * currentDirection/(PI*2) - viewAngle/2) ;
- path.arc(x,y,distanceToFuji,distanceToFuji,angle1,angle2);
+ float angle1 = 360 - (360 * currentDirection / (PI * 2) + viewAngle / 2) ;
+ float angle2 = 360 - (360 * currentDirection / (PI * 2) - viewAngle / 2) ;
+ path.arc(x, y, distanceToFuji, distanceToFuji, angle1, angle2);
- if(status ==0){
+ if(status == 0){
c = c0;
}else if (status == 1){
c = c1;
radius *= 2;
path.draw();
- }else if (status ==2){
+ }else if (status == 2){
c = c2;
}
@@ -78,8 +78,20 @@ int ArsUIButton::tapped(float _x, float _y){
return -1;
}
+void ArsUIButton::setPosition(ofPoint pos)
+{
+ x = pos.x;
+ y = pos.y;
+}
+
+ofPoint ArsUIButton::getPosition()
+{
+ return ofPoint(x, y);
+}
+
//return radian
-double ArsUIButton::calcDirection(ofPoint *_p1, ofPoint *_p2){
+double ArsUIButton::calcDirection(ofPoint *_p1, ofPoint *_p2)
+{
double v1[] = {100.0, 0};
double v2[] = { _p2->x - _p1->x, _p2->y - _p1->y };
double cosTheta,theta,innerProduct;
View
10 src/ArsUIButton.h
@@ -4,9 +4,9 @@
class ArsUIButton
{
protected:
- int status,bcnt,speed,tcnt; //status 0: not selected, 1:selected, 2: broken
- ofImage mark,markShadow;
- float x,y,radius;
+ int status, bcnt, speed, tcnt; //status 0: not selected, 1:selected, 2: broken
+ ofImage mark, markShadow;
+ float x, y, radius;
int bid;
ofPoint fuji;
double directionToFuji; //radian
@@ -21,6 +21,10 @@ class ArsUIButton
virtual void draw();
virtual void update();
virtual int tapped(float _x, float _y);
+
+ void setPosition(ofPoint pos);
+ ofPoint getPosition();
+
void setAngle(float _angle);
void setStatus(int _status);
int getStatus();
View
53 src/ArsUIMapControlState.cpp
@@ -40,6 +40,9 @@ void ArsUIMapControlState::stateEnter()
robos.push_back(ArsUIRoboCam(ofRandom(ofGetWidth()), ofRandom(ofGetHeight() - 100), i, fujiPoint, ofRandom(20, 60)));
}
+ cam1Position = ofPoint(robos[0].getPosition().x, robos[0].getPosition().y);
+ cam2Position = ofPoint(robos[1].getPosition().x, robos[1].getPosition().y);
+
eye[0] = -1;
eye[1] = -1;
selectedMode = 0;
@@ -50,6 +53,8 @@ void ArsUIMapControlState::stateEnter()
ofAddListener(getSharedData().tuioClient.cursorRemoved, this, &ArsUIMapControlState::tuioRemoved);
ofAddListener(getSharedData().tuioClient.cursorUpdated, this, &ArsUIMapControlState::tuioUpdated);
ofAddListener(getSharedData().oscReceiverFromServer.onMessageReceived, this, &ArsUIMapControlState::onOscMessageReceived);
+
+ ofAddListener(timer.TIMER_REACHED, this, &ArsUIMapControlState::timerReached);
}
//--------------------------------------------------------------
@@ -63,6 +68,10 @@ void ArsUIMapControlState::stateExit()
ofRemoveListener(getSharedData().tuioClient.cursorRemoved, this, &ArsUIMapControlState::tuioRemoved);
ofRemoveListener(getSharedData().tuioClient.cursorUpdated, this, &ArsUIMapControlState::tuioUpdated);
ofRemoveListener(getSharedData().oscReceiverFromServer.onMessageReceived, this, &ArsUIMapControlState::onOscMessageReceived);
+
+ ofRemoveListener(timer.TIMER_REACHED, this, &ArsUIMapControlState::timerReached);
+ timer.stopTimer();
+ timer.~ofxTimer();
}
//--------------------------------------------------------------
@@ -83,9 +92,10 @@ void ArsUIMapControlState::update()
buttons[i].update();
}
- for (int i = 0; i < robos.size(); ++i) {
- robos[i].update();
- }
+ robos[0].setPosition(cam1Position);
+ robos[1].setPosition(cam2Position);
+ robos[0].update();
+ robos[1].update();
}
//--------------------------------------------------------------
@@ -187,6 +197,14 @@ void ArsUIMapControlState::tuioAdded(ofxTuioCursor &tuioCursor)
{
ofPoint loc = ofPoint(tuioCursor.getX() * ofGetWidth(), tuioCursor.getY() * ofGetHeight());
+ cout << "TUIO added, x: " << loc.x << ", y: " << loc.y << endl;
+
+ initialTouchPoint = loc;
+ lastTouchPoint = initialTouchPoint;
+
+ timer.setup(1000, false);
+ timer.startTimer();
+
ArsUITappedPoint tappedPoint(loc.x, loc.y, tuioCursor.getFingerId());
getSharedData().tappedPoints.push_back(tappedPoint);
@@ -217,13 +235,19 @@ void ArsUIMapControlState::tuioAdded(ofxTuioCursor &tuioCursor)
void ArsUIMapControlState::tuioRemoved(ofxTuioCursor &tuioCursor)
{
ofPoint loc = ofPoint(tuioCursor.getX() * ofGetWidth(), tuioCursor.getY() * ofGetHeight());
+ cout << "TUIO removed, id: " << tuioCursor.getFingerId() << endl;
//cout << "Point n" << tuioCursor.getSessionId() << " remove at " << loc << endl;
+
+ timer.stopTimer();
}
//--------------------------------------------------------------
void ArsUIMapControlState::tuioUpdated(ofxTuioCursor &tuioCursor)
{
ofPoint loc = ofPoint(tuioCursor.getX() * ofGetWidth(), tuioCursor.getY() * ofGetHeight());
+
+ lastTouchPoint = loc;
+
//cout << "Point n" << tuioCursor.getSessionId() << " updated at " << loc << endl;
for (int i = 0; i < robos.size(); ++i) {
@@ -332,4 +356,27 @@ void ArsUIMapControlState::sendOSCToDisplay(int bid)
void ArsUIMapControlState::guiEvent(ofxUIEventArgs &e)
{
+}
+
+//--------------------------------------------------------------
+void ArsUIMapControlState::timerReached(ofEventArgs &e)
+{
+ if (lastTouchPoint.x < initialTouchPoint.x + 5 &&
+ lastTouchPoint.y < initialTouchPoint.y + 5 &&
+ lastTouchPoint.x > initialTouchPoint.x - 5 &&
+ lastTouchPoint.y > initialTouchPoint.y - 5) {
+ cout << "hold" << endl;
+ ArsUITappedPoint tappedPoint(lastTouchPoint.x, lastTouchPoint.y, 0);
+ getSharedData().tappedPoints.push_back(tappedPoint);
+
+ float dist1 = lastTouchPoint.distance(robos[0].getPosition());
+ float dist2 = lastTouchPoint.distance(robos[1].getPosition());
+
+ if (dist1 < dist2) {
+ isCam1Draggable = true;
+ } else {
+ isCam2Draggable = true;
+ }
+
+ }
}
View
12 src/ArsUIMapControlState.h
@@ -9,7 +9,7 @@
#ifndef arsUI_MapControlState_h
#define arsUI_MapControlState_h
-#define GUI_CANVAS_WIDTH 350
+#define GUI_CANVAS_WIDTH 200
#define GUI_CANVAS_HEIGHT ofGetHeight()
#include "ofxState.h"
@@ -20,6 +20,7 @@
#include "ofxJSONElement.h"
#include "ofxUI.h"
#include "ArsUIUtil.h"
+#include "ofxTimer.h"
class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
{
@@ -57,7 +58,9 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
ofImage fujiMap;
ofPoint fujiPoint;
-
+
+ ofPoint cam1Position, cam2Position;
+
int eye[2]; //0:right 1:left
int selectedMode;//0:select right eye, 1:select left eye
void setEye(int bid);
@@ -70,6 +73,11 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
void setupGUI();
ofxUICanvas *gui;
void guiEvent(ofxUIEventArgs &e);
+
+ ofxTimer timer;
+ void timerReached(ofEventArgs &e);
+ ofPoint initialTouchPoint, lastTouchPoint;
+ bool isCam1Draggable, isCam2Draggable;
};
#endif
View
17 src/ArsUIRoboCam.cpp
@@ -6,6 +6,7 @@ ArsUIRoboCam::ArsUIRoboCam(float _x, float _y, int _bid, ofPoint _fuji,float _an
void ArsUIRoboCam::update(){
ArsUIButton::update();
+ dragAngle(x, y);
}
void ArsUIRoboCam::draw(){
@@ -24,12 +25,12 @@ void ArsUIRoboCam::draw(){
path.setCurveResolution(60);
path.setColor( ofColor(255, 255, 0,40));
path.moveTo(x,y);
- float angle1 = 360 -( 360 * currentDirection/(PI*2) + viewAngle/2) ;
+ float angle1 = 360 - (360 * currentDirection/(PI*2) + viewAngle/2) ;
float angle2 = 360 - (360 * currentDirection/(PI*2) - viewAngle/2) ;
- path.arc(x,y,distanceToFuji,distanceToFuji,angle1,angle2);
+ path.arc(x, y, distanceToFuji, distanceToFuji, angle1, angle2);
- if(status ==0){
+ if(status == 0){
c = c0;
}else if (status == 1){
c = c1;
@@ -38,8 +39,8 @@ void ArsUIRoboCam::draw(){
path.draw();
}
- ofSetColor(255, 255, 255,200);
- ofLine(x, y, x + cos(currentDirection) *lineLength ,y - sin(currentDirection)*lineLength);
+ ofSetColor(255, 255, 255, 200);
+ ofLine(x, y, x + cos(currentDirection) * lineLength, y - sin(currentDirection) * lineLength);
//ofDrawBitmapString(ofToString(bid), x,y+50);
ofSetColor(c);
@@ -66,8 +67,10 @@ void ArsUIRoboCam::draw(){
}
-int ArsUIRoboCam::tapped(float _x, float _y){
- int _bid = ArsUIButton::tapped(_x,_y);
+int ArsUIRoboCam::tapped(float _x, float _y)
+{
+ int _bid = ArsUIButton::tapped(_x, _y);
+
if (_bid != -1 && status ==1){
setDefaultAngle();
}

0 comments on commit 5461ab7

Please sign in to comment.
Something went wrong with that request. Please try again.