#include "viewpoint.h" #define DEBUG 1 void viewpoint::setup(map&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 fov=17.25; aspect=1.79; near=1; far=20; vars=new keyVar[8]; vars[0].set('w','s',17.25,0.5,1.0,3.0); vars[1].set('g','d',0.0,10,1.0,3.0); vars[2].set('r','v',112,10,1.0,3.0); vars[3].set('t','c',0.0,10,1.0,3.0); vars[4].set('u','n',0.0,10,1.0,3.0); 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)); light.setPosition(camera.getGlobalPosition()); } //-------------------------------------------------------------- void viewpoint::begin(){ renderFBO.begin(); ofClear(0,0,0); camera.begin(); camera.setFov(vars[0].getVal()); } //-------------------------------------------------------------- void viewpoint::end(){ camera.end(); renderFBO.end(); ofPushMatrix(); bindTexture(renderFBO); ofNoFill(); ofSetLineWidth(1.0); //ofSetColor(I_fade1,I_fade1,I_fade1); int gridX=50; int gridY=50; int xStep=window.width/2; int yStep=window.height/2; ofTranslate(window.x+xStep,window.y+yStep); //todo: distort texcoords instead of vertex coords for (float i = -1; i < 1.001; i+=(2.0f/gridY)){ glBegin(GL_QUAD_STRIP); ofPoint p0; ofPoint p1; for (float j = -1; j < 1.001; j+=(2.0f/gridX)){ p0=distort(ofPoint(j,i-(2.0f/gridY)),vars[7].getVal()); p1=distort(ofPoint(j,i),vars[7].getVal()); glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5); glVertex3f(p0.x*xStep,p0.y*yStep,-0.1); glTexCoord2f((j+1)*0.5,(i+1)*0.5); glVertex3f(p1.x*xStep,p1.y*yStep,-0.1); } glEnd(); } ofFill(); unbindTexture(renderFBO); ofPopMatrix(); ofSetHexColor(0xFFFFFF); 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){ for (int i=0;i<8;i++) vars[i].keyPressed(key); if (DEBUG) printf("fov: %f distort: %f\n",vars[0].getVal(),vars[7].getVal()); } //-------------------------------------------------------------- void viewpoint::keyReleased(int key){ for (int i=0;i<8;i++) vars[i].keyReleased(key); }