Created
October 9, 2013 19:02
-
-
Save veev/6906394 to your computer and use it in GitHub Desktop.
MPE Ball Receiving Keypress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "testApp.h" | |
#define RECONNECT_TIME 400 | |
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
// initialize app | |
ofSetFrameRate(30); | |
ofEnableSmoothing(); | |
ofEnableAlphaBlending(); | |
ofSetBackgroundAuto(false); | |
client.setup("settings.xml", this); | |
// set the random seed | |
ofSeedRandom(1); | |
// add a "randomly" placed ball | |
Ball* ball = new Ball(ofRandom(0, client.getMWidth()), ofRandom(0, client.getMHeight()), client.getMWidth(), client.getMHeight()); | |
balls.push_back(ball); | |
blackBkgd = false; | |
// ofBackground(255, 255, 255); | |
// start client | |
client.start(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::frameEvent() { | |
// clear the x | |
ofBackground(255, 255, 255); | |
if(blackBkgd) { | |
ofBackground(0, 0, 0); | |
} else { | |
ofBackground(255, 255, 255); | |
} | |
// move and draw all the balls | |
for (int i = 0; i < balls.size(); i++) { | |
balls[i]->calc(); | |
balls[i]->draw(); | |
} | |
// read any incoming messages | |
if (client.messageAvailable()) { | |
vector<string> msg = client.getDataMessage(); | |
if(msg[0] == "0") { | |
blackBkgd = true; | |
} | |
if(msg[0] == "1") { | |
blackBkgd = false; | |
} | |
vector<string> xy = ofSplitString(msg[0], ","); | |
float x = ofToInt(xy[0]); | |
float y = ofToInt(xy[1]); | |
Ball* ball = new Ball(x, y, client.getMWidth(), client.getMHeight()); | |
balls.push_back(ball); | |
} | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mousePressed(int x, int y, int button) { | |
// never include a ":" when broadcasting your message | |
// x += client.getXoffset(); | |
// y += client.getYoffset(); | |
// client.broadcast(ofToString(x) + "," + ofToString(y)); | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::windowResized(int w, int h){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "testApp.h" | |
#define RECONNECT_TIME 400 | |
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
// initialize app | |
ofSetFrameRate(30); | |
ofEnableSmoothing(); | |
ofEnableAlphaBlending(); | |
ofSetBackgroundAuto(false); | |
client.setup("settings.xml", this); | |
// set the random seed | |
ofSeedRandom(1); | |
// add a "randomly" placed ball | |
// Ball* ball = new Ball(ofRandom(0, client.getMWidth()), ofRandom(0, client.getMHeight()), client.getMWidth(), client.getMHeight()); | |
// balls.push_back(ball); | |
// start client | |
client.start(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::frameEvent() { | |
// clear the x | |
ofBackground(255, 255, 255); | |
// // move and draw all the balls | |
// for (int i = 0; i < balls.size(); i++) { | |
// balls[i]->calc(); | |
// balls[i]->draw(); | |
// } | |
// read any incoming messages | |
// if (client.messageAvailable()) { | |
// vector<string> msg = client.getDataMessage(); | |
// vector<string> xy = ofSplitString(msg[0], ","); | |
// float x = ofToInt(xy[0]); | |
// float y = ofToInt(xy[1]); | |
// Ball* ball = new Ball(x, y, client.getMWidth(), client.getMHeight()); | |
// balls.push_back(ball); | |
// } | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyReleased(int key){ | |
if(key == '1'){ | |
client.broadcast(ofToString(1)); | |
} | |
if (key == '0') { | |
client.broadcast(ofToString(0)); | |
} | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mousePressed(int x, int y, int button) { | |
// never include a ":" when broadcasting your message | |
x += client.getXoffset(); | |
y += client.getYoffset(); | |
client.broadcast(ofToString(x) + "," + ofToString(y)); | |
cout << ofToString(x) + "," + ofToString(y) << endl; | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::windowResized(int w, int h){ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment