Permalink
Browse files

Updating OSC to read transform data as floats.

  • Loading branch information...
1 parent 17ba31f commit 7935ceb33ed5a021ba4e2897ff91563f4bb3f510 @bakercp committed Apr 3, 2012
View
16 livedraw/src/canvas/CanvasLayerManager.cpp
@@ -41,23 +41,21 @@ void CanvasLayerManager::processOscMessage(string pattern, ofxOscMessage& m) {
if(isMatch(pattern,"/new")) {
// /livedraw/canvas/layer/new LAYER_NAME [X_POSITION Y_POSITION [Z_POSITION]]
if(validateOscSignature("s[fi][fi][fi]?", m)) {
- int x = 0;
- int y = 0;
- int z = 0;
+
+ ofPoint p(0.0f,0.0f,0.0f);
+
string layerName = m.getArgAsString(0);
if(m.getNumArgs() > 1) {
- x = m.getArgAsInt32(1);
- y = m.getArgAsInt32(2);
+ p.x = m.getArgAsFloat(1);
+ p.y = m.getArgAsFloat(2);
if(m.getNumArgs() > 3) {
- cout << " got a z" << endl;
- z = m.getArgAsInt32(3);
+ p.z = m.getArgAsFloat(3);
}
}
-
// make a new layer
- newLayer(layerName, ofPoint(x,y,z));
+ newLayer(layerName, p);
}
} else if(isMatch(pattern, "/delete")) {
View
79 livedraw/src/canvas/CanvasLayerTransform.cpp
@@ -11,82 +11,3 @@
//--------------------------------------------------------------
-
-/*
- void keyPressed(int key) {
-
- //key ^= GLUT_ACTIVE_CTRL;
-
- cout << "key ========" << key << endl;
-
- switch(key) {
- case 'q':
- position.incrementX();
- break;
- case 'w':
- position.decrementX();
- break;
- case 'a':
- position.incrementY();
- break;
- case 's':
- position.decrementY();
- break;
- case 'z':
- position.incrementZ();
- break;
- case 'x':
- position.decrementZ();
- break;
- // scale
-
- case 'e':
- position.incrementX();
- break;
- case 'r':
- position.decrementX();
- break;
- case 'd':
- position.incrementY();
- break;
- case 'f':
- position.decrementY();
- break;
- case 'c':
- position.incrementZ();
- break;
- case 'v':
- position.decrementZ();
- break;
-
- //rotation
- case 't':
- position.incrementX();
- break;
- case 'y':
- position.decrementX();
- break;
- case 'g':
- position.incrementY();
- break;
- case 'h':
- position.decrementY();
- break;
- case 'b':
- position.incrementZ();
- break;
- case 'n':
- position.decrementZ();
- break;
- case '1':
- opacity+=0.1;
- opacity = CLAMP(opacity, 0,1);
- break;
- case '2':
- opacity-=0.1;
- opacity = CLAMP(opacity, 0,1);
- break;
- }
-
- }
- */
View
52 livedraw/src/canvas/CanvasLayerTransform.h
@@ -122,20 +122,11 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
void processOscMessage(string address, ofxOscMessage& m) {
-// cout << "getting TRANSFORM MESSAGE!"<<endl;
-
if(isMatch(address,"/position")) {
if(validateOscSignature("([if][if]?[if]?)|([s][if])", m)) {
-
- cout << "GOT POSITION INFO" << endl;
-
if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
-
char c = tolower(m.getArgAsString(0)[0]);
- int val = m.getArgAsInt32(1);
-
- cout << "\t\t in STRING TYPE ->" << val << endl;
-
+ float val = m.getArgAsFloat(1);
if(c == 'x') {
setPositionX(val);
@@ -146,25 +137,13 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
} else {
ofLog(OF_LOG_ERROR, "CanvasLayerTransform: invalid arg type: " + ofToString(c) + " " + address);
}
-
-
- } else {
-
- cout << "\t\t in NON _> STRING TYPE ->" << m.getArgAsInt32(0) << endl;
-
- setPositionX(m.getArgAsInt32(0));
+ } else {
+ setPositionX(m.getArgAsFloat(0));
if(m.getNumArgs() > 1) {
-
- cout << "\t\t\t setting y posi t0= " << m.getArgAsInt32(1) << endl;
-
- setPositionY(m.getArgAsInt32(1));
+ setPositionY(m.getArgAsFloat(1));
if(m.getNumArgs() > 2) {
-
- cout << "\t\t\t setting ZZ posi t0= " << m.getArgAsInt32(2) << endl;
-
- setPositionZ(m.getArgAsInt32(2));
-
+ setPositionZ(m.getArgAsFloat(2));
}
}
}
@@ -175,7 +154,7 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
char c = tolower(m.getArgAsString(0)[0]);
- int val = m.getArgAsInt32(1);
+ float val = m.getArgAsFloat(1);
if(c == 'x') {
setAnchorPointX(val);
@@ -189,11 +168,11 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
} else {
- setAnchorPointX(m.getArgAsInt32(0));
+ setAnchorPointX(m.getArgAsFloat(0));
if(m.getNumArgs() > 1) {
- setAnchorPointY(m.getArgAsInt32(1));
+ setAnchorPointY(m.getArgAsFloat(1));
if(m.getNumArgs() > 2) {
- setAnchorPointZ(m.getArgAsInt32(2));
+ setAnchorPointZ(m.getArgAsFloat(2));
}
}
}
@@ -234,9 +213,7 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
}
- } else if(isMatch(address,"/scale")) {
- // TODO: z-scale? is this possible in 2d space?
-
+ } else if(isMatch(address,"/scale")) {
if(validateOscSignature("([f][f]?[f]?)|([s][f])", m)) {
if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
@@ -253,7 +230,6 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
ofLog(OF_LOG_ERROR, "CanvasLayerTransform: invalid arg type: " + ofToString(c) + " " + address);
}
-
} else {
setScaleX(m.getArgAsFloat(0));
if(m.getNumArgs() > 1) {
@@ -267,13 +243,13 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
} else if(isMatch(address,"/opacity")) {
if(validateOscSignature("[if]", m)) {
- int val = m.getArgAsInt32(0);
+ float val = m.getArgAsFloat(0);
setOpacity(val);
}
} else if(isMatch(address,"/size")) {
if(validateOscSignature("[if][if]", m)) {
- int w = m.getArgAsInt32(0);
- int h = m.getArgAsInt32(1);
+ int w = m.getArgAsFloat(0);
+ int h = m.getArgAsFloat(1);
setSize(ofPoint(w,h));
}
}
@@ -395,7 +371,7 @@ class CanvasLayerTransform : public OscNodeListener, public Enabler {
ofxLimitedPoint size;
- int opacity; // 0-255
+ float opacity; // 0-255
/*
ofEvent<ofxLimitedPoint*> newPositionEvent;

0 comments on commit 7935ceb

Please sign in to comment.