diff options
| author | Tim Redfern <tim@gray.(none)> | 2012-10-28 17:40:19 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@gray.(none)> | 2012-10-28 17:40:19 +0000 |
| commit | 796d647fd38f7cf01cb70bbb0700b75427e42d55 (patch) | |
| tree | 9022fe609a3db0e8f5d92bc179155a6f785707e0 /liveengine/src/viewport.cpp | |
| parent | 1584507071a2aa4cb27801e980dce0e1843069a4 (diff) | |
starting to build kinect addition
Diffstat (limited to 'liveengine/src/viewport.cpp')
| -rwxr-xr-x | liveengine/src/viewport.cpp | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/liveengine/src/viewport.cpp b/liveengine/src/viewport.cpp index ce67b37..82ee5a0 100755 --- a/liveengine/src/viewport.cpp +++ b/liveengine/src/viewport.cpp @@ -1,11 +1,62 @@ #include "viewport.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 bindTex(ofTexture &tex) {
+ 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 unbindTex(ofTexture &tex) {
+ tex.unbind();
+
+ glMatrixMode(GL_TEXTURE);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+}
+//--------------------------------------------------
viewport::viewport()
{
//ctor
}
+viewport::viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ setup(_w,_h,_x,_y,_r,_ox,_oy);
+}
void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
r=_r;
@@ -105,3 +156,186 @@ viewport::~viewport() {
//dtor
}
+
+void viewport::setUG(ofxUserGenerator *_rUser){
+ rUser=_rUser;
+ isMapped=true;
+}
+
+//-------------------------
+mappedviewport::mappedviewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ setup(_w,_h,_x,_y,_r,_ox,_oy);
+}
+void mappedviewport::setUG(ofxUserGenerator *_rUser){
+ rUser=_rUser;
+}
+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){
+ //printf("draw mapped%s\n",ofGetFrameNum());
+ rb1.begin();
+ int startx=((w-(w*fscale))/2)+xshift;
+ while (startx>0) startx-=(w*fscale);
+ int starty=((h-(h*fscale))/2)+yshift;
+ while (starty>0) starty-=(h*fscale);
+
+ for (int i=startx;i<w*2;i+=(w*fscale)) {
+ for (int j=starty;j<h*2;j+=(h*fscale)) {
+ rb2.draw(i,j,w*fscale,h*fscale);
+ }
+ }
+
+ float notewidth=w/NUM_NOTES;
+ float noteheight=h/NUM_CONTROLLERS;
+
+ ofPushStyle();
+
+ if (note>0) {
+ switch(mode) {
+ case BLOCKS:
+ for (int i=0;i<NUM_CONTROLLERS;i++){
+ ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
+ ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
+ }
+ break;
+ case LIST:
+ if (list.lock()) { //if playlist is loaded
+ if (list.layers.find(note)!=list.layers.end()) {
+ ofPushMatrix();
+ ofTranslate(w/2,h/2);
+ ofScale(scale,scale,scale);
+ ofTranslate(-w/2,-h/2);
+ if (controlColours) list.layers[note]->draw(a,controllers,w,h,transparentBlack,colShift);
+ else list.layers[note]->draw(a,w,h,colShift);
+ ofPopMatrix();
+ }
+ list.unlock();
+ }
+ break;
+ }
+ }
+
+ rb1.end();
+
+ rb2.begin();
+ ofSetColor(255,255,255);
+ ofBackground(0,0,0);
+ //rb1.draw(0,0);
+
+ //map on kinect skeleton
+ bindTexture(rb1);
+
+ glPushMatrix();
+ glScalef(ofGetWidth()/640.0f,ofGetHeight()/480.0f, 1);
+ for (int i=0;i<rUser->getNumberOfTrackedUsers();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);
+
+ }
+ }
+ glPopMatrix();
+ unbindTexture(rb1);
+
+
+ rb2.end();
+
+ ofPushMatrix();
+ ofTranslate(x+(w/2),y+(h/2));
+ ofRotate(r);
+ //ofTranslate(-abs(sin(ofDegToRad(r))*h/2)-abs(cos(ofDegToRad(r))*w/2),-abs(sin(ofDegToRad(r))*w/2)-abs(cos(ofDegToRad(r))*h/2));
+ ofTranslate(ox,oy);
+
+ rb2.draw(0,0);
+
+ ofPopStyle();
+
+ ofPopMatrix();
+
+}
|
