summaryrefslogtreecommitdiff
path: root/src/viewpoint.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-01-04 23:03:45 +0000
committerTim Redfern <tim@eclectronics.org>2012-01-04 23:03:45 +0000
commit16cc03c435982383627dd01341656d0371ca1f2b (patch)
treeb4faad19f0c6b28da72a2050e49c22bb2322a3ce /src/viewpoint.cpp
parent64a4a42ee6826584c38c09a2b5976356e4488993 (diff)
tidied up
Diffstat (limited to 'src/viewpoint.cpp')
-rw-r--r--src/viewpoint.cpp53
1 files changed, 5 insertions, 48 deletions
diff --git a/src/viewpoint.cpp b/src/viewpoint.cpp
index efb6894..daca64f 100644
--- a/src/viewpoint.cpp
+++ b/src/viewpoint.cpp
@@ -1,8 +1,7 @@
#include "viewpoint.h"
#define DEBUG 0
-void viewpoint::setup(int ln,float w, float h, float x, float y) {
- lightNum=ln;
+void viewpoint::setup(float w, float h, float x, float y) {
window=ofRectangle(w,h,x,y);
distortFactor=0.0;
renderFBO.allocate(window.width,window.height,GL_RGB);
@@ -13,10 +12,8 @@ void viewpoint::setup(int ln,float w, float h, float x, float y) {
near=1;
far=20;
- //camera.setParent(target);
vars=new keyVar[8];
- //void set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float accelTime);
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);
@@ -26,69 +23,34 @@ void viewpoint::setup(int ln,float w, float h, float x, float y) {
vars[6].set('o','l',1000.0,10,1.0,3.0);
vars[7].set('q','a',0,1,1.0,3.0);
- //camera.setPosition(0,0,vars[6].getVal());
-
- getLightPosition=new GLfloat[4];
-
light.enable();
light.setDirectional();
}
//--------------------------------------------------------------
void viewpoint::setLight(){
- //glLoadIdentity();
- //glPushMatrix();
target.setPosition(vars[1].getVal(),vars[2].getVal(),vars[3].getVal());
- /*
- target.rotate(vars[4].getInc(),1,0,0);
- target.rotate(vars[5].getInc(),0,1,0);
- camera.setPosition(0,0,vars[6].getVal());
- */
-
camera.orbit(vars[5].getVal(), vars[4].getVal(), vars[6].getVal(), target);
camera.lookAt(target,ofVec3f(0,1,0));
- //glPopMatrix();
- //ofVec3f lp=camera.getGlobalPosition();
light.setPosition(camera.getGlobalPosition());
- /*
- GLfloat lightPosition[] = {lp.x, lp.y, lp.z,1};
- GLfloat lightColour[] = {0.99, 0.99, 0.99, 0.5};
-
- glLightfv(lightNum, GL_POSITION, lightPosition);
- glLightfv(lightNum, GL_DIFFUSE, lightColour);
- glEnable(lightNum);
- glGetLightfv(lightNum,GL_POSITION, getLightPosition);
- */
}
//--------------------------------------------------------------
-void viewpoint::begin(){
-
+void viewpoint::begin(){
renderFBO.begin();
ofClear(0,0,0);
- //ofPushView();
-
camera.begin();
camera.setFov(vars[0].getVal());
-
-
-
- }
+}
//--------------------------------------------------------------
-void viewpoint::end(){
-
+void viewpoint::end(){
camera.end();
- //ofPopView();
renderFBO.end();
ofPushMatrix();
bindTexture(renderFBO);
-
- //draw a grid
- //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
ofNoFill();
-
ofSetLineWidth(1.0);
//ofSetColor(I_fade1,I_fade1,I_fade1);
int gridX=50;
@@ -97,8 +59,8 @@ void viewpoint::end(){
int yStep=ofGetHeight()/2;
ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
+ //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;
@@ -110,21 +72,16 @@ void viewpoint::end(){
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), 10, ofGetHeight()-30);
ofDrawBitmapString("light: "+ofToString(light.getX(), 2)+","+ofToString(light.getY(), 2)+","+ofToString(light.getZ(), 2), 10, ofGetHeight()-18);
-
}
//--------------------------------------------------------------
void viewpoint::keyPressed(int key){