From d06fe4264b760e4be5880456cfd50f817dbeb1ea Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 11 Nov 2012 11:19:41 +0000 Subject: tracking kinda working --- liveengine/bin/data/settings.xml | 2 +- liveengine/liveengine.layout | 22 ++--- liveengine/src/testApp.cpp | 13 +-- liveengine/src/testApp.h | 2 + liveengine/src/viewport.cpp | 181 ++++++++++++++++++--------------------- liveengine/src/viewport.h | 5 +- 6 files changed, 106 insertions(+), 119 deletions(-) diff --git a/liveengine/bin/data/settings.xml b/liveengine/bin/data/settings.xml index 42e4a52..abe3343 100755 --- a/liveengine/bin/data/settings.xml +++ b/liveengine/bin/data/settings.xml @@ -1,7 +1,7 @@ - + diff --git a/liveengine/liveengine.layout b/liveengine/liveengine.layout index 131871b..77840d6 100755 --- a/liveengine/liveengine.layout +++ b/liveengine/liveengine.layout @@ -1,25 +1,25 @@ - - + + - + - - + + - - + + - - + + - - + + diff --git a/liveengine/src/testApp.cpp b/liveengine/src/testApp.cpp index d5288c1..fb531a5 100755 --- a/liveengine/src/testApp.cpp +++ b/liveengine/src/testApp.cpp @@ -143,7 +143,7 @@ void testApp::setup(){ controllers=new unsigned char[NUM_CONTROLLERS]; memset(controllers,NUM_CONTROLLERS,0); - note=0; + note=1; makeColours(); @@ -208,6 +208,7 @@ void testApp::setup(){ gui.add(transparentBlack.setup("transparent black", false)); gui.add(resetDrawscale.setup("reset draw scale")); gui.add(resetFBscale.setup("reset FB scale")); + gui.add(drawCloud.setup("draw pointCloud",false)); resetDrawscale.addListener(this,&testApp::resetDrawscalePressed); resetFBscale.addListener(this,&testApp::resetFBscalePressed); @@ -278,7 +279,7 @@ void testApp::draw(){ //vp2.draw(lambda,controllers,reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,reversemain?1.0f/scale:scale,reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f); for (int i=0;iisMapped) viewports[i]->mapdraw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/scale:scale,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f); + if (viewports[i]->isMapped) viewports[i]->mapdraw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/scale:scale,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f,drawCloud); else viewports[i]->draw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/scale:scale,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f); } @@ -431,8 +432,8 @@ void testApp::keyPressed(int key){ else if (activeViewkeyPressed(key); - if (key>='1' && key <='6'){ - activeView=min(key-'3',(int)viewports.size()); + if (key>='0' && key <='5'){ + activeView=min(key-'2',(int)viewports.size()); switch (activeView){ case -2: printf("deactivating viewport adjustment\n"); @@ -456,8 +457,8 @@ void testApp::keyPressed(int key){ if(key == 'f'){ toggleFPS(); } - if(key >='7' && key <= '9'){ - mode=key-'7'; + if(key >='6' && key <= '9'){ + mode=key-'6'; } if(key == 267){ xshift--; diff --git a/liveengine/src/testApp.h b/liveengine/src/testApp.h index 2f4b4e1..3df1482 100755 --- a/liveengine/src/testApp.h +++ b/liveengine/src/testApp.h @@ -181,10 +181,12 @@ class testApp : public ofxFensterListener, public ofxMidiListener{ ofxToggle transparentBlack; ofxButton resetDrawscale; ofxButton resetFBscale; + ofxToggle drawCloud; void resetDrawscalePressed(bool & pressed); void resetFBscalePressed(bool & pressed); + //kinect stuff bool useKinect; diff --git a/liveengine/src/viewport.cpp b/liveengine/src/viewport.cpp index 35a4036..5a5a5e2 100755 --- a/liveengine/src/viewport.cpp +++ b/liveengine/src/viewport.cpp @@ -109,7 +109,11 @@ void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,pla ofPushStyle(); if (note>0) { - switch(mode) { + switch(mode) { + case SOLID: + ofSetColor(255,0,0); + ofRect(0,0,ofGetWidth(),ofGetHeight()); + break; case BLOCKS: for (int i=0;i>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); @@ -196,7 +200,7 @@ double viewport::getSetting(const string& setting){ if (setting=="distort") return vars[8].getVal(); return 0.0; } -void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift){ +void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift,bool drawCloud){ ofNode c=ofNode(); ofNode t=ofNode(); @@ -218,7 +222,6 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, rb1.begin(); - camera.begin(); int startx=((w-(w*fscale))/2)+xshift; while (startx>0) startx-=(w*fscale); @@ -237,7 +240,11 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, ofPushStyle(); if (note>0) { - switch(mode) { + switch(mode) { + case SOLID: + ofSetColor(255,0,0); + ofRect(0,0,ofGetWidth(),ofGetHeight()); + break; case BLOCKS: for (int i=0;i>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); @@ -260,8 +267,7 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, break; } } - - camera.end(); + rb1.end(); @@ -276,106 +282,83 @@ void viewport::mapdraw(float a,unsigned char* controllers,int xshift,int yshift, //rb1.draw(0,0); //map onto kinect skeleton - bindTexture(rb1); + bindTexture(rb1); + + camera.begin(); + + if (drawCloud) { + int step = 1; + + for(int y = 0; y < h; y += step) { + for(int x = 0; x < w; x += step) { + ofPoint pos = rUser->getWorldCoordinateAt(x, y, 0); //userID); + if (pos.z == 0 ) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd + ofColor color = rUser->getWorldColorAt(x,y, 0); //userID); + glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); + glVertex3f(pos.x, pos.y, pos.z); + } + } + glEnd(); + glColor3f(1.0f, 1.0f, 1.0f); + } + glPushMatrix(); glScalef(ofGetWidth()/640.0f,ofGetHeight()/480.0f, 1); for (int i=0;igetNumberOfTrackedUsers();i++){ ofxTrackedUser* u=(rUser->getTrackedUser(i+1)); - //if (u->skeletonTracking) { - if (u->neck.found) { - // u->debugDraw(); - //ofxTrackedUser* u= - //printf("%i\n",(int)recordUser.getTrackedUser(i)->id); - //printf("tracking\n"); - - /* - glBegin(GL_QUADS); - glVertex3i(u->hip.position[0].X, u->hip.position[0].Y,u->hip.position[0].Z); - glVertex3i(u->hip.position[1].X, u->hip.position[1].Y,u->hip.position[1].Z); - glVertex3i(u->right_shoulder.position[1].X, u->right_shoulder.position[1].Y,u->right_shoulder.position[1].Z); - glVertex3i(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y, u->left_shoulder.position[1].Z); - glEnd(); - */ - - /* - glBegin(GL_QUADS); - glVertex3i(u->hip.position[0].X, u->hip.position[0].Y,0); - glVertex3i(u->hip.position[1].X, u->hip.position[1].Y,0); - glVertex3i(u->right_shoulder.position[1].X, u->right_shoulder.position[1].Y,0); - glVertex3i(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y,0); - glEnd(); - */ - - float ratio=16.0f/9.0f; - float heightratio=0.8f; - float widthratio=0.8f; - - float ax=((float)(u->hip.position[1].X-u->hip.position[0].X)); //hip width x - float ay=((float)(u->hip.position[1].Y-u->hip.position[0].Y)); //hip width y - - float cx=(float)(u->hip.position[0].X)+(ax*0.5f); //centre of hips - float cy=(float)(u->hip.position[0].Y)+(ay*0.5f); - - float hx=(((float)(u->left_shoulder.position[0].X))-cx); //height of torso - float hy=(((float)(u->left_shoulder.position[0].Y))-cy); - - float p1x=cx+(hx*(1.0f-heightratio)*0.5f); //centre of frame bottom - float p1y=cy+(hy*(1.0f-heightratio)*0.5f); - - float p2x=cx+(hx*(1.0f-((1.0f-heightratio)*0.5f))); //centre of frame top - float p2y=cy+(hy*(1.0f-((1.0f-heightratio)*0.5f))); - - ofVec3f c1=ofVec3f(p2x-(ax*0.5*widthratio), p2y-(ay*0.5*widthratio),0); - ofVec3f c2=ofVec3f(p2x+(ax*0.5*widthratio), p2y+(ay*0.5*widthratio),0); - ofVec3f c3=ofVec3f(p1x-(ax*0.5*widthratio), p1y-(ay*0.5*widthratio),0); - ofVec3f c4=ofVec3f(p1x+(ax*0.5*widthratio), p1y+(ay*0.5*widthratio),0); - - - /* - ofVec3f c1=ofVec3f(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y,0); - ofVec3f c2=ofVec3f(u->right_shoulder.position[1].X, u->right_shoulder.position[1].Y,0); - ofVec3f c3=ofVec3f(u->hip.position[1].X, u->hip.position[1].Y,0); - ofVec3f c4=ofVec3f(u->hip.position[0].X, u->hip.position[0].Y,0); - */ - - - /* - glBegin(GL_QUADS); - glVertex3i(u->hip.position[1].X, u->hip.position[1].Y,0); - glVertex3i(u->hip.position[0].X, u->hip.position[0].Y,0); - glVertex3i(u->left_shoulder.position[1].X, u->left_shoulder.position[1].Y,0); - glVertex3i(u->right_shoulder.position[1].X, u->right_shoulder.position[1].Y,0); - glEnd(); - */ - - - ofMesh targ; - targ.addVertex(c1); - targ.addTexCoord(ofVec2f(0,0)); - targ.addVertex(c2); - targ.addTexCoord(ofVec2f(1,0)); - targ.addVertex(c3); - targ.addTexCoord(ofVec2f(0,1)); - targ.addVertex(c3); - targ.addTexCoord(ofVec2f(0,1)); - targ.addVertex(c2); - targ.addTexCoord(ofVec2f(1,0)); - targ.addVertex(c4); - targ.addTexCoord(ofVec2f(1,1)); - targ.draw(); - - - - //ofLine(u->left_shoulder.position[1].X,u->left_shoulder.position[1].Y,u->left_shoulder.position[1].Z,u->right_shoulder.position[1].X,u->right_shoulder.position[1].Y,u->right_shoulder.position[1].Z); - ofLine(u->right_shoulder.position[1].X,u->right_shoulder.position[1].Y,u->right_shoulder.position[1].Z,u->right_lower_torso.position[1].X,u->right_lower_torso.position[1].Y,u->right_lower_torso.position[1].Z); - ofLine(u->right_lower_torso.position[1].X,u->right_lower_torso.position[1].Y,u->right_lower_torso.position[1].Z,u->left_lower_torso.position[1].X,u->left_lower_torso.position[1].Y,u->left_lower_torso.position[1].Z); - ofLine(u->left_lower_torso.position[1].X,u->left_lower_torso.position[1].Y,u->left_lower_torso.position[1].Z,u->left_shoulder.position[1].X,u->left_shoulder.position[1].Y,u->left_shoulder.position[1].Z); + if (u->neck.found) { + + float ratio=16.0f/9.0f; + float heightratio=0.8f; + float widthratio=0.8f; + + float ax=((float)(u->hip.position[1].X-u->hip.position[0].X)); //hip vector + float ay=((float)(u->hip.position[1].Y-u->hip.position[0].Y)); + float az=((float)(u->hip.position[1].Z-u->hip.position[0].Z)); + + float cx=(float)(u->hip.position[0].X)+(ax*0.5f); //centre of hips + float cy=(float)(u->hip.position[0].Y)+(ay*0.5f); + float cz=(float)(u->hip.position[0].Z)+(az*0.5f); + + float hx=(((float)(u->left_shoulder.position[0].X))-cx); //torso vector + float hy=(((float)(u->left_shoulder.position[0].Y))-cy); + float hz=(((float)(u->left_shoulder.position[0].Z))-cz); + + float p1x=cx+(hx*(1.0f-heightratio)*0.5f); //centre of frame bottom + float p1y=cy+(hy*(1.0f-heightratio)*0.5f); + float p1z=cz+(hz*(1.0f-heightratio)*0.5f); + + float p2x=cx+(hx*(1.0f-((1.0f-heightratio)*0.5f))); //centre of frame top + float p2y=cy+(hy*(1.0f-((1.0f-heightratio)*0.5f))); + float p2z=cz+(hz*(1.0f-((1.0f-heightratio)*0.5f))); + + ofVec3f c1=ofVec3f(p2x-(ax*0.5*widthratio), p2y-(ay*0.5*widthratio), p2z-(az*0.5*widthratio)); + ofVec3f c2=ofVec3f(p2x+(ax*0.5*widthratio), p2y+(ay*0.5*widthratio), p2z+(az*0.5*widthratio)); + ofVec3f c3=ofVec3f(p1x-(ax*0.5*widthratio), p1y-(ay*0.5*widthratio), p1z-(az*0.5*widthratio)); + ofVec3f c4=ofVec3f(p1x+(ax*0.5*widthratio), p1y+(ay*0.5*widthratio), p1z+(az*0.5*widthratio)); + + ofMesh targ; + targ.addVertex(c1); + targ.addTexCoord(ofVec2f(0,0)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c3); + targ.addTexCoord(ofVec2f(0,1)); + targ.addVertex(c2); + targ.addTexCoord(ofVec2f(1,0)); + targ.addVertex(c4); + targ.addTexCoord(ofVec2f(1,1)); + targ.draw(); + + } + } + + camera.end(); - } - } - glPopMatrix(); unbindTexture(rb1); diff --git a/liveengine/src/viewport.h b/liveengine/src/viewport.h index 51c56c8..4c59e2a 100755 --- a/liveengine/src/viewport.h +++ b/liveengine/src/viewport.h @@ -12,7 +12,8 @@ #define NOTHING 0 #define BLOCKS 1 -#define LIST 2 +#define LIST 2 +#define SOLID 3 void bindTexture(ofBaseHasTexture &t); void unbindTexture(ofBaseHasTexture &t); @@ -28,7 +29,7 @@ class viewport viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy); void setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy); void draw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift); - void mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift); + void mapdraw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift,bool drawCloud); void setcam(map&settings); double getSetting(const string& setting); -- cgit v1.2.3