summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp2
-rw-r--r--src/mapUtils.cpp22
-rw-r--r--src/mapUtils.h1
-rw-r--r--src/testApp.cpp78
-rw-r--r--src/testApp.h1
-rw-r--r--src/viewpoint.cpp33
-rw-r--r--src/viewpoint.h7
7 files changed, 59 insertions, 85 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 049d993..3df2e96 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,7 +6,7 @@
int main( ){
ofAppGlutWindow window;
- ofSetupOpenGL(&window, 512,512, OF_WINDOW); // <-------- setup the GL context
+ ofSetupOpenGL(&window, 1024,600, OF_FULLSCREEN); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
diff --git a/src/mapUtils.cpp b/src/mapUtils.cpp
index 1023a40..c6a1955 100644
--- a/src/mapUtils.cpp
+++ b/src/mapUtils.cpp
@@ -5,10 +5,10 @@
* global utils for projection mapping
*
*/
-#pragma once
#include "ofMain.h"
+//texture binding with normalised coords
void bindTexture(ofBaseHasTexture &t) {
ofTexture &tex = t.getTextureReference();
tex.bind();
@@ -75,5 +75,21 @@ void drawBox(float size) {
glTexCoord2f(0.0f, 1.0f); glVertex3f(-size, size, -size); // Top Left Of The Texture and Quad
glEnd();
}
-
-
+void drawBoard(float x,float y,float z) {
+ glPushMatrix();
+ glTranslated(x,y,z);
+ glBegin(GL_QUADS);
+ int cx,cz;
+ for (int i=0;i<8;i++) {
+ for (int j=0;j<4;j++) {
+ cx=((i%2)*16)+(j*32)-56;
+ cz=(i*16)-56;
+ glVertex3f(cx+8, 0, cz-8);
+ glVertex3f(cx+8, 0, cz+8);
+ glVertex3f(cx-8, 0, cz+8);
+ glVertex3f(cx-8, 0, cz-8);
+ }
+ }
+ glEnd();
+ glPopMatrix();
+}
diff --git a/src/mapUtils.h b/src/mapUtils.h
index 002f90a..97af934 100644
--- a/src/mapUtils.h
+++ b/src/mapUtils.h
@@ -13,4 +13,5 @@ void bindTexture(ofBaseHasTexture &t);
void unbindTexture(ofBaseHasTexture &t);
ofPoint distort(ofPoint pt,float d);
void drawBox(float size);
+void drawBoard(float x,float y,float z);
diff --git a/src/testApp.cpp b/src/testApp.cpp
index 10dbdf4..0d42e85 100644
--- a/src/testApp.cpp
+++ b/src/testApp.cpp
@@ -1,11 +1,5 @@
#include "testApp.h"
-GLfloat lightOnePosition[] = {40.0, 40, 100.0, 0.0};
-GLfloat lightOneColor[] = {0.99, 0.99, 0.99, 0.5};
-
-GLfloat lightTwoPosition[] = {-40.0, 40, 100.0, 0.0};
-GLfloat lightTwoColor[] = {0.99, 0.99, 0.99, 0.5};
-
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(0,0,0);
@@ -17,43 +11,27 @@ void testApp::setup(){
glShadeModel (GL_SMOOTH);
/* initialize lighting */
- glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition);
- glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor);
- glEnable (GL_LIGHT0);
- glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition);
- glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor);
- glEnable (GL_LIGHT1);
glEnable (GL_LIGHTING);
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);
- board.loadModel("box.3DS", 1);
bottle.setRotation(0, 180, 1, 0, 0);
- board.setRotation(0, 180, 1, 0, 0);
+ bottle.setPosition(0, 112, 0);
- //you can create as many rotations as you want
- //choose which axis you want it to effect
- //you can update these rotations later on
- //bottleModel.setRotation(0, -90, 1, 0, 0);
- //bottleModel.setRotation(1, 270, 0, 0, 1);
- //bottleModel.setScale(0.9, 0.9, 0.9);
- bottle.setPosition(0, 0, -50);
- board.setPosition(0, 0, -50);
//ofDisableArbTex();
texture.loadMovie("gradblend01.mov");
texture.play();
- mode=NOTHING;
+ mode=CALIBRATE;
views=new viewpoint[1];
//todo: read this from xml
- views[0].setup(ofGetWidth(),ofGetHeight(),0,0);
-
+ views[0].setup(GL_LIGHT0,ofGetWidth(),ofGetHeight(),0,0);
activeView=0;
@@ -61,75 +39,37 @@ void testApp::setup(){
//--------------------------------------------------------------
void testApp::update(){
- board.setRotation(1, 270 + ofGetElapsedTimef() * 60, 0, 1, 0);
texture.idleMovie();
}
//--------------------------------------------------------------
void testApp::draw(){
- //ofPushView();
- //glMatrixMode(GL_PROJECTION);
- //glLoadIdentity();
- //gluPerspective(fov,aspect,near,far);
- // glTranslatef(0,0,-1000);
- //glMatrixMode(GL_MODELVIEW);
- // glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr());
-
- //glEnable(GL_LIGHTING);
- //ofRectangle vp=ofRectangle(0,0,ofGetWidth(),ofGetHeight());
- //camera.setFov(fov);
-
-
- views[0].begin();
+ views[0].setLight();
+ views[0].begin();
ofSetColor(255, 255, 255, 255);
ofFill();
-
switch(mode) {
case CALIBRATE:
-
- int cx,cz;
-
- glFrontFace(GL_CW);
- glBegin(GL_QUADS);
- for (int i=0;i<8;i++) {
- for (int j=0;j<4;j++) {
- cx=((i%2)*16)+(j*32)-56;
- cz=(i*16)-56;
- glVertex3f(cx+8, 0, cz-8);
- glVertex3f(cx+8, 0, cz+8);
- glVertex3f(cx-8, 0, cz+8);
- glVertex3f(cx-8, 0, cz-8);
-
- }
- }
- glEnd();
-
+ drawBoard(0,225,0);
bottle.draw();
-
break;
case DISPLAY:
-
- board.draw();
bindTexture(texture);
bottle.draw();
unbindTexture(texture);
break;
- case NOTHING:
-
+ case NOTHING:
bindTexture(texture);
- glPushMatrix();
+ glPushMatrix();
drawBox(50.0f);
unbindTexture(texture);
- glPopMatrix();
+ glPopMatrix();
break;
}
-
views[0].end();
-
ofSetHexColor(0xFFFFFF);
ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
-
}
//--------------------------------------------------------------
diff --git a/src/testApp.h b/src/testApp.h
index 69cfa4e..14fc09d 100644
--- a/src/testApp.h
+++ b/src/testApp.h
@@ -47,7 +47,6 @@ class testApp : public ofBaseApp{
void gotMessage(ofMessage msg);
ofx3DModelLoader bottle;
- ofx3DModelLoader board;
ofVideoPlayer texture;
diff --git a/src/viewpoint.cpp b/src/viewpoint.cpp
index 5d61f1f..0c7fe8a 100644
--- a/src/viewpoint.cpp
+++ b/src/viewpoint.cpp
@@ -1,7 +1,8 @@
#include "viewpoint.h"
#define DEBUG 0
-void viewpoint::setup(float w, float h, float x, float y) {
+void viewpoint::setup(int ln,float w, float h, float x, float y) {
+ lightNum=ln;
window=ofRectangle(w,h,x,y);
distortFactor=0.0;
renderFBO.allocate(window.width,window.height,GL_RGB);
@@ -13,20 +14,37 @@ void viewpoint::setup(float w, float h, float x, float y) {
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,2.0,3.0);
vars[1].set('g','d',0.0,10,3.0,3.0);
- vars[2].set('r','v',0.0,10,3.0,3.0);
+ vars[2].set('r','v',112,10,3.0,3.0);
vars[3].set('t','c',0.0,10,3.0,3.0);
vars[4].set('u','n',0.0,1.0,3.0,3.0);
vars[5].set('j','h',0.0,1.0,3.0,3.0);
vars[6].set('o','l',1000.0,10,3.0,3.0);
vars[7].set('q','a',0,0.0001,2.0,3.0);
- //camera.setPosition(0,0,vars[6].getVal());
+ camera.setPosition(0,0,vars[6].getVal());
+}
+//--------------------------------------------------------------
+void viewpoint::setLight(){
+ 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[4].getVal(), vars[5].getVal(), vars[6].getVal(), target);
+
+ ofVec3f lp=camera.getGlobalPosition();
+ GLfloat lightPosition[] = {lp.x, lp.y, lp.z};
+ GLfloat lightColour[] = {0.99, 0.99, 0.99, 0.5};
+ glLightfv(lightNum, GL_POSITION, lightPosition);
+ glLightfv(lightNum, GL_DIFFUSE, lightColour);
+ glEnable(lightNum);
}
//--------------------------------------------------------------
void viewpoint::begin(){
@@ -38,11 +56,8 @@ void viewpoint::begin(){
camera.begin();
camera.setFov(vars[0].getVal());
- 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());
-
+
+
}
//--------------------------------------------------------------
diff --git a/src/viewpoint.h b/src/viewpoint.h
index 1a46081..2a43a2d 100644
--- a/src/viewpoint.h
+++ b/src/viewpoint.h
@@ -15,11 +15,12 @@ class viewpoint {
public:
- void setup(float w, float h, float x, float y);
+ void setup(int ln,float w, float h, float x, float y);
void begin();
void end();
void keyPressed(int key);
void keyReleased(int key);
+ void setLight();
ofFbo renderFBO;
@@ -29,12 +30,14 @@ class viewpoint {
ofRectangle window;
-
double fov,aspect,near,far;
ofCamera camera;
ofNode target;
keyVar* vars;
+
+ int lightNum;
+ GLfloat lightColour[];
};