#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); 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)); xshift =0; yshift=0; scale=1.0; fscale=1.0; xrot=yrot=zrot=0.0f; logo.loadImage("logo.png"); } void viewport::draw(int mode,int fade,float decimate, float feat, float xr, float yr, float zr, int range, bool add, bool dologo, bool col){ /*ool ad ofNode c=ofNode(); ofNode t=ofNode(); t.setParent(c); t.setPosition(); //make target controls relative to rotation c.rotate(vars["lng"].getVal(), ofVec3f(0, 1, 0)); target.setPosition(vars["targX"].getVal(),vars["targY"].getVal(),vars["targZ"].getVal()); //camera.orbit(vars[5].getVal(), vars[4].getVal(), vars[7].getVal(), target); camera.setFov(vars["fov"].getVal()); ofVec3f p(0, 0, vars["dolly"].getVal()); //p.rotate(ofClamp(vars[2].getVal(), -89, 89), ofVec3f(1, 0, 0)); p.rotate(vars["lat"].getVal(), ofVec3f(1, 0, 0)); p.rotate(vars["lng"].getVal(), ofVec3f(0, 1, 0)); p += target.getPosition(); camera.setPosition(p); camera.lookAt(target,ofVec3f(0,1,0).rotate(vars["roll"].getVal(),ofVec3f(0,0,1)).rotate(vars["lng"].readVal(),ofVec3f(0,1,0))); */ rb1.begin(); glDisable(GL_BLEND); //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;i254) ofClear(0,0,0); else if (fade>0) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ofSetColor(0,0,0,fade); ofRect(0,0,w,h); glDisable(GL_BLEND); } camera.begin(); ofPushMatrix(); ofTranslate(0,0,-1500); xrot+=xr; yrot+=yr; zrot+=zr; ofRotateZ(zrot); ofRotateX(xrot); ofRotateY(yrot); float minstep=1.0f/160.0f; float step = decimate>minstep?1.0f/decimate:160.0f; float scale=w/640.0f; glEnable(GL_BLEND); if (add) glBlendFunc(GL_ONE,GL_ONE); else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (mode==POINTS) { glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glPointSize(feat); glBegin(GL_POINTS); for(float y = 0.0f; y < 480.0f; y += step) { for(float x = 0.0f; x < 640.0f; x += step) { ofVec3f pos = kinect->getWorldCoordinateAt(x, y); if (pos.z == 0 || pos.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(pos.x*scale, pos.y*scale, pos.z*scale); } } glEnd(); glDisable(GL_PROGRAM_POINT_SIZE); } if (mode==LINES) { glEnable(GL_LINE_SMOOTH); glLineWidth(feat); for(float y = 0.0f; y < 480.0f; y += step) { glBegin(GL_LINE_STRIP); for(float x = 0.0f; x < 640.0f; x += 1.0f+(step*0.1)) { ofVec3f pos = kinect->getWorldCoordinateAt(x, y); if (pos.z == 0 || pos.z>range) { glEnd(); glBegin(GL_LINE_STRIP); 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(pos.x*scale, pos.y*scale, pos.z*scale); } glEnd(); } } ofPopMatrix(); camera.end(); glColor3f(1.0f, 1.0f, 1.0f); 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); if (dologo) { ofEnableAlphaBlending(); logo.draw(0,0,ofGetWidth(),ofGetHeight()); ofDisableAlphaBlending(); } ofPopMatrix(); glDisable(GL_BLEND); } viewport::~viewport() { //dtor } void viewport::setKinect(ofxKinect *k){ kinect=k; } void viewport::mousePressedEvent(int xs,int ys,float sc,float fs) { xshift=xs; yshift=ys; scale=sc; fscale=fs; } void viewport::setcam(map&settings){ vars["fov"].set('w','s',settings["fov"],0.2,1.0,1.0); vars["targX"].set('g','d',settings["targX"],100,1.0,1.0); vars["targY"].set('r','v',settings["targY"],100,1.0,1.0); vars["targZ"].set('t','c',settings["targZ"],100,1.0,1.0); vars["lat"].set('u','n',settings["lat"],1,1.0,1.0); vars["lng"].set('j','h',settings["lng"],1,1.0,1.0); vars["roll"].set(',','m',settings["roll"],1,1.0,1.0); vars["dolly"].set('o','l',settings["dolly"],10,1.0,1.0); } double viewport::getSetting(const string& setting){ return vars[setting].getVal(); } void viewport::keyPressed(int key){ map::iterator iter; for (iter=vars.begin();iter!=vars.end();++iter) iter->second.keyPressed(key); if(key == 267){ xshift--; } if(key == 268){ xshift++; } if(key == 269){ yshift--; } if(key == 270){ yshift++; } if (key=='.') { fscale*=0.99f; } if (key=='/') { fscale*=1.01f; } }; void viewport::keyReleased(int key){ map::iterator iter; for (iter=vars.begin();iter!=vars.end();++iter) iter->second.keyReleased(key); };