summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-01-09 16:36:57 +0000
committerTim Redfern <tim@eclectronics.org>2012-01-09 16:36:57 +0000
commit7ff3ebe50cd272176daff0de4aee32c1dc0f3320 (patch)
tree0dbebbef6fe8688bf9ac98f415b542b1e100bda6 /src
parentc63227ab08ef1caa5efe957d6f9472387c9481ae (diff)
xmlising settings
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp16
-rw-r--r--src/testApp.cpp69
-rw-r--r--src/testApp.h8
-rw-r--r--src/viewpoint.cpp37
-rw-r--r--src/viewpoint.h15
5 files changed, 103 insertions, 42 deletions
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 <GLUT/glut.h>
-#include <OpenGL/gl.h>
-#include <OpenGL/glu.h>
-
-/*
- //Includes for Windows
-
+#ifdef TARGET_OSX
+ #include <GLUT/glut.h>
+ #include <OpenGL/gl.h>
+ #include <OpenGL/glu.h>
+#else
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
#include <iostream>
- */
+#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;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();
+ }
+ }
+ //numViews=2;
+ //views[0].setup(ofGetWidth()/2,ofGetHeight(),0,0);
+ //views[1].setup(ofGetWidth()/2,ofGetHeight(),ofGetWidth()/2,0);
+ //activeView=0;
+}
+//--------------------------------------------------------------
+void testApp::saveSettings(){
+ //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<numViews;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("settings.xml");
+}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
if (activeView<0) for (int i=0;i<numViews;i++) views[i].keyReleased(key);
diff --git a/src/testApp.h b/src/testApp.h
index 95aabf7..dadad43 100644
--- a/src/testApp.h
+++ b/src/testApp.h
@@ -25,19 +25,22 @@ have to track how many frames each key has been pressed for
#define NOTHING 3
#include "ofMain.h"
+#include "ofxXmlSettings.h"
#include "ofx3DModelLoader.h"
+
#include "mapUtils.h"
#include "viewpoint.h"
-
-
class testApp : public ofBaseApp{
public:
+ ~testApp();
void setup();
void update();
void draw();
+ void loadSettings();
+ void saveSettings();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
@@ -58,4 +61,5 @@ class testApp : public ofBaseApp{
int mode;
+ ofxXmlSettings XML;
};
diff --git a/src/viewpoint.cpp b/src/viewpoint.cpp
index 225ad0f..31d2ec7 100644
--- a/src/viewpoint.cpp
+++ b/src/viewpoint.cpp
@@ -1,9 +1,11 @@
#include "viewpoint.h"
-#define DEBUG 0
+#define DEBUG 1
-void viewpoint::setup(float w, float h, float x, float y) {
- window=ofRectangle(x,y,w,h);
- distortFactor=0.0;
+void viewpoint::setup(map<string,string>&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<string,string>&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;
};