#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; w=_w; h=_h; x=_x; y=_y; ox=_ox; oy=_oy; rb1.allocate(w,h,GL_RGB); rb2.allocate(w,h,GL_RGB); rb3.allocate(w,h,GL_RGB); printf("%ix%i, vp offset: %f,%f\n",w,h,-(sin(ofDegToRad(r))*h/2)-(cos(ofDegToRad(r))*w/2),-(sin(ofDegToRad(r))*w/2)-(cos(ofDegToRad(r))*h/2)); } void viewport::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){ // test screen shape /* ofSetColor(255,0,0); ofRect(0,0,w/2,h/2); ofRect(w/2,h/2,w/2,h/2); ofSetColor(0,255,0); ofRect(0,h/2,w/2,h/2); ofRect(w/2,0,w/2,h/2); */ rb1.begin(); //can be done with texture offset? 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;i0) { switch(mode) { case BLOCKS: for (int i=0;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); rb1.draw(0,0); 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(); } 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;i0) { switch(mode) { case BLOCKS: for (int i=0;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); rb1.draw(0,0); rb2.end(); rb3.begin(); ofSetColor(255,255,255); ofBackground(0,0,0); //rb1.draw(0,0); //map onto kinect skeleton bindTexture(rb1); 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); } } glPopMatrix(); unbindTexture(rb1); rb3.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); rb3.draw(0,0); ofPopStyle(); ofPopMatrix(); }