diff options
| -rw-r--r-- | 03_play/src/testApp.cpp | 112 | ||||
| -rw-r--r-- | 03_play/src/testApp.h | 27 | ||||
| -rw-r--r-- | 04_playobjects/src/testApp.cpp | 8 | ||||
| -rw-r--r-- | 04_playobjects/src/testApp.h | 55 |
4 files changed, 175 insertions, 27 deletions
diff --git a/03_play/src/testApp.cpp b/03_play/src/testApp.cpp index 1688ef3..3095a18 100644 --- a/03_play/src/testApp.cpp +++ b/03_play/src/testApp.cpp @@ -1,5 +1,30 @@ #include "testApp.h" +//texture binding with normalised coords +void 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 unbindTexture(ofBaseHasTexture &t) { + t.getTextureReference().unbind(); + + glMatrixMode(GL_TEXTURE); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); +} //-------------------------------------------------------------- void testApp::setup() { @@ -43,6 +68,13 @@ void testApp::setup() { offset=0.0f; drawmovies=false;drawcloud=true; frame=0; + + target.setPosition(0,0,0); + camera.setPosition(0,0,-500); + camera.lookAt(target,ofVec3f(0,1,0)); + + point_texture.loadImage("spriteA.png"); + } void testApp::startPlayers(){ @@ -50,6 +82,7 @@ void testApp::startPlayers(){ //openNIPlayers[deviceID].stop(); openNIPlayers[deviceID].setup(true); usleep(100000); + openNIPlayers[deviceID].setMirror(true); //? openNIPlayers[deviceID].start(); openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing].data[deviceID])); //openNIPlayers[deviceID].setSpeed(0.01f); @@ -76,18 +109,35 @@ void testApp::update(){ //-------------------------------------------------------------- void testApp::draw(){ - ofBackground(50, 50, 50); + ofBackground(0,0,0); ofSetColor(255, 255, 255); +/* + glEnable(GL_PROGRAM_POINT_SIZE); + glEnable(GL_POINT_SMOOTH); + glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); - //glEnable(GL_PROGRAM_POINT_SIZE); - //glEnable(GL_POINT_SMOOTH); - //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + glPointSize(12.0f); + */ - //glPointSize(12.0f); + glEnable( GL_POINT_SPRITE ); // GL_POINT_SPRITE_ARB if you're + // using the functionality as an extension. + glEnable( GL_POINT_SMOOTH ); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glPointSize( 2.0 ); + + + glActiveTexture(GL_TEXTURE0); + glEnable( GL_TEXTURE_2D ); + //glTexEnv(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); + //glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + //glBindTexture(GL_TEXTURE_2D, texture_name); + bindTexture(point_texture); + //ofEnablePointSprites(); for (int deviceID = 0; deviceID < numDevices; deviceID++){ @@ -110,11 +160,12 @@ void testApp::draw(){ if (drawcloud) { - cam.begin(); + camera.begin(); ofPushMatrix(); - ofRotate(0,1,0,180); - ofTranslate(0,0,1500); + + ofRotateY(ofGetElapsedTimef()*2.0f); + ofTranslate(0,0,-1100); @@ -123,35 +174,57 @@ void testApp::draw(){ int count; const XnDepthPixel* depthmap=openNIPlayers[deviceID].getDepthGenerator().GetDepthMap(); - int range=2500; + const ofPixels& pixels=openNIPlayers[deviceID].getImagePixels(); + int range=1500; + + int step=pixels.getWidth()/openNIPlayers[deviceID].getWidth(); int dmw=openNIPlayers[deviceID].getWidth(); - for (int i=0;i<openNIPlayers[deviceID].getWidth();i+=2) { + //for (int i=0;i<openNIPlayers[deviceID].getWidth();i+=20) { - glBegin(GL_LINES); + - for (int j=0;j<openNIPlayers[deviceID].getHeight();j+=2) { + //for (int j=0;j<openNIPlayers[deviceID].getHeight();j+=20) { + for (int o=0;o<2000;o++) { //100 new points per frame + int i=ofRandom(openNIPlayers[deviceID].getWidth()); + int j=ofRandom(openNIPlayers[deviceID].getHeight()); ofPoint p= openNIPlayers[deviceID].projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i])); //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i])); - if (p.z == 0 || p.z>range) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd + if (p.z <100 || p.z>range) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd //ofColor color = kinect->getColorAt(x,y); //userID); //if (col) glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); // else + points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2,20,0.5)); + - glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255); - glVertex3f(p.x, p.y, p.z); + //glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255); + //glColor4ub(pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2, (unsigned char)255); + //glVertex3f(p.x, p.y, p.z); //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl; + } + //} + + //} - glEnd(); - } + glBegin(GL_POINTS); + int p=0; + while (p < points.size()) { + if (points[p].draw()) { + points.erase( points.begin() + p ); + } else { + ++p; + } + } + + glEnd(); //export for fast/ switchable playback //figure out how to line up (could be one off) @@ -167,13 +240,16 @@ void testApp::draw(){ ofPopMatrix(); - cam.end(); + camera.end(); glDisable(GL_PROGRAM_POINT_SIZE); } } + //ofDisablePointSprites(); + unbindTexture(point_texture); + ofSetColor(255, 255, 255); string msg = "MILLIS: " + ofToString(ofGetElapsedTimeMillis()); msg += "\nFPS: " + ofToString(ofGetFrameRate()); diff --git a/03_play/src/testApp.h b/03_play/src/testApp.h index 67cd4dc..7453e44 100644 --- a/03_play/src/testApp.h +++ b/03_play/src/testApp.h @@ -13,6 +13,28 @@ struct record{ string audio; }; +class fpoint{ + public: + fpoint(float _x,float _y, float _z, unsigned char _r,unsigned char _g,unsigned char _b,float _ay,float _lt){ + x=_x;y=_y;z=_z;r=_r;g=_g;b=_b;ay=_ay;dy=0;st=ofGetElapsedTimef(),lt=_lt; + } + float x,y,z; + float st; + float dy; + float ay; + unsigned char r,g,b; + float lt; + bool draw(){ + float l=ofGetElapsedTimef()-st; + if (lt>l) { + glColor4ub(r,g,b, (unsigned char)((l/lt)*255.0f)); + glVertex3f(x,y-(pow(l,2)*ay),z); + return false; + } + else return true; + } +}; + class testApp : public ofBaseApp{ public: @@ -47,10 +69,15 @@ public: float offset; ofxMayaCam cam; + ofCamera camera; + ofNode target; bool drawmovies,drawcloud; int frame; + + ofImage point_texture; + vector<fpoint> points; }; #endif diff --git a/04_playobjects/src/testApp.cpp b/04_playobjects/src/testApp.cpp index 6351282..fe26030 100644 --- a/04_playobjects/src/testApp.cpp +++ b/04_playobjects/src/testApp.cpp @@ -68,7 +68,7 @@ void testApp::update(){ if (newplaying!=playing) startPlayers(newplaying); - players[playing].update(); + if (playing>-1) players[playing].update(); } //-------------------------------------------------------------- @@ -84,11 +84,11 @@ void testApp::draw(){ } if (drawcloud) { - cam.begin(); - ofTranslate(ofGetWidth()/2, ofGetHeight()/2,0); + //cam.begin(); + ofTranslate(ofGetWidth(), ofGetHeight()/2,0); players[playing].drawCloud(); ofDrawAxis(100); - cam.end(); + //cam.end(); } } diff --git a/04_playobjects/src/testApp.h b/04_playobjects/src/testApp.h index 32e6dad..e1f1e5c 100644 --- a/04_playobjects/src/testApp.h +++ b/04_playobjects/src/testApp.h @@ -20,6 +20,7 @@ struct record{ //in order to play different clips it seems necessary to have a player per clip class syncOniPlayer{ public: + syncOniPlayer() {drawable=false;} ~syncOniPlayer(){ stop(); } @@ -40,7 +41,7 @@ class syncOniPlayer{ for (int i=0;i<players.size();i++) { players[i]=new ofxOpenNI(); //players[i]->setSafeThreading(true); - players[i]->setupFromONI(filenames[i],false); + players[i]->setupFromONI(filenames[i],true); //players[i]->addDepthGenerator(); //players[i]->addImageGenerator(); //players[i]->setRegister(true); @@ -52,6 +53,8 @@ class syncOniPlayer{ soundplayer.loadSound(audio); soundplayer.play(); }; + //sleep(2); + drawable=true; } } void update(){ @@ -70,11 +73,47 @@ class syncOniPlayer{ else return -1; } void drawWindows(){ + if (!drawable) return; for (int i=0;i<players.size();i++) { if (players[i]==NULL) break; ofTranslate(0, i * 400); players[i]->drawDepth(50, 0,520,390); players[i]->drawImage(600, 0,520,390); + + const XnDepthPixel* depthmap=players[i]->getDepthGenerator().GetDepthMap(); + + + int range=2500; + + + + int dmw=players[i]->getWidth(); + + //for (int i=0;i<players[i]->getWidth();i+=2) { + + glBegin(GL_LINES); + + //for (int j=0;j<players[i]->getHeight();j+=2) { + + ofPoint p= players[i]->projectiveToWorld(ofPoint(300,150,(float)(depthmap[1200]))); +/* + ofPoint p= players[i]->projectiveToWorld(ofPoint(i,j,(float)(depthmap[j*dmw+i]))); + //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i])); + + if (p.z == 0 || p.z>range) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd + //ofColor color = kinect->getColorAt(x,y); //userID); + //if (col) glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); + // else + + + glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255); + glVertex3f(p.x, p.y, p.z); + //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl; + */ + //} + + glEnd(); + //} } } void drawCloud(){ @@ -103,14 +142,17 @@ class syncOniPlayer{ int count; for (int i=0;i<players.size();i++) { + if (players[i]==0x00) { + cerr<<"more spooky shit....!"; + return; + } + const XnDepthPixel* depthmap=players[i]->getDepthGenerator().GetDepthMap(); //uint16_t* depthpixels=depthmap.getPixels(); int range=2500; - if (players[i]==NULL) { - cerr<<"more spooky shit....!"; - return; - } + + int dmw=players[i]->getWidth(); for (int i=0;i<players[i]->getWidth();i+=2) { @@ -137,6 +179,7 @@ class syncOniPlayer{ glEnd(); } + } return; @@ -150,6 +193,7 @@ class syncOniPlayer{ players[i]=NULL; } } + drawable=false; } string audio; @@ -157,6 +201,7 @@ class syncOniPlayer{ vector<ofxOpenNI*> players; vector<string> filenames; ofSoundPlayer soundplayer; + bool drawable; }; |
