From 7ff3ebe50cd272176daff0de4aee32c1dc0f3320 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 9 Jan 2012 16:36:57 +0000 Subject: xmlising settings --- src/main.cpp | 16 +++++-------- src/testApp.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++--------- src/testApp.h | 8 +++++-- src/viewpoint.cpp | 37 ++++++++++++++++++----------- src/viewpoint.h | 15 ++++++++---- 5 files changed, 103 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index ac9bc8c..57716da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,20 +2,16 @@ #include "testApp.h" #include "ofAppGlutWindow.h" -// Includes for Mac OSX - -#include -#include -#include - -/* - //Includes for Windows - +#ifdef TARGET_OSX + #include + #include + #include +#else #include #include #include #include - */ +#endif //======================================================================== int main( ){ diff --git a/src/testApp.cpp b/src/testApp.cpp index 2094c34..b93f4be 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,10 +1,13 @@ #include "testApp.h" - +//-------------------------------------------------------------- +testApp::~testApp(){ + saveSettings(); +} //-------------------------------------------------------------- void testApp::setup(){ + ofBackground(0,0,0); - ///ofSetVerticalSync(true); //some model / light stuff @@ -12,7 +15,7 @@ void testApp::setup(){ glShadeModel (GL_SMOOTH); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); - + //load the bottle model - the 3ds and the texture file need to be in the same folder bottle.loadModel("bottle.3DS", 1); bottle.setRotation(0, 180, 1, 0, 0); @@ -25,13 +28,7 @@ void testApp::setup(){ mode=CALIBRATE; - views=new viewpoint[2]; - - //todo: read this from xml - numViews=2; - views[0].setup(ofGetWidth()/2,ofGetHeight(),0,0); - views[1].setup(ofGetWidth()/2,ofGetHeight(),ofGetWidth()/2,0); - activeView=0; + loadSettings(); } //-------------------------------------------------------------- @@ -95,11 +92,61 @@ void testApp::keyPressed(int key){ case '3': activeView=1; break; - + } } +void testApp::loadSettings(){ + //viewport settings are float/ normalised to 0..1 + if( !XML.loadFile("settings.xml") ){ + printf("unable to load settings.xml check data/ folder\n"); + }else{ + if(XML.pushTag("map4")) { + numViews=XML.getNumTags("view"); + if(numViews) { + views=new viewpoint[numViews]; + for (int i=0;ikeys; + XML.getAttributeNames("settings", keys, 0); + mapsettings; + for (int k=0;kkeys; + XML.getAttributeNames("settings", keys, 0); + for (int k=0;k&settings){ + //setup(float w, float h, float x, float y) { + if (DEBUG) printf("window: %f,%f %fx%f n",ofGetWidth()*ofToFloat(settings["x"]),ofGetHeight()*ofToFloat(settings["y"]),ofGetWidth()*ofToFloat(settings["w"]),ofGetHeight()*ofToFloat(settings["h"])); + window=ofRectangle(ofGetWidth()*ofToFloat(settings["x"]),ofGetHeight()*ofToFloat(settings["y"]),ofGetWidth()*ofToFloat(settings["w"]),ofGetHeight()*ofToFloat(settings["h"])); + distortFactor=ofToFloat(settings["distort"]); renderFBO.allocate(window.width,window.height,GL_RGB); //todo: load/save from xml @@ -22,33 +24,40 @@ void viewpoint::setup(float w, float h, float x, float y) { vars[5].set('j','h',0.0,10,1.0,3.0); vars[6].set('o','l',1000.0,10,1.0,3.0); vars[7].set('q','a',0,.000001,1.0,3.0); - + light.enable(); light.setDirectional(); } +double viewpoint::getSetting(const string& setting){ + if (setting=="x") return window.x/ofGetWidth(); + if (setting=="y") return window.y/ofGetHeight(); + if (setting=="w") return window.width/ofGetWidth(); + if (setting=="h") return window.height/ofGetHeight(); + if (setting=="distort") return distortFactor; +} //-------------------------------------------------------------- void viewpoint::setLight(){ target.setPosition(vars[1].getVal(),vars[2].getVal(),vars[3].getVal()); camera.orbit(vars[5].getVal(), vars[4].getVal(), vars[6].getVal(), target); - camera.lookAt(target,ofVec3f(0,1,0)); + camera.lookAt(target,ofVec3f(0,1,0)); light.setPosition(camera.getGlobalPosition()); } //-------------------------------------------------------------- -void viewpoint::begin(){ +void viewpoint::begin(){ renderFBO.begin(); ofClear(0,0,0); - + camera.begin(); camera.setFov(vars[0].getVal()); } //-------------------------------------------------------------- -void viewpoint::end(){ +void viewpoint::end(){ camera.end(); - + renderFBO.end(); ofPushMatrix(); - + bindTexture(renderFBO); ofNoFill(); ofSetLineWidth(1.0); @@ -78,10 +87,10 @@ void viewpoint::end(){ ofFill(); unbindTexture(renderFBO); ofPopMatrix(); - + ofSetHexColor(0xFFFFFF); - ofDrawBitmapString("camera: "+ofToString(camera.getX(), 2)+","+ofToString(camera.getY(), 2)+","+ofToString(camera.getZ(), 2), 10, ofGetHeight()-30); - ofDrawBitmapString("light: "+ofToString(light.getX(), 2)+","+ofToString(light.getY(), 2)+","+ofToString(light.getZ(), 2), 10, ofGetHeight()-18); + ofDrawBitmapString("camera: "+ofToString(camera.getX(), 2)+","+ofToString(camera.getY(), 2)+","+ofToString(camera.getZ(), 2), window.x+10, window.y+window.height-30); + ofDrawBitmapString("light: "+ofToString(light.getX(), 2)+","+ofToString(light.getY(), 2)+","+ofToString(light.getZ(), 2), window.x+10, window.y+window.height-18); } //-------------------------------------------------------------- void viewpoint::keyPressed(int key){ diff --git a/src/viewpoint.h b/src/viewpoint.h index e66dffa..2b42756 100644 --- a/src/viewpoint.h +++ b/src/viewpoint.h @@ -15,9 +15,14 @@ class viewpoint { public: - void setup(float w, float h, float x, float y); + void setup(map&settings); + double getSetting(const string& setting); + void begin(); void end(); + + void setDefaults(); + void keyPressed(int key); void keyReleased(int key); void setLight(); @@ -36,12 +41,12 @@ class viewpoint { ofNode target; keyVar* vars; - + int lightNum; GLfloat lightColour[]; - + GLfloat* getLightPosition; - - ofLight light; + + ofLight light; }; -- cgit v1.2.3