From ef5d82a13d1154ccdf4de91d869178dab6b76b7f Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 23 Nov 2012 16:24:03 +0000 Subject: ready for gig --- src/main.cpp | 2 +- src/testApp.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++---------- src/testApp.h | 52 ++++++++++++++++++++++++++---- src/viewport.cpp | 85 ++++++++++++++++++++++++++++++++++++++++--------- src/viewport.h | 19 ++++++++--- 5 files changed, 211 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index f0c0c0f..a815136 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(ofxFensterManager::get(),1024,768, OF_WINDOW); //2048,768 + ofSetupOpenGL(ofxFensterManager::get(),1280,768, OF_WINDOW); //2048,768 //ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context //ofSetupOpenGL(&window, 1024,768, OF_WINDOW); diff --git a/src/testApp.cpp b/src/testApp.cpp index de970da..c12ef7e 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -27,6 +27,7 @@ void guiWindow::draw(){ parent->gui.draw(); } + void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ parent->dragEvent(dragInfo); } @@ -67,9 +68,9 @@ void testApp::setup(){ kinectWin->setParent(this); // enable depth->video image calibration - kinect.setRegistration(true); + kinect.setRegistration(); //true); - kinect.init(true); + kinect.init(); //kinect.init(true); // shows infrared instead of RGB video image //kinect.init(false, false); // disable video image (faster fps) @@ -161,10 +162,37 @@ void testApp::setup(){ gui.add(drawCloud.setup("draw pointCloud",false)); */ + gui.add(logo.setup("logo",false)); + fade=255; gui.add(fadectl.setup("fade level",fade,0,255,255)); - decimate=255; - gui.add(decimatectl.setup("decimate",decimate,0,255,255)); + decimate=1.0f; + gui.add(decimatectl.setup("decimate",decimate,0,1.0f,255)); + + featuresize=1.0f; + gui.add(featurectl.setup("featuresize",featuresize,0,16.0f,255)); + + gui.add(pointsMode.setup("points",true)); + gui.add(linesMode.setup("lines",false)); + gui.add(polysMode.setup("lines",false)); + drawMode=POINTS; + + pointsMode.addListener(this,&testApp::pointsModeSet); + linesMode.addListener(this,&testApp::linesModeSet); + polysMode.addListener(this,&testApp::polysModeSet); + + range=5000; + gui.add(rangectl.setup("max range",range,0,5000,255)); + xrot=0.0f; + gui.add(xrotctl.setup("x rotate",xrot,-1.0f,1.0f,255)); + yrot=0.0f; + gui.add(yrotctl.setup("y rotate",yrot,-1.0f,1.0f,255)); + zrot=0.0f; + gui.add(zrotctl.setup("z rotate",zrot,-1.0f,1.0f,255)); + + gui.add(resetDrawscale.setup("points")); + gui.add(resetFBscale.setup("points")); + gui.add(resetSlide.setup("points")); //resetDrawscale.addListener(this,&testApp::resetDrawscalePressed); //resetFBscale.addListener(this,&testApp::resetFBscalePressed); @@ -179,13 +207,31 @@ void testApp::setup(){ guiWin->setup(); guiWin->setParent(this); - +int values[2]; +glGetIntegerv(GL_POINT_SIZE_RANGE, values); +for (int i=0; i<3; i++){ +printf("GLPOINTSIZE = %d\n", values[i]); +} } -void testApp::fadeSet(int amt) { - printf("fader set to %i\n",amt); +void testApp::pointsModeSet(bool & set){ + drawMode=POINTS; + //pointsMode=true; //segfaults!? + //linesMode=false; + //polysMode=false; +} +void testApp::linesModeSet(bool & set){ + drawMode=LINES; + //pointsMode=true; + //linesMode=true; + //polysMode=false; +} +void testApp::polysModeSet(bool & set){ + drawMode=POLYS; + //pointsMode=false; + //linesMode=false; + //polysMode=true; } - //-------------------------------------------------------------- void testApp::update(){ @@ -213,13 +259,9 @@ void testApp::saveSettings(string filename){ void testApp::draw(){ for (int i=0;idraw(fade,decimate); + viewports[i]->draw(drawMode,fade,decimate,featuresize,xrot,yrot,zrot,range,logo); } - - - - } //-------------------------------------------------------------- @@ -233,8 +275,8 @@ void testApp::keyPressed(int key, ofxFenster* win){ } void testApp::keyPressed(int key){ - if (activeView<0) for (int i=0;ikeyPressed(key); - else if (activeViewkeyPressed(key); + //if (activeView<0) for (int i=0;ikeyPressed(key); + //else if (activeViewkeyPressed(key); if (key>='0' && key <='5'){ @@ -263,12 +305,32 @@ void testApp::keyPressed(int key){ toggleFPS(); } + if(key == 'z'){ + if (activeView<0) for (int i=0;icamera.enableAllInput(); + else if (activeViewcamera.enableAllInput(); + } + if(key == 'x'){ + if (activeView<0) for (int i=0;icamera.disableAllInput(); + else if (activeViewcamera.disableAllInput(); + } + if(key == 'q'){ + if (activeView<0) for (int i=0;ixrot=0; + else if (activeViewxrot=0; + } + if(key == 'w'){ + if (activeView<0) for (int i=0;iyrot=0; + else if (activeViewyrot=0; + } + if(key == 'e'){ + if (activeView<0) for (int i=0;izrot=0; + else if (activeViewzrot=0; + } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ - if (activeView<0) for (int i=0;ikeyReleased(key); - else if (activeViewkeyReleased(key); + //if (activeView<0) for (int i=0;ikeyReleased(key); + //else if (activeViewkeyReleased(key); } //-------------------------------------------------------------- diff --git a/src/testApp.h b/src/testApp.h index f99df9f..78ed5eb 100755 --- a/src/testApp.h +++ b/src/testApp.h @@ -13,13 +13,13 @@ #include "ofxMidi.h" #include "ofxFensterManager.h" + + #include "ofxGui.h" #include "viewport.h" -#include "ofxKinect.h" - class previewWindow; @@ -27,6 +27,8 @@ class guiWindow; class kinectWindow; + + class testApp : public ofxFensterListener, public ofxMidiListener{ public: @@ -81,6 +83,7 @@ class testApp : public ofxFensterListener, public ofxMidiListener{ ofxPanel gui; + /* ofxToggle reversemain; ofxToggle controlColours; ofxToggle noteRandomiseColours; @@ -88,17 +91,45 @@ class testApp : public ofxFensterListener, public ofxMidiListener{ ofxButton resetDrawscale; ofxButton resetFBscale; ofxToggle drawCloud; + */ ofxIntSlider fadectl; ofxParameter fade; - ofxIntSlider decimatectl; - ofxParameter decimate; - + ofxFloatSlider decimatectl; + ofxParameter decimate; + ofxFloatSlider featurectl; + ofxParameter featuresize; + + //a radio button. sigh. + int drawMode; + ofxToggle pointsMode; + ofxToggle linesMode; + ofxToggle polysMode; + void pointsModeSet(bool & set); + void linesModeSet(bool & set); + void polysModeSet(bool & set); + + ofxToggle logo; + //void logoSet(bool & set); + + ofxFloatSlider rangectl; + ofxParameter range; + + ofxFloatSlider xrotctl; + ofxParameter xrot; + ofxFloatSlider yrotctl; + ofxParameter yrot; + ofxFloatSlider zrotctl; + ofxParameter zrot; + + ofxButton resetDrawscale; + ofxButton resetFBscale; + ofxButton resetSlide; void resetDrawscalePressed(bool & pressed); void resetFBscalePressed(bool & pressed); + void resetSlidePressed(bool & pressed); - void fadeSet(int amt); //kinect stuff @@ -136,6 +167,15 @@ public: void setup(); void setParent(testApp *p); void draw(); + void mouseMoved(int x, int y, ofxFenster* f) {}; + void mouseMoved(int x, int y) {}; + void mouseDragged(int x, int y, int button, ofxFenster* f) {}; + void mouseDragged(int x, int y, int button) {}; + void mousePressed(int x, int y, int btn, ofxFenster* f) {}; + void mousePressed(int x, int y, int btn) {}; + void mouseReleased(int x, int y, int btn, ofxFenster* f) {}; + void mouseReleased(int x, int y, int btn) {}; + void mouseReleased() {}; void dragEvent(ofDragInfo dragInfo,ofxFenster* win); void windowMoved(int x, int y); }; diff --git a/src/viewport.cpp b/src/viewport.cpp index 513b954..4f65a6d 100755 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -74,9 +74,13 @@ void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) { yshift=0; scale=1.0; fscale=1.0; + xrot=yrot=zrot=0.0f; + + logo.loadImage("logo.png"); } -void viewport::draw(int fade,int decimate){ +void viewport::draw(int mode,int fade,float decimate, float feat, float xr, float yr, float zr, int range, bool dologo){ + /* ofNode c=ofNode(); ofNode t=ofNode(); @@ -84,7 +88,7 @@ void viewport::draw(int fade,int decimate){ 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()); @@ -95,6 +99,7 @@ void viewport::draw(int fade,int decimate){ 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(); @@ -122,25 +127,69 @@ void viewport::draw(int fade,int decimate){ camera.begin(); + ofPushMatrix(); - glBegin(GL_POINTS); - - float step = 255.0f/(float)decimate; + ofTranslate(0,0,-1500); + xrot+=xr; + yrot+=yr; + zrot+=zr; + ofRotateY(yrot); + ofRotateX(xrot); + ofRotateZ(zrot); + float minstep=1.0f/160.0f; + float step = decimate>minstep?1.0f/decimate:160.0f; + float scale=w/640.0f; + + glEnable(GL_BLEND); + 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); + glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); + glVertex3f(pos.x*scale, pos.y*scale, pos.z*scale); + } + } - 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 ) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd - ofColor color = kinect->getColorAt(x,y); //userID); - glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); - 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); + glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a); + glVertex3f(pos.x*scale, pos.y*scale, pos.z*scale); + } + glEnd(); + } } - - glEnd(); + ofPopMatrix(); camera.end(); glColor3f(1.0f, 1.0f, 1.0f); @@ -158,6 +207,12 @@ void viewport::draw(int fade,int decimate){ ofTranslate(ox,oy); rb2.draw(0,0); + + if (dologo) { + ofEnableAlphaBlending(); + logo.draw(0,0,ofGetWidth(),ofGetHeight()); + ofDisableAlphaBlending(); + } ofPopMatrix(); } diff --git a/src/viewport.h b/src/viewport.h index 1ffda0a..f635e51 100755 --- a/src/viewport.h +++ b/src/viewport.h @@ -6,6 +6,12 @@ #include "ofMain.h" #include "keyVar.h" +#define POINTS 1 +#define LINES 2 +#define POLYS 3 + +#include "ofxMayaCam.h" + class viewport { @@ -22,26 +28,31 @@ class viewport void mousePressedEvent(int xs,int ys,float sc,float fs); - void draw(int fade,int decimate); + void draw(int mode,int fade,float decimate, float feat, float xr, float yr, float zr, int range, bool dologo); void drawgui(); ofFbo rb1,rb2; //can do 2d buffer effects with feedback, can pass out rb2 for preview void keyPressed(int key); void keyReleased(int key); + ofxMayaCam camera; + float xrot,yrot,zrot; + protected: int x, y,w,h,ox,oy,r; int xshift, yshift; float scale,fscale; + + ofImage logo; + ofxKinect *kinect; //passes in kinect data //passes in a playing move that can be used to generate 3D points in teh same way private: map vars; //change to midimappedkeyvars - //has its own own camera - ofCamera camera; - ofNode target; + + }; -- cgit v1.2.3