summaryrefslogtreecommitdiff
path: root/osctest/src
diff options
context:
space:
mode:
Diffstat (limited to 'osctest/src')
-rw-r--r--osctest/src/main.cpp13
-rw-r--r--osctest/src/ofApp.cpp133
-rw-r--r--osctest/src/ofApp.h64
3 files changed, 210 insertions, 0 deletions
diff --git a/osctest/src/main.cpp b/osctest/src/main.cpp
new file mode 100644
index 0000000..372cbf9
--- /dev/null
+++ b/osctest/src/main.cpp
@@ -0,0 +1,13 @@
+#include "ofMain.h"
+#include "ofApp.h"
+
+//========================================================================
+int main( ){
+ ofSetupOpenGL(400,300, OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ ofRunApp( new ofApp());
+
+}
diff --git a/osctest/src/ofApp.cpp b/osctest/src/ofApp.cpp
new file mode 100644
index 0000000..918480e
--- /dev/null
+++ b/osctest/src/ofApp.cpp
@@ -0,0 +1,133 @@
+#include "ofApp.h"
+
+
+
+//--------------------------------------------------------------
+void ofApp::setup(){
+ ofSetVerticalSync(true);
+
+
+ gui.setup(""); // most of the time you don't need a name but don't forget to call setup
+
+ gui.add(enable.set("enable", true));
+ gui.add(duration.set("duration", 1.0f,0.0f,10.0f));
+ gui.add(spawnProbability.set("spawn", 0.1f));
+
+
+ bHide = false;
+
+}
+
+//--------------------------------------------------------------
+void ofApp::exit(){
+
+}
+
+
+//--------------------------------------------------------------
+void ofApp::update(){
+ if (ofRandom(1.0f)<(spawnProbability/ofGetFrameRate())){
+ tracers.push_back(tracer());
+ ofLog() << "new tracer: "<<tracers[tracers.size()-1].colour;
+ }
+ // open an outgoing connection to HOST:PORT
+ sender.setup(HOST, PORT);
+}
+
+//--------------------------------------------------------------
+void ofApp::draw(){
+ ofBackground(ofColor::black);
+
+ ofxOscBundle bundle;
+
+ auto t=tracers.begin();
+ while (t!=tracers.end()){
+ if (ofGetElapsedTimef()-t->born>duration){
+ tracers.erase(t);
+ }
+ else {
+ if (enable){
+ ofxOscMessage m;
+ m.setAddress("/xyrgb");
+ m.addFloatArg(t->pos.x);
+ m.addFloatArg(t->pos.y);
+ m.addIntArg(t->colour.r);
+ m.addIntArg(t->colour.g);
+ m.addIntArg(t->colour.b);
+ bundle.addMessage(m);
+ t->draw();
+ }
+ t++;
+ }
+ }
+
+ sender.sendBundle(bundle);
+
+
+ if( !bHide ){
+ gui.draw();
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::keyPressed(int key){
+ if( key == 'h' ){
+ bHide = !bHide;
+ }
+ if(key == 's') {
+ gui.saveToFile("settings.xml");
+ }
+ if(key == 'l') {
+ gui.loadFromFile("settings.xml");
+ }
+
+}
+
+//--------------------------------------------------------------
+void ofApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseDragged(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void ofApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseEntered(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseExited(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::dragEvent(ofDragInfo dragInfo){
+
+}
diff --git a/osctest/src/ofApp.h b/osctest/src/ofApp.h
new file mode 100644
index 0000000..096630d
--- /dev/null
+++ b/osctest/src/ofApp.h
@@ -0,0 +1,64 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxGui.h"
+#include "ofxOsc.h"
+
+#define HOST "localhost"
+#define PORT 9001
+#define SPOT_RADIUS 2
+
+class tracer{
+ public:
+ tracer(){
+ pos=ofPoint(ofRandom(1.0f),ofRandom(1.0f));
+ born=ofGetElapsedTimef();
+ colour=ofColor(
+ ofRandom(128)+127,
+ ofRandom(128)+127,
+ ofRandom(128)+127);
+ }
+ void draw(){
+ ofSetColor(colour);
+ ofDrawCircle(ofGetWidth()*pos.x,ofGetHeight()*pos.y,SPOT_RADIUS);
+ }
+ ofPoint pos;
+ float born;
+ ofColor colour;
+};
+
+class ofApp : public ofBaseApp{
+
+ public:
+ void setup();
+ void update();
+ void draw();
+
+ void exit();
+
+ void keyPressed(int key);
+ void keyReleased(int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void mouseEntered(int x, int y);
+ void mouseExited(int x, int y);
+ void windowResized(int w, int h);
+ void dragEvent(ofDragInfo dragInfo);
+ void gotMessage(ofMessage msg);
+
+ bool bHide;
+
+ ofParameter<bool> enable;
+ ofParameter<float> duration;
+ ofParameter<float> spawnProbability;
+
+ ofxPanel gui;
+
+ vector<tracer> tracers;
+
+ ofxOscSender sender;
+
+};
+