summaryrefslogtreecommitdiff
path: root/src/viewpoint.cpp
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/viewpoint.cpp
parentc63227ab08ef1caa5efe957d6f9472387c9481ae (diff)
xmlising settings
Diffstat (limited to 'src/viewpoint.cpp')
-rw-r--r--src/viewpoint.cpp37
1 files changed, 23 insertions, 14 deletions
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){