Permalink
Browse files

refactored and implemented OSC messaging

  • Loading branch information...
1 parent 280f067 commit 38a8b13a308e812efa88025157605ff8caa5bd2d hideyukisaito committed Mar 11, 2013

Large diffs are not rendered by default.

Oops, something went wrong.
Submodule ofxJSON added at 8708ff
View
@@ -0,0 +1,62 @@
+//
+// OSCThreadedObject.h
+// DieHard
+//
+// Created by Koichiro Mori on 2012/11/06.
+//
+//
+
+#ifndef DieHard_OSCThreadedObject_h
+#define DieHard_OSCThreadedObject_h
+
+#define PORT 5000
+
+#import "ofmain.h"
+#include "ofxOsc.h"
+
+class OSCThreadedObject : public ofThread {
+private:
+ ofxOscReceiver receiver;
+ string currentMessage;
+
+public:
+
+ int status;
+
+ OSCThreadedObject(){
+ status = 0;
+ receiver.setup(PORT);
+ }
+
+ void start(){
+ startThread(true, false); // blocking, verbose
+ }
+
+ void stop(){
+ stopThread();
+ }
+
+ void threadedFunction(){
+ while( isThreadRunning() != 0 ){
+ if( lock() ){
+ // check for waiting messages
+ while(receiver.hasWaitingMessages()){
+ ofxOscMessage m;
+ receiver.getNextMessage(&m);
+
+ // test message
+ if(m.getAddress() == "/test"){
+ //currentMessage = m.getArgAsString(0);
+ cout << "recived /test message : " << currentMessage << endl;
+ status = 1;
+ }
+ }
+ unlock();
+ }
+ }
+ }
+
+
+};
+
+#endif
@@ -1,7 +1,7 @@
-#include "button.h"
+#include "ofxArsUIButton.h"
#include "ofxEasingFunc.h"
-button::button(float _x, float _y, int _bid, ofPoint _fuji, float _angle){
+ofxArsUIButton::ofxArsUIButton(float _x, float _y, int _bid, ofPoint _fuji, float _angle){
x = _x;
y = _y;
bid = _bid;
@@ -18,15 +18,15 @@ button::button(float _x, float _y, int _bid, ofPoint _fuji, float _angle){
viewAngle = _angle;
}
-void button::update(){
+void ofxArsUIButton::update(){
float v = sinf((float)bcnt/speed * 2 * PI);
radius = 30 + v*4;
bcnt++;
if(bcnt == speed) bcnt =0;
}
-void button::draw(){
+void ofxArsUIButton::draw(){
//status: 0:default 1:select
ofColor c;
@@ -70,7 +70,7 @@ void button::draw(){
ofPopMatrix();
}
-int button::tapped(float _x, float _y){
+int ofxArsUIButton::tapped(float _x, float _y){
double distance = sqrt( (double)((_x - x) * (_x - x) + (_y - y)*(_y - y))) ;
if (distance < radius/2) {
return bid;
@@ -79,7 +79,7 @@ int button::tapped(float _x, float _y){
}
//return radian
-double button::calcDirection(ofPoint *_p1, ofPoint *_p2){
+double ofxArsUIButton::calcDirection(ofPoint *_p1, ofPoint *_p2){
double v1[] = {100.0, 0};
double v2[] = { _p2->x - _p1->x, _p2->y - _p1->y };
double cosTheta,theta,innerProduct;
@@ -92,21 +92,21 @@ double button::calcDirection(ofPoint *_p1, ofPoint *_p2){
return theta;
}
-void button::setAngle(float _angle){
+void ofxArsUIButton::setAngle(float _angle){
viewAngle = _angle;
}
-void button::setStatus(int _status){
+void ofxArsUIButton::setStatus(int _status){
status = _status;
}
-int button::getStatus(){
+int ofxArsUIButton::getStatus(){
return bid;
}
-int button::getId(){
+int ofxArsUIButton::getId(){
return bid;
}
-void button::setCameraStatus(double _lat, double _lon){
+void ofxArsUIButton::setCameraStatus(double _lat, double _lon){
latitude = _lat;
longtitude = _lon;
ofPoint place = GPStoXY(_lat, _lon);
@@ -115,7 +115,7 @@ void button::setCameraStatus(double _lat, double _lon){
}
-ofPoint button::GPStoXY(double _lat,double _lon){
+ofPoint ofxArsUIButton::GPStoXY(double _lat,double _lon){
//calibration set
//fuji benchmark (富士 中心)
double fujiLat = 35.362841;
@@ -1,7 +1,8 @@
#include "ofMain.h"
-class button{
+class ofxArsUIButton
+{
protected:
int status,bcnt,speed,tcnt; //status 0: not selected, 1:selected, 2: broken
ofImage mark,markShadow;
@@ -16,7 +17,7 @@ class button{
double longtitude;
public:
- button(float _x, float _y, int _bid, ofPoint _fuji, float _angle );
+ ofxArsUIButton(float _x, float _y, int _bid, ofPoint _fuji, float _angle );
virtual void draw();
virtual void update();
virtual int tapped(float _x, float _y);
@@ -1,14 +1,14 @@
-#include "robo.h"
+#include "ofxArsUIRoboCam.h"
-robo::robo(float _x, float _y, int _bid, ofPoint _fuji,float _angle):button(_x,_y,_bid,_fuji,_angle){
- button::mark.loadImage("markyellow.png");
+ofxArsUIRoboCam::ofxArsUIRoboCam(float _x, float _y, int _bid, ofPoint _fuji,float _angle):ofxArsUIButton(_x,_y,_bid,_fuji,_angle){
+ ofxArsUIButton::mark.loadImage("markyellow.png");
}
-void robo::update(){
- button::update();
+void ofxArsUIRoboCam::update(){
+ ofxArsUIButton::update();
}
-void robo::draw(){
+void ofxArsUIRoboCam::draw(){
//status: 0:default 1:select
ofColor c;
@@ -66,29 +66,29 @@ void robo::draw(){
}
-int robo::tapped(float _x, float _y){
- int _bid = button::tapped(_x,_y);
+int ofxArsUIRoboCam::tapped(float _x, float _y){
+ int _bid = ofxArsUIButton::tapped(_x,_y);
if (_bid != -1 && status ==1){
setDefaultAngle();
}
return _bid;
}
-void robo::dragAngle(float _x, float _y){
+void ofxArsUIRoboCam::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 = button::calcDirection(&p1,&p2);
+ float newAngle = ofxArsUIButton::calcDirection(&p1,&p2);
// if(newAngle < directionToFuji + 0.8 && newAngle > directionToFuji - 0.8 ){
currentDirection = newAngle;
// }
}
}
}
-bool robo::dragAngleEnded (float _x, float _y){
+bool ofxArsUIRoboCam::dragAngleEnded (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) {
@@ -99,16 +99,16 @@ bool robo::dragAngleEnded (float _x, float _y){
return false;
}
-void robo::setDefaultAngle(){
+void ofxArsUIRoboCam::setDefaultAngle(){
currentDirection = directionToFuji;
}
-void robo::setRoboStatus(string _udid, double _lat, double _long, double _robox, double _roboy, double _buttery, bool _living){
+void ofxArsUIRoboCam::setRoboStatus(string _udid, double _lat, double _long, double _robox, double _roboy, double _buttery, bool _living){
udid = _udid;
latitude = _lat;
longtitude = _long;
- robox = _robox;
- roboy = _roboy;
+ xpos = _robox;
+ ypos = _roboy;
buttery = _buttery;
living = _living;
ofPoint p = GPStoXY(latitude, longtitude);
@@ -1,15 +1,17 @@
-#include "button.h"
+#include "ofxArsUIButton.h"
-class robo: public button{
- private :
+class ofxArsUIRoboCam: public ofxArsUIButton
+{
+ private:
string udid;
- double robox,roboy,buttery;
+ double xpos, ypos, buttery;
bool living;
public:
- robo(float _x, float _y, int _bid, ofPoint _fuji, float angle);
+ ofxArsUIRoboCam(float _x, float _y, int _bid, ofPoint _fuji, float angle);
void draw();
void update();
+
int tapped(float _x, float _y);
void dragAngle(float _, float _y);
bool dragAngleEnded(float _, float _y);
@@ -6,35 +6,39 @@
//
//
-#include "tapped.h"
+#include "ofxArsUITappedPoint.h"
#include "ofxEasingFunc.h"
-tapped::tapped(float _x, float _y, int tid){
+ofxArsUITappedPoint::ofxArsUITappedPoint(float _x, float _y, int tid)
+{
x = _x;
y = _y;
radius=1;
alpha = 100;
- tcnt=0;
+ tcnt = 0;
cntmax = 30;
tapid = tid;
}
-void tapped::update(){
- float v = ofxEasingFunc::Circ::easeOut((float)tcnt/cntmax) ;
+void ofxArsUITappedPoint::update()
+{
+ float v = ofxEasingFunc::Circ::easeOut((float)tcnt / cntmax);
//cout << " v " << v;
radius = v * 100;
- alpha = (1 - v) * 80 ;
+ alpha = (1 - v) * 80;
tcnt++;
}
-void tapped::draw(){
+void ofxArsUITappedPoint::draw()
+{
ofSetColor(51, 205, 255, alpha);
//cout<< " alpha " << alpha << " radius " << radius ;
ofCircle(x, y, radius);
ofSetColor(255, 255, 255, 255);
}
-bool tapped::alive(){
+bool ofxArsUITappedPoint::alive()
+{
return tcnt <= cntmax ;
}
@@ -1,14 +1,16 @@
#include "ofMain.h"
-class tapped{
+class ofxArsUITappedPoint
+{
private:
- float x,y,radius;
+ float x, y, radius;
float alpha;
int tcnt,cntmax;
int tapid;
+
public:
- tapped(float _x, float _y, int tid);
+ ofxArsUITappedPoint(float _x, float _y, int tid);
void draw();
void update();
bool alive();
Oops, something went wrong.

0 comments on commit 38a8b13

Please sign in to comment.