summaryrefslogtreecommitdiff
path: root/03_play
diff options
context:
space:
mode:
Diffstat (limited to '03_play')
-rw-r--r--03_play/src/testApp.cpp112
-rw-r--r--03_play/src/testApp.h27
2 files changed, 121 insertions, 18 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