Permalink
Browse files

get direction as compass

  • Loading branch information...
1 parent 3dda42f commit 1a35ae1db021c147eda85fa0dea109e8881dd01e @hideyukisaito hideyukisaito committed Mar 13, 2013
Showing with 105 additions and 17 deletions.
  1. +35 −1 src/ArsUIButton.cpp
  2. +5 −0 src/ArsUIButton.h
  3. +56 −9 src/ArsUIMapControlState.cpp
  4. +3 −1 src/ArsUIMapControlState.h
  5. +6 −6 src/ArsUIRoboCam.cpp
View
@@ -106,10 +106,44 @@ double ArsUIButton::calcDirection(ofPoint *_p1, ofPoint *_p2)
return theta;
}
-void ArsUIButton::setAngle(float _angle){
+int ArsUIButton::calcCompass(ofPoint *p)
+{
+ float dx = x - p->x;
+ float dy = y - p->y;
+ float radians = atan2(dy, dx);
+ return (int)radians * 180 / PI;
+}
+
+void ArsUIButton::setAngle(float _angle)
+{
viewAngle = _angle;
}
+int ArsUIButton::getAngle()
+{
+ return viewAngle;
+}
+
+
+double ArsUIButton::getDirectionAsRadians()
+{
+ return currentDirection;
+}
+
+double ArsUIButton::getDirectionAsDegrees()
+{
+ return currentDirection * 180 / PI;
+}
+
+int ArsUIButton::getCompass()
+{
+ int deg = (int)getDirectionAsDegrees() - 90;
+ if (0 > deg) {
+ deg = ofMap(deg, -90, -1, 270, 359);
+ }
+ return deg;
+}
+
void ArsUIButton::setStatus(int _status){
status = _status;
}
View
@@ -12,6 +12,7 @@ class ArsUIButton
double directionToFuji; //radian
double currentDirection;
double calcDirection(ofPoint *_p1, ofPoint *_p2);
+ int calcCompass(ofPoint *p);
double viewAngle;
double latitude;
double longtitude;
@@ -26,6 +27,10 @@ class ArsUIButton
ofPoint getPosition();
void setAngle(float _angle);
+ int getAngle();
+ double getDirectionAsRadians();
+ double getDirectionAsDegrees();
+ int getCompass();
void setStatus(int _status);
int getStatus();
int getId();
@@ -29,6 +29,8 @@ void ArsUIMapControlState::init()
//--------------------------------------------------------------
void ArsUIMapControlState::stateEnter()
{
+ bShowStatus = true;
+
fujiPoint.set(964, 600);
for (int i = 0; i < 10; ++i) {
@@ -52,6 +54,9 @@ void ArsUIMapControlState::stateEnter()
ofAddListener(getSharedData().tuioClient.cursorRemoved, this, &ArsUIMapControlState::tuioRemoved);
ofAddListener(getSharedData().tuioClient.cursorUpdated, this, &ArsUIMapControlState::tuioUpdated);
ofAddListener(getSharedData().oscReceiverFromServer.onMessageReceived, this, &ArsUIMapControlState::onOscMessageReceived);
+
+ sendViewpointToServer(robos[0]);
+ sendViewpointToServer(robos[1]);
}
//--------------------------------------------------------------
@@ -65,6 +70,7 @@ 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(gui->newGUIEvent, this, &ArsUIMapControlState::guiEvent);
}
//--------------------------------------------------------------
@@ -122,6 +128,41 @@ void ArsUIMapControlState::draw()
ofLine(0, p.y, ofGetWidth(), p.y);
}
+ ofPushStyle();
+ ofSetColor(255, 0, 0);
+
+ if (bShowStatus) {
+ string str1 = "X : " + ofToString(cam1Position.x) +
+ "\nY : " + ofToString(cam1Position.y) +
+ "\nANGLE : " + ofToString(robos[0].getAngle()) +
+ "\nCOMPASS: " + ofToString(robos[0].getCompass());
+ ofDrawBitmapString(str1, cam1Position + ofPoint(70, -50));
+
+ string str2 = "X : " + ofToString(cam2Position.x) +
+ "\nY : " + ofToString(cam2Position.y) +
+ "\nANGLE : " + ofToString(robos[1].getAngle()) +
+ "\nCOMPASS: " + ofToString(robos[1].getCompass());
+ ofDrawBitmapString(str2, cam2Position + ofPoint(70, -50));
+ } else {
+ if (isCam1Draggable) {
+ string str = "X : " + ofToString(cam1Position.x) +
+ "\nY : " + ofToString(cam1Position.y) +
+ "\nANGLE : " + ofToString(robos[0].getAngle()) +
+ "\nCOMPASS: " + ofToString(robos[0].getCompass());
+ ofDrawBitmapString(str, cam1Position + ofPoint(70, -50));
+ }
+
+ if (isCam2Draggable) {
+ string str = "X : " + ofToString(cam2Position.x) +
+ "\nY : " + ofToString(cam2Position.y) +
+ "\nANGLE : " + ofToString(robos[1].getAngle()) +
+ "\nCOMPASS: " + ofToString(robos[1].getCompass());
+ ofDrawBitmapString(str, cam2Position + ofPoint(70, -50));
+ }
+ }
+
+ ofPopStyle();
+
ofSetColor(0, 255, 0);
ofLine(fujiPoint.x, 0, fujiPoint.x, ofGetHeight());
ofLine(0, fujiPoint.y, ofGetWidth(), fujiPoint.y);
@@ -167,8 +208,10 @@ void ArsUIMapControlState::setupGUI()
gui->addSpacer();
gui->addFPSSlider("FPS SLIDER", GUI_CANVAS_WIDTH - 10, 18, 60);
gui->addSpacer();
- gui->addWidgetDown(new ofxUILabel("FUJI POSITION", OFX_UI_FONT_MEDIUM));
+ gui->addLabelButton("SHOOT", false, true);
gui->autoSizeToFitWidgets();
+
+ ofAddListener(gui->newGUIEvent, this, &ArsUIMapControlState::guiEvent);
}
//--------------------------------------------------------------
@@ -261,6 +304,8 @@ void ArsUIMapControlState::tuioRemoved(ofxTuioCursor &tuioCursor)
cam2FingerId = -1;
isCam2Draggable = false;
}
+
+ sendViewpointToServer(robos[0]);
}
//--------------------------------------------------------------
@@ -285,10 +330,6 @@ void ArsUIMapControlState::tuioUpdated(ofxTuioCursor &tuioCursor)
isCam2Draggable = false;
robos[1].dragAngle(loc.x, loc.y);
}
-
-// for (int i = 0; i < robos.size(); ++i) {
-// robos[i].dragAngle(loc.x, loc.y);
-// }
}
//--------------------------------------------------------------
@@ -352,13 +393,13 @@ void ArsUIMapControlState::getPictureFromURL(string url)
}
//--------------------------------------------------------------
-void ArsUIMapControlState::sendViewpointToServer(int camId, int compass, int angle)
+void ArsUIMapControlState::sendViewpointToServer(ArsUIRoboCam cam)
{
ofxOscMessage msg;
msg.setAddress("/gianteyes/viewpoint");
- msg.addIntArg(camId);
- msg.addIntArg(compass);
- msg.addIntArg(angle);
+ msg.addIntArg(cam.getId());
+ msg.addIntArg(cam.getCompass());
+ msg.addIntArg(cam.getAngle());
getSharedData().oscSenderToServer.sendMessage(msg);
}
@@ -391,5 +432,11 @@ void ArsUIMapControlState::sendOSCToDisplay(int bid)
//--------------------------------------------------------------
void ArsUIMapControlState::guiEvent(ofxUIEventArgs &e)
{
+ string name = e.widget->getName();
+ int kind = e.widget->getKind();
+ if(kind == OFX_UI_WIDGET_LABELBUTTON) {
+ ofxUILabelButton *button = (ofxUILabelButton *) e.widget;
+ cout << name << "\t value: " << button->getValue() << endl;
+ }
}
@@ -52,7 +52,7 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
void onOscMessageReceived(ofxOscMessage &msg);
- void sendViewpointToServer(int camId, int compass, int angle);
+ void sendViewpointToServer(ArsUIRoboCam cam);
void sendTakeTriggerToServer(int camId);
void sendOSCToDisplay(int bid);
@@ -77,6 +77,8 @@ class ArsUIMapControlState : public Apex::ofxState<ArsUISharedData>
bool isCam1Draggable, isCam2Draggable;
int cam1FingerId, cam2FingerId;
unsigned long long cam1TouchedStartedAt, cam2TouchedStartedAt;
+
+ bool bShowStatus;
};
#endif
View
@@ -6,7 +6,7 @@ ArsUIRoboCam::ArsUIRoboCam(float _x, float _y, int _bid, ofPoint _fuji,float _an
void ArsUIRoboCam::update(){
ArsUIButton::update();
- dragAngle(x, y);
+ // dragAngle(x, y);
}
void ArsUIRoboCam::draw(){
@@ -58,7 +58,7 @@ void ArsUIRoboCam::draw(){
ofSetColor(255, 255, 255, 255);
ofPopMatrix();
- if(status ==1){
+ if(status == 1){
ofSetColor(50, 50, 50,200);
ofCircle(x + cos(currentDirection) * times * radius /2.7 , y - sin(currentDirection) * times *radius /2.7, times *radius / 12);
}
@@ -80,10 +80,10 @@ int ArsUIRoboCam::hitTestPoint(ofPoint p)
void ArsUIRoboCam::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);
+ if (distance > radius && distance < radius * 1.5) {
+ ofPoint p1 = ofPoint(x, y);
+ ofPoint p2 = ofPoint(_x, _y);
+ float newAngle = ArsUIButton::calcDirection(&p1, &p2);
// if(newAngle < directionToFuji + 0.8 && newAngle > directionToFuji - 0.8 ){
currentDirection = newAngle;
// }

0 comments on commit 1a35ae1

Please sign in to comment.