#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[7]; //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,0.2,3.0,3.0); vars[2].set('r','v',0.0,0.2,3.0,3.0); vars[3].set('t','c',0.0,0.2,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',0.0,0.2,3.0,3.0); } //-------------------------------------------------------------- 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()); 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.move(0,0,vars[6].getInc()); 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); // add polygons here //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); */ ofSetHexColor(0xFFFFFF); ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15); //ofDrawBitmapString("segmentpow: "+ofToString(pow(vars[0].segment,vars[0].accel), 2), 10, 25); } //-------------------------------------------------------------- void testApp::keyPressed(int key){ for (int i=0;i<7;i++) vars[i].keyPressed(key); } //-------------------------------------------------------------- void testApp::keyReleased(int key){ for (int i=0;i<7;i++) vars[i].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(); }