Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ok

  • Loading branch information...
commit dda6bca0d4dc5d78f88bc5d7c23db6ae5ec82059 1 parent 0e4f0e1
@hideyukisaito hideyukisaito authored
View
24 arsUI.xcodeproj/project.pbxproj
@@ -46,8 +46,8 @@
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 */; };
+ AB47ADA016D73C9C00C50356 /* ArsUICamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB47AD9E16D73C9C00C50356 /* ArsUICamera.cpp */; };
+ AB47ADFD16DB355500C50356 /* ArsUIOperableCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB47ADFB16DB355500C50356 /* ArsUIOperableCamera.cpp */; };
BBAB23CB13894F3D00AA2426 /* GLUT.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = BBAB23BE13894E4700AA2426 /* GLUT.framework */; };
E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
E45BE97B0E8CC7DD009D7055 /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE9710E8CC7DD009D7055 /* AGL.framework */; };
@@ -248,10 +248,10 @@
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>"; };
- AB47ADFC16DB355500C50356 /* ArsUIRoboCam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArsUIRoboCam.h; sourceTree = "<group>"; };
+ AB47AD9E16D73C9C00C50356 /* ArsUICamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArsUICamera.cpp; sourceTree = "<group>"; };
+ AB47AD9F16D73C9C00C50356 /* ArsUICamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArsUICamera.h; sourceTree = "<group>"; };
+ AB47ADFB16DB355500C50356 /* ArsUIOperableCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArsUIOperableCamera.cpp; sourceTree = "<group>"; };
+ AB47ADFC16DB355500C50356 /* ArsUIOperableCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArsUIOperableCamera.h; sourceTree = "<group>"; };
AB47AE0016DCEF2300C50356 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
BBAB23BE13894E4700AA2426 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = ../../../libs/glut/lib/osx/GLUT.framework; sourceTree = "<group>"; };
E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
@@ -787,10 +787,10 @@
E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */,
40DDEEFA16D5F5A5000C1E58 /* ArsUITappedPoint.h */,
40DDEEF916D5F5A5000C1E58 /* ArsUITappedPoint.cpp */,
- AB47AD9F16D73C9C00C50356 /* ArsUIButton.h */,
- AB47AD9E16D73C9C00C50356 /* ArsUIButton.cpp */,
- AB47ADFC16DB355500C50356 /* ArsUIRoboCam.h */,
- AB47ADFB16DB355500C50356 /* ArsUIRoboCam.cpp */,
+ AB47AD9F16D73C9C00C50356 /* ArsUICamera.h */,
+ AB47AD9E16D73C9C00C50356 /* ArsUICamera.cpp */,
+ AB47ADFC16DB355500C50356 /* ArsUIOperableCamera.h */,
+ AB47ADFB16DB355500C50356 /* ArsUIOperableCamera.cpp */,
AB2701DE16EECBE0000AC44E /* ArsUITitleState.h */,
AB2701DF16EECBFA000AC44E /* ArsUITitleState.cpp */,
AB2701EE16EECC49000AC44E /* ArsUISharedData.h */,
@@ -911,8 +911,8 @@
40FA61F816D35BBD00493C03 /* ofxOscSender.cpp in Sources */,
40DDEEFB16D5F5A5000C1E58 /* ArsUITappedPoint.cpp in Sources */,
40DDEF0616D604D3000C1E58 /* ofxEasingFunc.cpp in Sources */,
- AB47ADA016D73C9C00C50356 /* ArsUIButton.cpp in Sources */,
- AB47ADFD16DB355500C50356 /* ArsUIRoboCam.cpp in Sources */,
+ AB47ADA016D73C9C00C50356 /* ArsUICamera.cpp in Sources */,
+ AB47ADFD16DB355500C50356 /* ArsUIOperableCamera.cpp in Sources */,
AB2701E016EECBFA000AC44E /* ArsUITitleState.cpp in Sources */,
AB2701EA16EECC26000AC44E /* tinyxml.cpp in Sources */,
AB2701EB16EECC26000AC44E /* tinyxmlerror.cpp in Sources */,
View
89 src/ArsUIButton.cpp → src/ArsUICamera.cpp
@@ -1,29 +1,38 @@
-#include "ArsUIButton.h"
+#include "ArsUICamera.h"
#include "ofxEasingFunc.h"
+#include "ArsUIUtil.h"
//--------------------------------------------------------------
-ArsUIButton::ArsUIButton(float _x, float _y, int _bid, ofPoint _fuji, float _angle, string _udid){
+ArsUICamera::ArsUICamera(float _x, float _y, int _bid, ofPoint _fuji, float _angle, string _udid){
x = _x;
y = _y;
udid = _udid;
+ angle = _angle;
+ compass = getCompass();
bid = _bid;
+
status = 0;
speed = 3600;
bcnt = (int)ofRandom(speed);
mark.loadImage("mark.png");
markShadow.loadImage("markshadow.png");
+
fuji = _fuji;
+
ofPoint current;
current.set(_x, _y);
+
directionToFuji = calcDirection(&current, &fuji);
currentDirection = directionToFuji;
- angle = _angle;
- compass = getCompass();
+
+ operable = false;
}
//--------------------------------------------------------------
-ArsUIButton::ArsUIButton(double _lat, double _lon, string _udid, int _angle, int _compass, int _bid, ofPoint _fuji)
+ArsUICamera::ArsUICamera(double _lat, double _lon, string _udid, int _angle, int _compass, int _bid, ofPoint _fuji)
{
+ fuji = _fuji;
+
ofPoint p = GPStoXY(_lat, _lon);
x = p.x;
y = p.y;
@@ -31,7 +40,6 @@ ArsUIButton::ArsUIButton(double _lat, double _lon, string _udid, int _angle, int
angle = _angle;
compass = _compass;
bid = _bid;
- fuji = _fuji;
status = 0;
speed = 3600;
@@ -42,22 +50,24 @@ ArsUIButton::ArsUIButton(double _lat, double _lon, string _udid, int _angle, int
ofPoint current;
current.set(x, y);
+ directionToFuji = calcDirection(&current, &fuji);
currentDirection = compass * PI / 180;
+ currentDirection = directionToFuji;
compass = getCompass();
}
//--------------------------------------------------------------
-void ArsUIButton::update(){
+void ArsUICamera::update(){
- float v = sinf((float)bcnt/speed * 2 * PI);
- radius = 30 + v*4;
+ float v = sinf((float)bcnt / speed * 2 * PI);
+ radius = 30 + v * 4;
bcnt++;
- if(bcnt == speed) bcnt =0;
+ if(bcnt == speed) bcnt = 0;
}
//--------------------------------------------------------------
-void ArsUIButton::draw(){
+void ArsUICamera::draw(){
//status: 0:default 1:select
ofColor c;
@@ -103,7 +113,7 @@ void ArsUIButton::draw(){
//--------------------------------------------------------------
-int ArsUIButton::hitTestPoint(ofPoint p)
+int ArsUICamera::hitTestPoint(ofPoint p)
{
double distance = abs(sqrt((double)((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y))));
@@ -114,27 +124,27 @@ int ArsUIButton::hitTestPoint(ofPoint p)
}
//--------------------------------------------------------------
-void ArsUIButton::setPosition(ofPoint pos)
+void ArsUICamera::setPosition(ofPoint pos)
{
x = pos.x;
y = pos.y;
}
//--------------------------------------------------------------
-ofPoint ArsUIButton::getPosition()
+ofPoint ArsUICamera::getPosition()
{
return ofPoint(x, y);
}
//--------------------------------------------------------------
-void ArsUIButton::setFujiPosition(ofPoint p)
+void ArsUICamera::setFujiPosition(ofPoint p)
{
fuji = p;
}
//--------------------------------------------------------------
//return radian
-double ArsUIButton::calcDirection(ofPoint *_p1, ofPoint *_p2)
+double ArsUICamera::calcDirection(ofPoint *_p1, ofPoint *_p2)
{
double v1[] = {100.0, 0};
double v2[] = { _p2->x - _p1->x, _p2->y - _p1->y };
@@ -149,7 +159,7 @@ double ArsUIButton::calcDirection(ofPoint *_p1, ofPoint *_p2)
}
//--------------------------------------------------------------
-int ArsUIButton::calcCompass(ofPoint *p)
+int ArsUICamera::calcCompass(ofPoint *p)
{
float dx = x - p->x;
float dy = y - p->y;
@@ -158,37 +168,43 @@ int ArsUIButton::calcCompass(ofPoint *p)
}
//--------------------------------------------------------------
-void ArsUIButton::setAngle(float _angle)
+string ArsUICamera::getUDID()
+{
+ return udid;
+}
+
+//--------------------------------------------------------------
+void ArsUICamera::setAngle(float _angle)
{
angle = _angle;
}
//--------------------------------------------------------------
-int ArsUIButton::getAngle()
+int ArsUICamera::getAngle()
{
return angle;
}
//--------------------------------------------------------------
-double ArsUIButton::getDirectionAsRadians()
+double ArsUICamera::getDirectionAsRadians()
{
return currentDirection;
}
//--------------------------------------------------------------
-double ArsUIButton::getDirectionAsDegrees()
+double ArsUICamera::getDirectionAsDegrees()
{
return currentDirection * 180 / PI;
}
//--------------------------------------------------------------
-void ArsUIButton::setCompass(int degrees)
+void ArsUICamera::setCompass(int degrees)
{
currentDirection = degrees * PI / 180;
}
//--------------------------------------------------------------
-int ArsUIButton::getCompass()
+int ArsUICamera::getCompass()
{
int deg = (int)getDirectionAsDegrees() - 90;
if (0 > deg) {
@@ -198,22 +214,28 @@ int ArsUIButton::getCompass()
}
//--------------------------------------------------------------
-void ArsUIButton::setStatus(int _status){
+void ArsUICamera::setStatus(int _status){
status = _status;
}
//--------------------------------------------------------------
-int ArsUIButton::getStatus(){
+int ArsUICamera::getStatus(){
return bid;
}
//--------------------------------------------------------------
-int ArsUIButton::getId(){
+int ArsUICamera::getButtonId(){
return bid;
}
//--------------------------------------------------------------
-void ArsUIButton::setCameraStatus(double _lat, double _lon, int compass, int angle){
+bool ArsUICamera::getOperable()
+{
+ return operable;
+}
+
+//--------------------------------------------------------------
+void ArsUICamera::setCameraStatus(double _lat, double _lon, int compass, int angle){
latitude = _lat;
longitude = _lon;
ofPoint place = GPStoXY(_lat, _lon);
@@ -223,7 +245,7 @@ void ArsUIButton::setCameraStatus(double _lat, double _lon, int compass, int ang
}
//--------------------------------------------------------------
-void ArsUIButton::setCameraStatus(ofxJSONElement json)
+void ArsUICamera::setCameraStatus(ofxJSONElement json)
{
latitude = json["latitude"].asDouble();
longitude = json["longitude"].asDouble();
@@ -236,7 +258,7 @@ void ArsUIButton::setCameraStatus(ofxJSONElement json)
}
//--------------------------------------------------------------
-ofPoint ArsUIButton::GPStoXY(double _lat,double _lon){
+ofPoint ArsUICamera::GPStoXY(double _lat,double _lon){
//calibration set
//fuji benchmark (富士 中心)
double fujiLat = 35.362841;
@@ -254,3 +276,12 @@ ofPoint ArsUIButton::GPStoXY(double _lat,double _lon){
return newPoint;
}
+//--------------------------------------------------------------
+double ArsUICamera::degreesAgainstFuji()
+{
+ double deg = atan2(y - fuji.y, x - fuji.x) * 180 / PI;
+// if (0 > deg) {
+// deg = ofMap(deg, -179, -1, 181, 359);
+// }
+ return deg;
+}
View
32 src/ArsUIButton.h → src/ArsUICamera.h
@@ -2,14 +2,15 @@
#include "ofxJSONElement.h"
-class ArsUIButton
+class ArsUICamera
{
protected:
string udid;
double latitude, longitude;
int compass;
int angle;
-
+ bool operable;
+
int status, bcnt, speed, tcnt; //status 0: not selected, 1:selected, 2: broken
ofImage mark, markShadow;
float x, y, radius;
@@ -23,27 +24,40 @@ class ArsUIButton
int calcCompass(ofPoint *p);
public:
- ArsUIButton(float _x, float _y, int _bid, ofPoint _fuji, float _angle, string _udid);
- ArsUIButton(double _lat, double _lon, string _udid, int _angle, int _compass, int _bid, ofPoint _fuji = ofPoint(964, 600));
+ ArsUICamera(float _x, float _y, int _bid, ofPoint _fuji, float _angle, string _udid);
+ ArsUICamera(double _lat, double _lon, string _udid, int _angle, int _compass, int _bid, ofPoint _fuji = ofPoint(964, 600));
virtual void draw();
virtual void update();
- virtual int hitTestPoint(ofPoint p);
+ virtual int hitTestPoint(ofPoint p);
+
void setPosition(ofPoint pos);
ofPoint getPosition();
-
+
void setFujiPosition(ofPoint p);
+ string getUDID();
+
void setAngle(float _angle);
int getAngle();
+
double getDirectionAsRadians();
double getDirectionAsDegrees();
+
void setCompass(int degrees);
int getCompass();
+
void setStatus(int _status);
int getStatus();
- int getId();
- void setCameraStatus(double _lat, double _lon, int compass, int angle);
- void setCameraStatus(ofxJSONElement json);
+
+ int getButtonId();
+
+ bool getOperable();
+
+ virtual void setCameraStatus(double _lat, double _lon, int compass, int angle);
+ virtual void setCameraStatus(ofxJSONElement json);
+
ofPoint GPStoXY(double _lat, double _lon);
+
+ double degreesAgainstFuji();
};
View
178 src/ArsUIMapControlState.cpp
@@ -32,15 +32,19 @@ void ArsUIMapControlState::stateEnter()
bShowStatus = true;
fujiPoint.set(964, 600);
- ofPoint p = ArsUIUtil::XYtoGPS(fujiPoint);
- cout << "XYtoGPS x: " << p.x << ", y: " << p.y << endl;
- for (int i = 0; i < 10; ++i) {
- inoperableCameras.push_back(ArsUIButton(ofRandom(ofGetWidth()), ofRandom(ofGetHeight() - 100), i, fujiPoint, ofRandom(20, 60), ""));
- }
+ json.clear();
- for (int i = 10; i < (10 + getSharedData().numRobots); ++i) {
- operableCameras.push_back(ArsUIRoboCam(ofRandom(ofGetWidth()), ofRandom(ofGetHeight() - 100), i, fujiPoint, ofRandom(20, 60), ""));
+ if (json.open(ofToDataPath("cameras.json"))) {
+ for (int i = 0; i < json["cameras"].size(); ++i) {
+ ofxJSONElement camera = json["cameras"][i];
+
+ if (true == camera["operable"].asBool()) {
+ operableCameras.push_back(createOperableCamera(camera, i));
+ } else {
+ inoperableCameras.push_back(createCamera(camera, i));
+ }
+ }
}
cam1Position = ofPoint(operableCameras[0].getPosition().x, operableCameras[0].getPosition().y);
@@ -48,7 +52,7 @@ void ArsUIMapControlState::stateEnter()
eyes[0] = -1;
eyes[1] = -1;
- selectedEye = 0;
+ selectedEye = EYE_LEFT;
fujiMap.loadImage("map.png");
@@ -64,6 +68,11 @@ void ArsUIMapControlState::stateEnter()
sendViewpointToServer(operableCameras[0]);
sendViewpointToServer(operableCameras[1]);
+
+ for (int i = 0; i < operableCameras.size(); ++i) {
+ sendViewpointToServer(operableCameras[i]);
+ sendImageUrlToDisplay(operableCameras[i].getEyeDirection(), "http://pds.exblog.jp/pds/1/200802/18/73/d0116173_14571347.jpg");
+ }
}
//--------------------------------------------------------------
@@ -127,12 +136,6 @@ void ArsUIMapControlState::draw()
for (int i = 0; i < operableCameras.size(); ++i) {
operableCameras[i].draw();
-
- ofPoint p = operableCameras[i].getPosition();
-
- ofSetColor(255, 0, 0);
- ofLine(p.x, 0, p.x, ofGetHeight());
- ofLine(0, p.y, ofGetWidth(), p.y);
}
ofPushStyle();
@@ -151,11 +154,34 @@ void ArsUIMapControlState::draw()
}
}
- ofPopStyle();
+ double cam1deg = operableCameras[0].degreesAgainstFuji();
+ double cam2deg = operableCameras[1].degreesAgainstFuji();
+
+ if (0 <= cam1deg && 0 <= cam2deg) {
+ if (cam1deg < cam2deg) {
+ operableCameras[0].setEyeDirection(EYE_RIGHT);
+ operableCameras[1].setEyeDirection(EYE_LEFT);
+ } else {
+ operableCameras[0].setEyeDirection(EYE_LEFT);
+ operableCameras[1].setEyeDirection(EYE_RIGHT);
+ }
+ } else if (0 <= cam1deg && 0 > cam2deg) {
+ operableCameras[0].setEyeDirection(EYE_RIGHT);
+ operableCameras[1].setEyeDirection(EYE_LEFT);
+ } else if (0 > cam1deg && 0 > cam2deg) {
+ if (cam1deg < cam2deg) {
+ operableCameras[0].setEyeDirection(EYE_RIGHT);
+ operableCameras[1].setEyeDirection(EYE_LEFT);
+ } else {
+ operableCameras[0].setEyeDirection(EYE_LEFT);
+ operableCameras[1].setEyeDirection(EYE_RIGHT);
+ }
+ } else if (0 > cam1deg && 0 <= cam2deg) {
+ operableCameras[0].setEyeDirection(EYE_LEFT);
+ operableCameras[1].setEyeDirection(EYE_RIGHT);
+ }
- ofSetColor(0, 255, 0);
- ofLine(fujiPoint.x, 0, fujiPoint.x, ofGetHeight());
- ofLine(0, fujiPoint.y, ofGetWidth(), fujiPoint.y);
+ ofPopStyle();
}
//--------------------------------------------------------------
@@ -205,19 +231,31 @@ void ArsUIMapControlState::setupGUI()
}
//--------------------------------------------------------------
+ArsUICamera ArsUIMapControlState::createCamera(ofxJSONElement json, int bid)
+{
+ return ArsUICamera(json["latitude"].asDouble(), json["longitude"].asDouble(), json["udid"].asString(), json["angle"].asInt(), json["compass"].asInt(), bid, fujiPoint);
+}
+
+//--------------------------------------------------------------
+ArsUIOperableCamera ArsUIMapControlState::createOperableCamera(ofxJSONElement json, int bid)
+{
+ return ArsUIOperableCamera(json["latitude"].asDouble(), json["longitude"].asDouble(), json["udid"].asString(), json["angle"].asInt(), json["compass"].asInt(), json["battery"].asInt(), json["living"].asBool(), bid, fujiPoint);
+}
+
+//--------------------------------------------------------------
void ArsUIMapControlState::setEye(int bid)
{
int lastEye = eyes[selectedEye];
if (-1 != lastEye) {
for (int i = 0; i < inoperableCameras.size(); ++i) {
- if(inoperableCameras[i].getId() == lastEye){
+ if(inoperableCameras[i].getButtonId() == lastEye){
inoperableCameras[i].setStatus(0);
}
}
for (int i = 0; i < operableCameras.size(); ++i) {
- if(operableCameras[i].getId() == lastEye){
+ if(operableCameras[i].getButtonId() == lastEye){
operableCameras[i].setStatus(0);
}
}
@@ -225,7 +263,7 @@ void ArsUIMapControlState::setEye(int bid)
eyes[selectedEye] = bid;
- selectedEye = !selectedEye ? 1 : 0;
+ selectedEye = !selectedEye ? EYE_RIGHT : EYE_LEFT;
}
//--------------------------------------------------------------
@@ -244,7 +282,6 @@ void ArsUIMapControlState::tuioAdded(ofxTuioCursor &tuioCursor)
if (0 <= bid && bid != eyes[0] && bid != eyes[1]) {
setEye(bid);
inoperableCameras[i].setStatus(1);
- sendOSCToDisplay(bid);
}
}
@@ -254,7 +291,6 @@ void ArsUIMapControlState::tuioAdded(ofxTuioCursor &tuioCursor)
if (0 <= bid && bid != eyes[0] && bid != eyes[1]){
setEye(bid);
operableCameras[i].setStatus(1);
- sendOSCToDisplay(bid);
}
}
@@ -290,11 +326,13 @@ void ArsUIMapControlState::tuioRemoved(ofxTuioCursor &tuioCursor)
cam1FingerId = -1;
isCam1Draggable = false;
sendViewpointToServer(operableCameras[0]);
+ sendImageUrlToDisplay(operableCameras[0].getEyeDirection(), "http://cache5.amanaimages.com/cen3tzG4fTr7Gtw1PoeRer/22973000320.jpg");
} else if (tuioCursor.getFingerId() == cam2FingerId) {
cam2TouchedStartedAt = 0;
cam2FingerId = -1;
isCam2Draggable = false;
sendViewpointToServer(operableCameras[1]);
+ sendImageUrlToDisplay(operableCameras[1].getEyeDirection(), "http://cache5.amanaimages.com/cen3tzG4fTr7Gtw1PoeRer/22973000320.jpg");
}
}
@@ -344,56 +382,74 @@ void ArsUIMapControlState::drawTuioCursors()
}
//--------------------------------------------------------------
-void ArsUIMapControlState::drawCamStatuses(ArsUIRoboCam cam)
+void ArsUIMapControlState::drawCamStatuses(ArsUIOperableCamera cam)
{
string str = "X : " + ofToString(cam.getPosition().x) +
"\nY : " + ofToString(cam.getPosition().y) +
- "\nANGLE : " + ofToString(cam.getAngle()) +
- "\nCOMPASS: " + ofToString(cam.getCompass());
- ofDrawBitmapString(str, cam.getPosition() + ofPoint(70, -50));
+ "\nANGLE : " + ofToString(cam.degreesAgainstFuji()) +
+ "\nCOMPASS: " + ofToString(cam.getCompass()) +
+ "\nEYE : " + ofToString(EYE_LEFT == cam.getEyeDirection() ? "LEFT" : "RIGHT");
+ ofDrawBitmapString(str, cam.getPosition() + ofPoint(70, -80));
}
//--------------------------------------------------------------
void ArsUIMapControlState::onOscMessageReceived(ofxOscMessage &msg)
{
+ json.clear();
+
string addr = msg.getAddress();
cout << "OSC received. address: " << addr << endl;
if ("/gianteyes/camera" == addr) {
- int udid = msg.getArgAsInt32(0);
- float lat = msg.getArgAsFloat(1);
- float lon = msg.getArgAsFloat(2);
- float compass = msg.getArgAsFloat(3);
- int angle = msg.getArgAsInt32(4);
- int battery = msg.getArgAsInt32(5);
- int operable = msg.getArgAsInt32(6);
- int living = msg.getArgAsInt32(7);
+ string jsonString = msg.getArgAsString(0);
+
+ if (0 < jsonString.length()) {
+ if (json.parse(jsonString)) {
+ string udid = json["udid"].asString();
+
+ if (true == json["operable"].asBool()) {
+ for (int i = 0; i < operableCameras.size(); ++i) {
+ if (operableCameras[i].getUDID() == udid) {
+ operableCameras[i].setCameraStatus(json);
+ }
+ }
+ } else {
+ for (int i = 0; i < inoperableCameras.size(); ++i) {
+ if (inoperableCameras[i].getUDID() == udid) {
+ inoperableCameras[i].setCameraStatus(json);
+ }
+ }
+ }
+ }
+ }
} else if ("/gianteyes/photo" == addr) {
- int udid = msg.getArgAsInt32(0);
- string url = msg.getArgAsString(1);
- float correction = msg.getArgAsFloat(2);
- float lat = msg.getArgAsFloat(3);
- float lon = msg.getArgAsFloat(4);
- float compass = msg.getArgAsFloat(5);
- int angle = msg.getArgAsInt32(6);
+ string jsonString = msg.getArgAsString(0);
- getPictureFromURL(url);
+ if (0 < jsonString.length()) {
+ if (json.parse(jsonString)) {
+ for (int i = 0; i < operableCameras.size(); ++i) {
+ if (json["udid"] == operableCameras[i].getUDID()) {
+ sendImageUrlToDisplay(operableCameras[i].getEyeDirection(), json["url"].asString());
+ }
+ }
+ }
+ }
} else if ("/gianteyes/cameras" == addr) {
string jsonString = msg.getArgAsString(0);
if (0 < jsonString.length()) {
if (json.parse(jsonString)) {
- ofxJSONElement cameras = json["cameras"];
-
inoperableCameras.clear();
operableCameras.clear();
- for (int i = 0; i < cameras.size(); ++i) {
- if (true == cameras[i]["operable"].asBool()) {
- ArsUIRoboCam r = ArsUIRoboCam(cameras[i]["latitude"].asDouble(), cameras[i]["longitude"].asDouble(), cameras[i]["udid"].asString(), cameras[i]["angle"].asInt(), cameras[i]["compass"].asInt(), cameras[i]["battery"].asInt(), cameras[i]["living"].asBool(), i, fujiPoint);
+ for (int i = 0; i < json["cameras"].size(); ++i) {
+ ofxJSONElement camera = json["cameras"][i];
+
+ if (true == camera["operable"].asBool()) {
+ operableCameras.push_back(createOperableCamera(camera, i));
} else {
- ArsUIButton b = ArsUIButton(cameras[i]["latitude"].asDouble(), cameras[i]["longitude"].asDouble(), cameras[i]["udid"].asString(), cameras[i]["angle"].asInt(), cameras[i]["compass"].asInt(), i, fujiPoint);
+ inoperableCameras.push_back(createCamera(camera, i));
}
}
}
@@ -402,24 +458,18 @@ void ArsUIMapControlState::onOscMessageReceived(ofxOscMessage &msg)
}
//--------------------------------------------------------------
-void ArsUIMapControlState::getPictureFromURL(string url)
-{
-
-}
-
-//--------------------------------------------------------------
-void ArsUIMapControlState::sendViewpointToServer(ArsUIRoboCam cam)
+void ArsUIMapControlState::sendViewpointToServer(ArsUIOperableCamera cam)
{
ofxOscMessage msg;
msg.setAddress("/gianteyes/viewpoint");
- msg.addIntArg(cam.getId());
+ msg.addIntArg(cam.getButtonId());
msg.addIntArg(cam.getCompass());
msg.addIntArg(cam.getAngle());
getSharedData().oscSenderToServer.sendMessage(msg);
}
//--------------------------------------------------------------
-void ArsUIMapControlState::sendTakeTriggerToServer(int camId)
+void ArsUIMapControlState::sendShootingTriggerToServer(int camId)
{
ofxOscMessage msg;
msg.setAddress("/gianteyes/take");
@@ -428,19 +478,13 @@ void ArsUIMapControlState::sendTakeTriggerToServer(int camId)
}
//--------------------------------------------------------------
-void ArsUIMapControlState::sendOSCToDisplay(int bid)
+void ArsUIMapControlState::sendImageUrlToDisplay(int whichEye, string url)
{
ofxOscMessage msg;
- if (1 == selectedEye) {
- msg.setAddress("/right/image");
- msg.addStringArg("right file address");
- } else if (0 == selectedEye) {
- msg.setAddress("/left/image");
- msg.addStringArg("left file address");
- }
+ EYE_RIGHT == whichEye ? msg.setAddress("/url/right") : msg.setAddress("/url/left");
- msg.addIntArg(bid);
+ msg.addStringArg(url);
getSharedData().oscSenderToDisplay.sendMessage(msg);
}
View
22 src/ArsUIMapControlState.h
@@ -12,11 +12,14 @@
#define GUI_CANVAS_WIDTH 200
#define GUI_CANVAS_HEIGHT ofGetHeight()
+#define EYE_LEFT 0
+#define EYE_RIGHT 1
+
#include "ofxState.h"
#include "ofxXmlSettings.h"
#include "ArsUISharedData.h"
#include "ofxTween.h"
-#include "ArsUIRoboCam.h"
+#include "ArsUIOperableCamera.h"
#include "ofxJSONElement.h"
#include "ofxUI.h"
#include "ArsUIUtil.h"
@@ -42,8 +45,10 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
private:
void init();
- vector <ArsUIButton> inoperableCameras; // web camera
- vector <ArsUIRoboCam> operableCameras; // robot
+ vector <ArsUICamera> inoperableCameras; // web camera
+ vector <ArsUIOperableCamera> operableCameras; // robot
+ ArsUICamera createCamera(ofxJSONElement json, int bid);
+ ArsUIOperableCamera createOperableCamera(ofxJSONElement json, int bid);
void tuioAdded(ofxTuioCursor & tuioCursor);
void tuioRemoved(ofxTuioCursor & tuioCursor);
@@ -52,9 +57,9 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
void onOscMessageReceived(ofxOscMessage &msg);
- void sendViewpointToServer(ArsUIRoboCam cam);
- void sendTakeTriggerToServer(int camId);
- void sendOSCToDisplay(int bid);
+ void sendViewpointToServer(ArsUIOperableCamera cam);
+ void sendShootingTriggerToServer(int camId);
+ void sendImageUrlToDisplay(int whichEye, string url);
ofImage fujiMap;
ofPoint fujiPoint;
@@ -68,7 +73,6 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
ofxJSONElement json;
string rightImageFile, leftImageFile;
- void getPictureFromURL(string url);
void setupGUI();
ofxUICanvas *gui;
@@ -77,9 +81,11 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
bool isCam1Draggable, isCam2Draggable;
int cam1FingerId, cam2FingerId;
unsigned long long cam1TouchedStartedAt, cam2TouchedStartedAt;
- void drawCamStatuses(ArsUIRoboCam cam);
+ void drawCamStatuses(ArsUIOperableCamera cam);
bool bShowStatus;
+
+ ofxTimer doubleTapTimer;
};
#endif
View
81 src/ArsUIRoboCam.cpp → src/ArsUIOperableCamera.cpp
@@ -1,28 +1,30 @@
-#include "ArsUIRoboCam.h"
+#include "ArsUIOperableCamera.h"
//--------------------------------------------------------------
-ArsUIRoboCam::ArsUIRoboCam(float _x, float _y, int _bid, ofPoint _fuji,float _angle, string _udid):ArsUIButton(_x, _y, _bid, _fuji, _angle, _udid)
+ArsUIOperableCamera::ArsUIOperableCamera(float _x, float _y, int _bid, ofPoint _fuji,float _angle, string _udid):ArsUICamera(_x, _y, _bid, _fuji, _angle, _udid)
{
- ArsUIButton::mark.loadImage("markyellow.png");
+ operable = true;
+ ArsUICamera::mark.loadImage("markyellow.png");
}
-ArsUIRoboCam::ArsUIRoboCam(double _lat, double _lon, string _udid, int _angle, int _compass, float _battery, bool _living, int _bid, ofPoint _fuji):ArsUIButton(
+ArsUIOperableCamera::ArsUIOperableCamera(double _lat, double _lon, string _udid, int _angle, int _compass, float _battery, bool _living, int _bid, ofPoint _fuji):ArsUICamera(
_lat, _lon, _udid, _angle, _compass, _bid, _fuji)
{
+ operable = true;
battery = _battery;
living = _living;
- ArsUIButton::mark.loadImage("markyellow.png");
+ ArsUICamera::mark.loadImage("markyellow.png");
}
//--------------------------------------------------------------
-void ArsUIRoboCam::update()
+void ArsUIOperableCamera::update()
{
- ArsUIButton::update();
+ ArsUICamera::update();
// dragAngle(x, y);
}
//--------------------------------------------------------------
-void ArsUIRoboCam::draw()
+void ArsUIOperableCamera::draw()
{
//status: 0:default 1:select
@@ -82,9 +84,9 @@ void ArsUIRoboCam::draw()
}
//--------------------------------------------------------------
-int ArsUIRoboCam::hitTestPoint(ofPoint p)
+int ArsUIOperableCamera::hitTestPoint(ofPoint p)
{
- int _bid = ArsUIButton::hitTestPoint(p);
+ int _bid = ArsUICamera::hitTestPoint(p);
if (-1 != _bid && 1 == status) {
setDefaultAngle();
@@ -93,14 +95,14 @@ int ArsUIRoboCam::hitTestPoint(ofPoint p)
}
//--------------------------------------------------------------
-void ArsUIRoboCam::dragAngle(float _x, float _y)
+void ArsUIOperableCamera::dragAngle(float _x, float _y)
{
if(status == 1){
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);
- float newAngle = ArsUIButton::calcDirection(&p1, &p2);
+ float newAngle = ArsUICamera::calcDirection(&p1, &p2);
// if(newAngle < directionToFuji + 0.8 && newAngle > directionToFuji - 0.8 ){
currentDirection = newAngle;
// }
@@ -109,7 +111,7 @@ void ArsUIRoboCam::dragAngle(float _x, float _y)
}
//--------------------------------------------------------------
-bool ArsUIRoboCam::dragAngleEnded (float _x, float _y)
+bool ArsUIOperableCamera::dragAngleEnded (float _x, float _y)
{
if(status == 1){
float distance = sqrt((x - _x) * (x - _x) + (y - _y) *(y - _y) );
@@ -122,13 +124,25 @@ bool ArsUIRoboCam::dragAngleEnded (float _x, float _y)
}
//--------------------------------------------------------------
-void ArsUIRoboCam::setDefaultAngle()
+void ArsUIOperableCamera::setDefaultAngle()
{
currentDirection = directionToFuji;
}
//--------------------------------------------------------------
-void ArsUIRoboCam::setRoboStatus(string _udid, double _lat, double _long, double _robox, double _roboy, double _battery, bool _living)
+int ArsUIOperableCamera::getEyeDirection()
+{
+ return eyeDirection;
+}
+
+//--------------------------------------------------------------
+void ArsUIOperableCamera::setEyeDirection(int direction)
+{
+ eyeDirection = direction;
+}
+
+//--------------------------------------------------------------
+void ArsUIOperableCamera::setRoboStatus(string _udid, double _lat, double _long, double _robox, double _roboy, double _battery, bool _living)
{
udid = _udid;
latitude = _lat;
@@ -143,7 +157,7 @@ void ArsUIRoboCam::setRoboStatus(string _udid, double _lat, double _long, double
}
//--------------------------------------------------------------
-void ArsUIRoboCam::setCamStatus(string jsonString)
+void ArsUIOperableCamera::setCamStatus(string jsonString)
{
ofxJSONElement json;
if (json.parse(jsonString)) {
@@ -155,25 +169,52 @@ void ArsUIRoboCam::setCamStatus(string jsonString)
//--------------------------------------------------------------
-int ArsUIRoboCam::getBattery()
+int ArsUIOperableCamera::getBattery()
{
return (int)battery;
}
//--------------------------------------------------------------
-void ArsUIRoboCam::setBattery(int value)
+void ArsUIOperableCamera::setBattery(int value)
{
battery = value;
}
//--------------------------------------------------------------
-bool ArsUIRoboCam::getLiving()
+bool ArsUIOperableCamera::getLiving()
{
return living;
}
//--------------------------------------------------------------
-void ArsUIRoboCam::setLiving(bool value)
+void ArsUIOperableCamera::setLiving(bool value)
{
living = value;
+}
+
+//--------------------------------------------------------------
+void ArsUIOperableCamera::setCameraStatus(double _lat, double _lon, int compass, int angle)
+{
+ latitude = _lat;
+ longitude = _lon;
+ ofPoint place = GPStoXY(_lat, _lon);
+ x = place.x;
+ y = place.y;
+
+}
+
+//--------------------------------------------------------------
+void ArsUIOperableCamera::setCameraStatus(ofxJSONElement json)
+{
+ latitude = json["latitude"].asDouble();
+ longitude = json["longitude"].asDouble();
+
+ ofPoint p = GPStoXY(latitude, longitude);
+ x = p.x;
+ y = p.y;
+
+ compass = json["compass"].asInt();
+ angle = json["angle"].asInt();
+ battery = json["battery"].asInt();
+ living = json["living"].asBool();
}
View
19 src/ArsUIRoboCam.h → src/ArsUIOperableCamera.h
@@ -1,24 +1,32 @@
-#include "ArsUIButton.h"
+#include "ArsUICamera.h"
#include "ofxJSONElement.h"
-class ArsUIRoboCam: public ArsUIButton
+class ArsUIOperableCamera: public ArsUICamera
{
private:
string udid;
double xpos, ypos;
float battery;
bool living;
+ bool operable;
+ int eyeDirection;
public:
- ArsUIRoboCam(float _x, float _y, int _bid, ofPoint _fuji, float angle, string _udid);
- ArsUIRoboCam(double _lat, double _lon, string _udid, int _angle, int _compass, float _battery, bool _living, int _bid, ofPoint _fuji);
+ ArsUIOperableCamera(float _x, float _y, int _bid, ofPoint _fuji, float angle, string _udid);
+ ArsUIOperableCamera(double _lat, double _lon, string _udid, int _angle, int _compass, float _battery, bool _living, int _bid, ofPoint _fuji);
void draw();
void update();
int hitTestPoint(ofPoint p);
+
void dragAngle(float _, float _y);
bool dragAngleEnded(float _, float _y);
+
void setDefaultAngle();
+
+ int getEyeDirection();
+ void setEyeDirection(int direction);
+
void setRoboStatus(string _udid, double _lat, double _long, double _robox, double _roboy, double _buttery, bool _living );
void setCamStatus(string jsonString);
@@ -27,4 +35,7 @@ class ArsUIRoboCam: public ArsUIButton
bool getLiving();
void setLiving(bool value);
+
+ void setCameraStatus(double _lat, double _lon, int compass, int angle);
+ void setCameraStatus(ofxJSONElement json);
};
View
2  src/testApp.cpp
@@ -7,7 +7,7 @@ void testApp::initOSC()
{
stateMachine.getSharedData().oscSenderToDisplay.setup(DISPLAY_HOST, DISPLAY_PORT);
stateMachine.getSharedData().oscReceiverFromServer.setup(INCOMING_PORT);
- stateMachine.getSharedData().oscSenderToServer.setup(SERVER_HOST, SERVER_PORT);
+ stateMachine.getSharedData().oscSenderToServer.setup(SERVER_HOST_PRODUCTION, SERVER_PORT);
}
//--------------------------------------------------------------
View
2  src/testApp.h
@@ -13,7 +13,7 @@
#define DISPLAY_PORT 4444
#define SERVER_HOST SERVER_HOST_PRODUCTION
-#define SERVER_PORT 7771
+#define SERVER_PORT 50001
#define INCOMING_PORT 5000
Please sign in to comment.
Something went wrong with that request. Please try again.