Skip to content
Browse files

cam is movable

  • Loading branch information...
1 parent 5461ab7 commit 3dda42fb66de8d8ba3a720b276c5d778ed77aa1a @hideyukisaito hideyukisaito committed Mar 13, 2013
View
8 src/ArsUIButton.cpp
@@ -70,9 +70,11 @@ void ArsUIButton::draw(){
ofPopMatrix();
}
-int ArsUIButton::tapped(float _x, float _y){
- double distance = sqrt( (double)((_x - x) * (_x - x) + (_y - y)*(_y - y))) ;
- if (distance < radius/2) {
+int ArsUIButton::hitTestPoint(ofPoint p)
+{
+ double distance = abs(sqrt((double)((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y))));
+
+ if (distance < radius / 2) {
return bid;
}
return -1;
View
2 src/ArsUIButton.h
@@ -20,7 +20,7 @@ class ArsUIButton
ArsUIButton(float _x, float _y, int _bid, ofPoint _fuji, float _angle );
virtual void draw();
virtual void update();
- virtual int tapped(float _x, float _y);
+ virtual int hitTestPoint(ofPoint p);
void setPosition(ofPoint pos);
ofPoint getPosition();
View
131 src/ArsUIMapControlState.cpp
@@ -24,13 +24,12 @@ ArsUIMapControlState::~ArsUIMapControlState()
void ArsUIMapControlState::init()
{
setupGUI();
- // gui->setDrawBack(false);
}
//--------------------------------------------------------------
void ArsUIMapControlState::stateEnter()
{
- fujiPoint.set(532.16, 633.19);
+ fujiPoint.set(964, 600);
for (int i = 0; i < 10; ++i) {
buttons.push_back(ArsUIButton(ofRandom(ofGetWidth()), ofRandom(ofGetHeight() - 100), i, fujiPoint, ofRandom(20, 60)));
@@ -43,18 +42,16 @@ void ArsUIMapControlState::stateEnter()
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;
+ eyes[0] = -1;
+ eyes[1] = -1;
+ selectedEye = 0;
fujiMap.loadImage("map.png");
ofAddListener(getSharedData().tuioClient.cursorAdded, this, &ArsUIMapControlState::tuioAdded);
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);
}
//--------------------------------------------------------------
@@ -68,10 +65,6 @@ 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();
}
//--------------------------------------------------------------
@@ -121,7 +114,17 @@ void ArsUIMapControlState::draw()
for (int i = 0; i < robos.size(); ++i) {
robos[i].draw();
+
+ ofPoint p = robos[i].getPosition();
+
+ ofSetColor(255, 0, 0);
+ ofLine(p.x, 0, p.x, ofGetHeight());
+ ofLine(0, p.y, ofGetWidth(), p.y);
}
+
+ ofSetColor(0, 255, 0);
+ ofLine(fujiPoint.x, 0, fujiPoint.x, ofGetHeight());
+ ofLine(0, fujiPoint.y, ofGetWidth(), fujiPoint.y);
}
//--------------------------------------------------------------
@@ -171,25 +174,25 @@ void ArsUIMapControlState::setupGUI()
//--------------------------------------------------------------
void ArsUIMapControlState::setEye(int bid)
{
- int oldMode = eye[selectedMode];
+ int lastEye = eyes[selectedEye];
- if (-1 != oldMode) {
+ if (-1 != lastEye) {
for (int i = 0; i < buttons.size(); ++i) {
- if(buttons[i].getId() == oldMode){
+ if(buttons[i].getId() == lastEye){
buttons[i].setStatus(0);
}
}
for (int i = 0; i < robos.size(); ++i) {
- if(robos[i].getId() == oldMode){
+ if(robos[i].getId() == lastEye){
robos[i].setStatus(0);
}
}
}
- eye[selectedMode] = bid;
+ eyes[selectedEye] = bid;
- selectedMode = !selectedMode ? 1 : 0;
+ selectedEye = !selectedEye ? 1 : 0;
}
//--------------------------------------------------------------
@@ -199,35 +202,46 @@ void ArsUIMapControlState::tuioAdded(ofxTuioCursor &tuioCursor)
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);
for (int i = 0; i < buttons.size(); ++i) {
- int bid = buttons[i].tapped(loc.x, loc.y);
+ int bid = buttons[i].hitTestPoint(loc);
- if (0 <= bid && bid != eye[0] && bid != eye[1]){
+ if (0 <= bid && bid != eyes[0] && bid != eyes[1]) {
setEye(bid);
buttons[i].setStatus(1);
sendOSCToDisplay(bid);
}
}
for (int i = 0; i < robos.size(); ++i) {
- int bid = robos[i].tapped(loc.x, loc.y);
+ int bid = robos[i].hitTestPoint(loc);
- if (0 <= bid && bid != eye[0] && bid != eye[1]){
+ if (0 <= bid && bid != eyes[0] && bid != eyes[1]){
setEye(bid);
robos[i].setStatus(1);
sendOSCToDisplay(bid);
}
}
+
+ ofPoint cam1Pos = robos[0].getPosition();
+ ofPoint cam2Pos = robos[1].getPosition();
+
+ float dist1 = ArsUIUtil::distance(loc, cam1Pos);
+ float dist2 = ArsUIUtil::distance(loc, cam2Pos);
+
+ if (dist1 < dist2 && dist1 <= 10) {
+ cam1TouchedStartedAt = ofGetElapsedTimeMillis();
+ cam1FingerId = tuioCursor.getFingerId();
+ cout << "CAM 1 touched, time(millis): " << cam1TouchedStartedAt << endl;
+ } else if (dist2 < dist1 && dist2 <= 10) {
+ cam2TouchedStartedAt = ofGetElapsedTimeMillis();
+ cam2FingerId = tuioCursor.getFingerId();
+ cout << "CAM 2 touched, time(millis): " << cam2TouchedStartedAt << endl;
+ }
+
// cout << "Point n" << tuioCursor.getSessionId() << " add at " << loc << endl;
}
@@ -237,22 +251,44 @@ 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();
+
+ if (tuioCursor.getFingerId() == cam1FingerId) {
+ cam1TouchedStartedAt = 0;
+ cam1FingerId = -1;
+ isCam1Draggable = false;
+ } else if (tuioCursor.getFingerId() == cam2FingerId) {
+ cam2TouchedStartedAt = 0;
+ cam2FingerId = -1;
+ isCam2Draggable = false;
+ }
}
//--------------------------------------------------------------
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;
+ // cout << "TUIO updated, id: " << tuioCursor.getFingerId() << endl;
+
+ if (0 < cam1TouchedStartedAt && 1000 <= ofGetElapsedTimeMillis() - cam1TouchedStartedAt && tuioCursor.getFingerId() == cam1FingerId) {
+ isCam1Draggable = true;
+ cam1Position = loc;
+ } else {
+ isCam1Draggable = false;
+ robos[0].dragAngle(loc.x, loc.y);
+ }
- for (int i = 0; i < robos.size(); ++i) {
- robos[i].dragAngle(loc.x, loc.y);
+ if (0 < cam2TouchedStartedAt && 1000 <= ofGetElapsedTimeMillis() - cam2TouchedStartedAt && tuioCursor.getFingerId() == cam2FingerId) {
+ isCam2Draggable = true;
+ cam2Position = loc;
+ } else {
+ isCam2Draggable = false;
+ robos[1].dragAngle(loc.x, loc.y);
}
+
+// for (int i = 0; i < robos.size(); ++i) {
+// robos[i].dragAngle(loc.x, loc.y);
+// }
}
//--------------------------------------------------------------
@@ -340,10 +376,10 @@ void ArsUIMapControlState::sendOSCToDisplay(int bid)
{
ofxOscMessage msg;
- if (1 == selectedMode) {
+ if (1 == selectedEye) {
msg.setAddress("/right/image");
msg.addStringArg("right file address");
- } else if (0 == selectedMode) {
+ } else if (0 == selectedEye) {
msg.setAddress("/left/image");
msg.addStringArg("left file address");
}
@@ -356,27 +392,4 @@ 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
9 src/ArsUIMapControlState.h
@@ -61,8 +61,8 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
ofPoint cam1Position, cam2Position;
- int eye[2]; //0:right 1:left
- int selectedMode;//0:select right eye, 1:select left eye
+ int eyes[2]; //0:right 1:left
+ int selectedEye;//0:select right eye, 1:select left eye
void setEye(int bid);
ofxJSONElement json;
@@ -74,10 +74,9 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
ofxUICanvas *gui;
void guiEvent(ofxUIEventArgs &e);
- ofxTimer timer;
- void timerReached(ofEventArgs &e);
- ofPoint initialTouchPoint, lastTouchPoint;
bool isCam1Draggable, isCam2Draggable;
+ int cam1FingerId, cam2FingerId;
+ unsigned long long cam1TouchedStartedAt, cam2TouchedStartedAt;
};
#endif
View
8 src/ArsUIRoboCam.cpp
@@ -67,19 +67,19 @@ void ArsUIRoboCam::draw(){
}
-int ArsUIRoboCam::tapped(float _x, float _y)
+int ArsUIRoboCam::hitTestPoint(ofPoint p)
{
- int _bid = ArsUIButton::tapped(_x, _y);
+ int _bid = ArsUIButton::hitTestPoint(p);
- if (_bid != -1 && status ==1){
+ if (-1 != _bid && 1 == status) {
setDefaultAngle();
}
return _bid;
}
void ArsUIRoboCam::dragAngle(float _x, float _y){
if(status == 1){
- float distance = sqrt((x - _x) * (x - _x) + (y - _y) *(y - _y) );
+ float distance = sqrt((x - _x) * (x - _x) + (y - _y) * (y - _y));
if (distance > radius && distance < radius *1.5) {
ofPoint p1 = ofPoint(x,y);
ofPoint p2 = ofPoint(_x,_y);
View
2 src/ArsUIRoboCam.h
@@ -12,7 +12,7 @@ class ArsUIRoboCam: public ArsUIButton
void draw();
void update();
- int tapped(float _x, float _y);
+ int hitTestPoint(ofPoint p);
void dragAngle(float _, float _y);
bool dragAngleEnded(float _, float _y);
void setDefaultAngle();
View
21 src/ArsUITappedPoint.cpp
@@ -9,7 +9,7 @@
#include "ArsUITappedPoint.h"
#include "ofxEasingFunc.h"
-ArsUITappedPoint::ArsUITappedPoint(float _x, float _y, int tid)
+ArsUITappedPoint::ArsUITappedPoint(float _x, float _y, int tid, bool isTap)
{
x = _x;
y = _y;
@@ -18,6 +18,12 @@ ArsUITappedPoint::ArsUITappedPoint(float _x, float _y, int tid)
tcnt = 0;
cntmax = 30;
tapid = tid;
+
+ if (isTap) {
+ touchStartedAt = ofGetElapsedTimeMillis();
+ } else {
+ touchStartedAt = 0;
+ }
}
void ArsUITappedPoint::update()
@@ -41,4 +47,17 @@ bool ArsUITappedPoint::alive()
{
return tcnt <= cntmax ;
+}
+
+unsigned long long ArsUITappedPoint::getTouchStartedAt()
+{
+ return touchStartedAt;
+}
+
+long ArsUITappedPoint::getElapsedTimeFromTouchStarted()
+{
+ if (0 < touchStartedAt) {
+ return ofGetElapsedTimeMillis() - touchStartedAt;
+ }
+ return 0;
}
View
7 src/ArsUITappedPoint.h
@@ -8,10 +8,13 @@ class ArsUITappedPoint
float alpha;
int tcnt,cntmax;
int tapid;
-
+ unsigned long long touchStartedAt;
+
public:
- ArsUITappedPoint(float _x, float _y, int tid);
+ ArsUITappedPoint(float _x, float _y, int tid, bool isTap = true);
void draw();
void update();
bool alive();
+ unsigned long long getTouchStartedAt();
+ long getElapsedTimeFromTouchStarted();
};
View
24 src/ArsUIUtil.h
@@ -9,10 +9,28 @@
#ifndef arsUI_ArsUIUtil_h
#define arsUI_ArsUIUtil_h
+#define FUJI_LAT 35.362841
+#define FUJI_LON 138.730674
+
+#define YAMANAKA_LAKE_LAT 35.407591
+#define YAMANAKA_LAKE_LON 138.876039
+
class ArsUIUtil
{
public:
- static ofPoint GPStoXY(double _lat,double _lon) {
+ static float distance(ofPoint p1, ofPoint p2) {
+ float a = p1.x - p2.x;
+ float b = p1.y - p1.y;
+ return abs(sqrt(a * a + b * b));
+ };
+
+ static ofPoint GPStoXY(ofPoint fujiPos, double lat, double lon) {
+ ofPoint yamanakaLakePos = ofPoint(1263, 489);
+
+ ofPoint p;
+ p.x = fujiPos.x + (lon - FUJI_LON) * ((yamanakaLakePos.x - fujiPos.x) / (YAMANAKA_LAKE_LON - FUJI_LON));
+ p.y = fujiPos.y + (lat - FUJI_LAT) * ((yamanakaLakePos.y - fujiPos.y) / (YAMANAKA_LAKE_LAT - FUJI_LAT));
+ return p;
// double fujiLat = 35.362841;
// double fujiLon = 138.730674;
//
@@ -28,6 +46,10 @@ class ArsUIUtil
// //cout << "x" << newPoint.x << " " << newPoint.y;
// return newPoint;
};
+
+ static ofPoint XYtoGPS(ofPoint fujiPos, ofPoint pos) {
+
+ };
};
#endif
View
7 src/testApp.h
@@ -6,10 +6,13 @@
#include "ArsUISharedData.h"
#include "ofxJSONElement.h"
+#define SERVER_HOST_DEVELOPMENT "localhost"
+#define SERVER_HOST_PRODUCTION "prix-ars-2013.aws.uniba.jp"
+
#define DISPLAY_HOST "127.0.0.1"
#define DISPLAY_PORT 4444
-#define SERVER_HOST "localhost"
+#define SERVER_HOST SERVER_HOST_DEVELOPMENT
#define SERVER_PORT 7771
#define INCOMING_PORT 5000
@@ -20,7 +23,7 @@
// uncomment if you use Full HD display
-// #define FULL_HD_ENABLE
+#define FULL_HD_ENABLE
class testApp : public ofBaseApp
{

0 comments on commit 3dda42f

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