diff options
Diffstat (limited to 'basedProject/src/ofApp.cpp')
| -rw-r--r-- | basedProject/src/ofApp.cpp | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/basedProject/src/ofApp.cpp b/basedProject/src/ofApp.cpp new file mode 100644 index 0000000..0dc6b46 --- /dev/null +++ b/basedProject/src/ofApp.cpp @@ -0,0 +1,176 @@ +#include "ofApp.h" +//-------------------------------------------------------------- +ofApp::~ofApp(){ + saveSettings("settings.xml"); +} + +//-------------------------------------------------------------- +void ofApp::setup() { + loadSettings("settings.xml"); + + ofBackground(0,0,0); + + ///ofSetVerticalSync(true); + + //some model / light stuff + glEnable (GL_DEPTH_TEST); + glShadeModel (GL_SMOOTH); + glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable (GL_COLOR_MATERIAL); + + ofDisableLighting(); + ofSetGlobalAmbientColor(ofColor(255,255,255)); + + fullscreen=false; + activeView=0; + + xhair.loadImage("crosshairs.png"); +} + +//-------------------------------------------------------------- +void ofApp::update() { + ofSetWindowTitle(ofToString(ofGetFrameRate())); +} + +//-------------------------------------------------------------- +void ofApp::draw() { + + for (int i=0;i<views.size();i++) { + views[i].setLight(); + } + for (int i=0;i<views.size();i++) { + //views[i].begin2d(); + views[i].begin(); + //ofFill(); + //ofEnableAlphaBlending(); + ofSetColor(0, 0, 255, 255); + ofDrawSphere(0,0,0,145); + ofSetColor(0, 255, 0, 255); + ofDrawSphere(200,0,230,75); + ofSetColor(255, 0,0, 255); + ofDrawSphere(-60,-190,280,47.5); + ofSetColor(255, 255,255, 255); + //xhair.draw(0,0,views[i].getWidth(),views[i].getHeight()); + + //views[i].end2d(); + views[i].end(); + } +} + +//-------------------------------------------------------------- +void ofApp::exit() { + +} + +//-------------------------------------------------------------- +void ofApp::keyPressed(int key){ + if (activeView<0) for (int i=0;i<views.size();i++) views[i].keyPressed(key); + else if (activeView<views.size()) views[activeView].keyPressed(key); + switch (key) { + case ' ': + fullscreen=!fullscreen; + ofSetFullscreen(fullscreen); + break; + case '8': + //mode=CALIBRATE; + break; + case '9': + //mode=DISPLAY; + break; + case '0': + //mode=GRAB; + break; + case '1': + activeView=-1; + break; + case '2': + activeView=0; + break; + case '3': + activeView=1; + break; + case '4': + activeView=2; + break; + case 'p': + saveSettings("settings.xml"); + break; + case 'z': + loadSettings("defaults.xml"); + break; + case ',': + case '<': + //prevMovie(); + break; + case '.': + case '>': + //nextMovie(); + break; + case '/': + //light=!light; + //printf(light?"LIGHT ON\n":"LIGHT OFF\n"); + break; + } +} + +void ofApp::keyReleased(int key){ + if (activeView<0) for (int i=0;i<views.size();i++) views[i].keyReleased(key); + else if (activeView<views.size()) views[activeView].keyReleased(key); +} + +void ofApp::loadSettings(string filename){ + //viewport settings are float/ normalised to 0..1 + if( !XML.loadFile(filename) ){ + printf("unable to load %s check data/ folder\n",filename.c_str()); + }else{ + if(XML.pushTag("map4")) { + int numViews=XML.getNumTags("view"); + if(numViews) { + views.resize(numViews); + for (int i=0;i<numViews;i++){ + XML.pushTag("view",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + map<string,string>settings; + for (int k=0;k<keys.size();k++) { + settings[keys[k]]=XML.getAttribute("settings",keys[k],"none",0); + } + views[i].setup(settings); + XML.popTag(); + } + } + XML.popTag(); + } + printf("loaded settings: %i views\n",views.size()); + } + + //numViews=2; + //views[0].setup(ofGetScreenWidth()/2,ofGetScreenHeight(),0,0); + //views[1].setup(ofGetScreenWidth()/2,ofGetScreenHeight(),ofGetScreenWidth()/2,0); + //activeView=0; +} +//-------------------------------------------------------------- +void ofApp::saveSettings(string filename){ + //either re-navigate the whole thing OR + //save the number to the vp OR + //send a pointer to the vp + + //renavigate? easiest way to get the settings back out + if(XML.pushTag("map4")) { + for (int i=0;i<views.size();i++){ + XML.pushTag("view",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + for (int k=0;k<keys.size();k++) { + XML.setAttribute("settings", keys[k], views[i].getSetting(keys[k]),0); + } + XML.popTag(); + } + XML.popTag(); + } + XML.saveFile(filename); + printf("saved %s\n",filename.c_str()); +} + +//-------------------------------------------------------------- + |
