summaryrefslogtreecommitdiff
path: root/src/testApp.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@sendak.local>2011-12-19 13:37:11 +0000
committerTim Redfern <tim@sendak.local>2011-12-19 13:37:11 +0000
commitf96ac8a05c915832c0efe5e70264245fca15b33e (patch)
tree366fea81a62199fb5d0521c91fe6e0c9bd2243e0 /src/testApp.cpp
linux osx project initial
Diffstat (limited to 'src/testApp.cpp')
-rw-r--r--src/testApp.cpp434
1 files changed, 434 insertions, 0 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp
new file mode 100644
index 0000000..8e1bb77
--- /dev/null
+++ b/src/testApp.cpp
@@ -0,0 +1,434 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup(){
+ ofBackground(0,0,0);
+
+ ///ofSetVerticalSync(true);
+
+ //some model / light stuff
+ glEnable (GL_DEPTH_TEST);
+ glShadeModel (GL_SMOOTH);
+
+
+
+ texture.loadMovie("gradblend01.mov");
+ texture.play();
+
+
+ //approx 200 x 108 x 60
+ //275:492
+ //vfov = sin t/2 = 30/200 = 0.15
+ fov=17.25;
+ aspect=1.79;
+ near=1;
+ far=20;
+
+ camera.setParent(target);
+ camera.setPosition(0,0,200);
+
+ vars=new keyVar[9];
+
+ vars[0].set('w','s',17.25,1.0,1.0,2.0);
+
+ /*
+
+case 'w':
+ fov*=0.99;
+ break;
+case 's':
+ fov*=1.01;
+ break;
+
+ //nav stuff
+case 'g':
+ target.move(1,0,0);
+ break;
+case 'd':
+ target.move(-1,0,0);
+ break;
+case 'r':
+ target.move(0,1,0);
+ break;
+case 'v':
+ target.move(0,-1,0);
+ break;
+case 'c':
+ target.move(0,0,1);
+ break;
+case 't':
+ target.move(0,0,-1);
+ break;
+
+case 'h':
+ target.rotate(1,0,1,0);
+ break;
+case 'j':
+ target.rotate(-1,0,1,0);
+ break;
+case 'u':
+ target.rotate(1,1,0,0);
+ break;
+case 'n':
+ target.rotate(-1,1,0,0);
+ break;
+
+case 'o':
+ camera.move(0,0,1);
+ break;
+case 'l':
+ camera.move(0,0,-1);
+ break;
+
+ */
+
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+
+ texture.idleMovie();
+}
+
+//--------------------------------------------------------------
+void testApp::draw(){
+ //http://njoubert.com/teaching/cs184_fa08/section/sec09_camera.pdf
+ //is good
+
+ //ofPushView();
+ /*
+ glMatrixMode(GL_PROJECTION);
+ //glPushMatrix();
+ //glViewport( 0 ,0 ,ofGetWidth(),ofGetHeight() ) ;
+ glLoadIdentity();
+ gluPerspective(fov,aspect,near,far);
+ //glTranslatef(x,y,z);
+ gluLookAt(x,y,z, 0,0,0, 0,1,0);
+ glMatrixMode(GL_MODELVIEW);
+ // glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr());
+ */
+
+ camera.begin();
+ camera.setFov(vars[0].getVal());
+
+
+ ofBackground(0);
+
+ ofSetColor(255,0,0);
+ ofFill();
+ ofBox(30);
+ ofNoFill();
+ ofSetColor(0);
+ ofBox(30);
+
+ ofPushMatrix();
+ ofTranslate(0,0,20);
+ ofSetColor(0,0,255);
+ ofFill();
+ ofBox(5);
+ ofNoFill();
+ ofSetColor(0);
+ ofBox(5);
+ ofPopMatrix();
+ camera.end();
+
+
+ //glEnable(GL_LIGHTING);
+ //ofRectangle vp=ofRectangle(0,0,ofGetWidth(),ofGetHeight());
+ //camera.setFov(fov);
+
+
+/*
+ //draw in middle of the screen
+ glPushMatrix();
+ //glTranslatef(ofGetWidth()/2,ofGetHeight()/2,0);
+ GLUquadricObj *sphere;
+ sphere= gluNewQuadric();
+
+ gluQuadricDrawStyle(sphere, GLU_FILL );
+ gluSphere(sphere, 50, 10, 10);
+
+ //fake back wall
+ ofSetColor(220, 20, 20);
+ glBegin(GL_QUADS);
+ glVertex3f(-50,50, -50);
+ glVertex3f(50, 50, -50);
+ glVertex3f(50, -50, -50);
+ glVertex3f(-50, -50, -50);
+
+ glVertex3f(50, -50, 50);
+ glVertex3f(-50, -50, 50);
+ glVertex3f(-50,50, 50);
+ glVertex3f(50, 50, 50);
+
+ glEnd();
+
+ //fake wall
+ ofSetColor(50, 150, 50);
+ glBegin(GL_QUADS);
+ glVertex3f(-50,-50 ,50);
+ glVertex3f(50,-50, 50);
+ glVertex3f(50,-50, -50);
+ glVertex3f(-50,-50, -50);
+
+ glVertex3f(50,50, -50);
+ glVertex3f(-50,50, -50);
+ glVertex3f(-50,50 ,50);
+ glVertex3f(50,50, 50);
+ glEnd();
+
+ glPopMatrix();
+*/
+
+ /*
+ //lets tumble the world with the mouse
+ glPushMatrix();
+
+
+ //tumble according to mouse
+ glRotatef(-mouseY,1,0,0);
+ glRotatef(mouseX,0,1,0);
+ glTranslatef(-ofGetWidth()/2,-ofGetHeight()/2,0);
+*/
+ ofSetColor(255, 255, 255, 255);
+ ofFill();
+
+ //renderFBO.begin(); //render to FOB
+ // ofClear(0,0,0);
+
+
+
+
+
+
+ //texture.getTextureReference().bind();
+
+
+/*
+ glBegin(GL_QUAD_STRIP);
+ glTexCoord2f (0.0, 0.0);
+ glVertex3f(ofGetWidth()/4,ofGetHeight()/4,0);
+ glTexCoord2f (0.0, 1.0);
+ glVertex3f(ofGetWidth()/4,(3*ofGetHeight())/4,0);
+ glTexCoord2f (1.0, 0.0);
+ glVertex3f((3*ofGetWidth())/4,ofGetHeight()/4,0);
+ glTexCoord2f (1.0, 1.0);
+ glVertex3f((3*ofGetWidth())/4,(3*ofGetHeight())/4,0);
+ glEnd();
+ */
+
+ //texture.getTextureReference().unbind();
+
+
+/*
+ renderFBO.end();
+
+ //glPopMatrix();
+
+ //renderFBO.draw(0,0);
+
+ glPushMatrix();
+
+ //renderFBO.getTextureReference().bind();
+ 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;
+ int gridY=50;
+ int xStep=ofGetWidth()/2;
+ int yStep=ofGetHeight()/2;
+ ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
+
+ 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)),distortFactor);
+ p1=distort(ofPoint(j,i),distortFactor);
+ glTexCoord2f((j+1)*0.5,((i-(2.0f/gridY))+1)*0.5);
+ glVertex3f(p0.x*xStep,p0.y*yStep,0);
+ glTexCoord2f((j+1)*0.5,(i+1)*0.5);
+ glVertex3f(p1.x*xStep,p1.y*yStep,0);
+ }
+ glEnd();
+ }
+
+ ofFill();
+ glPopMatrix();
+
+ //renderFBO.getTextureReference().unbind();
+ unbindTexture(renderFBO);
+
+ ofSetHexColor(0x000000);
+ ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
+
+
+ // add polygons here
+ //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+ */
+
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed(int key){
+ vars[0].keyPressed(key);
+ switch (key) {
+ /*
+ case 'w':
+ fov*=0.99;
+ break;
+ case 's':
+ fov*=1.01;
+ break;
+ */
+
+ //nav stuff
+ case 'g':
+ target.move(1,0,0);
+ break;
+ case 'd':
+ target.move(-1,0,0);
+ break;
+ case 'r':
+ target.move(0,1,0);
+ break;
+ case 'v':
+ target.move(0,-1,0);
+ break;
+ case 'c':
+ target.move(0,0,1);
+ break;
+ case 't':
+ target.move(0,0,-1);
+ break;
+
+ case 'h':
+ target.rotate(1,0,1,0);
+ break;
+ case 'j':
+ target.rotate(-1,0,1,0);
+ break;
+ case 'u':
+ target.rotate(1,1,0,0);
+ break;
+ case 'n':
+ target.rotate(-1,1,0,0);
+ break;
+
+ case 'o':
+ camera.move(0,0,1);
+ break;
+ case 'l':
+ camera.move(0,0,-1);
+ break;
+ }
+ //printf("xyx: %f,%f,%f rxry: %f,%f fov: %f\n",cx,cy,cz,crx,cry,fov);
+
+}
+
+//--------------------------------------------------------------
+void testApp::keyReleased(int key){
+ //printf("released %i\n",key);
+ vars[0].keyReleased(key);
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void testApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+void testApp::dragEvent(ofDragInfo dragInfo){
+
+}
+void testApp::bindTexture(ofBaseHasTexture &t) {
+ ofTexture &tex = t.getTextureReference();
+ tex.bind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPushMatrix();
+ glLoadIdentity();
+
+ ofTextureData texData = tex.getTextureData();
+ if(texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) {
+ glScalef(tex.getWidth(), tex.getHeight(), 1.0f);
+ } else {
+ glScalef(tex.getWidth() / texData.tex_w, tex.getHeight() / texData.tex_h, 1.0f);
+ }
+
+ glMatrixMode(GL_MODELVIEW);
+}
+void testApp::unbindTexture(ofBaseHasTexture &t) {
+ t.getTextureReference().unbind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+}
+
+void testApp::drawBox() {
+ // this func just draws a perfectly normal box with some texture coordinates
+ glBegin(GL_QUADS);
+ // Front Face
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
+ // Back Face
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
+ // Top Face
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
+ // Bottom Face
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
+ // Right face
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
+ glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
+ glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
+ // Left Face
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
+ glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
+ glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
+ glEnd();
+}
+