summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/keyVar.cpp62
-rwxr-xr-xsrc/keyVar.h38
-rwxr-xr-xsrc/main.cpp20
-rwxr-xr-xsrc/movieCloud.h15
-rwxr-xr-xsrc/testApp.cpp392
-rwxr-xr-xsrc/testApp.h143
-rwxr-xr-xsrc/viewport.cpp227
-rwxr-xr-xsrc/viewport.h50
8 files changed, 947 insertions, 0 deletions
diff --git a/src/keyVar.cpp b/src/keyVar.cpp
new file mode 100755
index 0000000..5d805c9
--- /dev/null
+++ b/src/keyVar.cpp
@@ -0,0 +1,62 @@
+/*
+ * keyvar.cpp
+
+ generalised cushioned keyboard controller
+ //todo time based rather than onoff to get around keyrepeat issue
+ */
+
+#include "keyVar.h"
+
+void keyVar::set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float _accelTime){
+ keyInc=_keyInc;
+ keyDec=_keyDec;
+ val=_val; //initial value
+ speed=_speed;
+ accel=_accel;
+ accelTime=_accelTime;
+ state=0;
+ timePressed=timeCalc=0;
+ inc=0;
+
+}
+void keyVar::keyPressed(char _key){
+ //need to deal with key repeat: OSX anyway
+ if (_key==keyInc&&state!=1) {
+ state=1;
+ timePressed=timeCalc=ofGetElapsedTimef();
+ if (DEBUG) printf("pressed %i:%i\n",_key,ofGetElapsedTimeMillis());
+ }
+ if (_key==keyDec&&state!=-1) {
+ state=-1;
+ timePressed=timeCalc=ofGetElapsedTimef();
+ if (DEBUG) printf("pressed %i:%i\n",_key,ofGetElapsedTimeMillis());
+ }
+}
+void keyVar::keyReleased(char _key){
+ if (_key==keyInc&&state==1) {
+ state=0;
+ if (DEBUG) printf("released %i:%i\n",_key,ofGetElapsedTimeMillis());
+ }
+ if (_key==keyDec&&state==-1) {
+ state=0;
+ if (DEBUG) printf("released %i:%i\n",_key,ofGetElapsedTimeMillis());
+ }
+}
+float keyVar::getVal(){
+ float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime);
+ //if (state)
+ val+=pow(segment,accel)*speed*state; //(ofGetElapsedTimef()-timeCalc)*
+ inc=pow(segment,accel)*speed*state;
+ timeCalc=ofGetElapsedTimef();
+ return val;
+}
+float keyVar::readVal(){
+ return val;
+}
+float keyVar::getInc(){
+ float segment = min(1.0f,(ofGetElapsedTimef()-timePressed)/accelTime);
+ return pow(segment,accel)*speed*state;
+}
+void keyVar::setVal(float _val){
+ val=_val;
+}
diff --git a/src/keyVar.h b/src/keyVar.h
new file mode 100755
index 0000000..3459537
--- /dev/null
+++ b/src/keyVar.h
@@ -0,0 +1,38 @@
+/*
+ * keyvar.h
+ * 3dnav
+ *
+ * Created by Tim Redfern on 15/12/2011.
+ * Copyright 2011 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "ofMain.h"
+
+#define DEBUG false
+
+class keyVar{
+
+ public:
+ void set(char _keyInc,char _keyDec,float _val,float _speed,float _accel,float accelTime);
+ void keyPressed(char _key);
+ void keyReleased(char _key);
+ float getVal();
+ float getInc();
+ void setVal(float _val);
+
+ float readVal();
+ float inc; //for syncing
+
+private:
+ char keyInc,keyDec;
+ long timePressed;
+ long timeCalc;
+ int state; //up-down-off
+ float val;
+ float speed;
+ float accelTime;
+ float accel;
+
+
+};
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100755
index 0000000..f0c0c0f
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,20 @@
+#include "ofMain.h"
+#include "testApp.h"
+#include "ofxFensterManager.h"
+#include "ofAppGlutWindow.h"
+
+//========================================================================
+int main( ){
+
+ ofAppGlutWindow window;
+ ofSetupOpenGL(ofxFensterManager::get(),1024,768, OF_WINDOW); //2048,768
+ //ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
+ //ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ //ofRunApp( new testApp());
+ ofRunFensterApp( new testApp());
+
+}
diff --git a/src/movieCloud.h b/src/movieCloud.h
new file mode 100755
index 0000000..fe6373b
--- /dev/null
+++ b/src/movieCloud.h
@@ -0,0 +1,15 @@
+#ifndef MOVCLOUD_H
+#define MOVCLOUD_H
+
+#include "ofMain.h"
+
+/*
+controls playback of a movie and allows it to display fake or real depth data
+can also make some depth movie recordings
+
+*/
+
+
+
+
+#endif \ No newline at end of file
diff --git a/src/testApp.cpp b/src/testApp.cpp
new file mode 100755
index 0000000..de970da
--- /dev/null
+++ b/src/testApp.cpp
@@ -0,0 +1,392 @@
+#include "testApp.h"
+
+previewWindow::~previewWindow(){
+ cout << "preview window destroyed" << endl;
+}
+void previewWindow::setup(){}
+void previewWindow::setBuffer(ofFbo *buffer){
+ rb=buffer;
+}
+void previewWindow::draw(){
+
+ rb->draw(0,0,ofGetWidth(),ofGetHeight()); //why crash?
+
+ ofSetColor(255,255,255);
+ ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
+
+}
+//--------------------------------------------------------------
+guiWindow::~guiWindow(){
+ cout << "gui window destroyed" << endl;
+}
+void guiWindow::setup(){}
+void guiWindow::setParent(testApp *p){
+ parent=p;
+}
+void guiWindow::draw(){
+
+ parent->gui.draw();
+}
+void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){
+ parent->dragEvent(dragInfo);
+}
+void guiWindow::windowMoved(int x,int y){
+ //printf("window moved!\n");
+}
+
+//----------------------------------------------------------------------
+
+kinectWindow::~kinectWindow(){
+ cout << "kinect window destroyed" << endl;
+}
+void kinectWindow::setup(){
+ ofSetBackgroundAuto(false);
+}
+void kinectWindow::setParent(testApp *p){
+ parent=p;
+}
+void kinectWindow::draw(){
+ parent->kinect.drawDepth(0,0,ofGetWidth(),ofGetHeight());
+}
+void kinectWindow::mousePressed( int x, int y, int button ){
+ ofVec3f w=parent->kinect.getWorldCoordinateAt(x*2, y*2);
+ printf("world coord at %i,%i : %02f,%02f,%02f\n",x*2,y*2,w.x,w.y,w.z);
+}
+
+
+//--------------------------------------------------------------
+void testApp::setup(){
+ int midiPort=0;
+ midiChannel=0;
+ useKinect=true;
+ kinectWin=new kinectWindow();
+ ofxFenster* kw=ofxFensterManager::get()->createFenster(0, 0, 320, 240, OF_WINDOW);
+ kw->setWindowTitle("kinect");
+ kw->addListener(kinectWin);
+ kinectWin->setup();
+ kinectWin->setParent(this);
+
+ // enable depth->video image calibration
+ kinect.setRegistration(true);
+
+ kinect.init(true);
+ //kinect.init(true); // shows infrared instead of RGB video image
+ //kinect.init(false, false); // disable video image (faster fps)
+
+ kinect.open(); // opens first available kinect
+ //kinect.open(1); // open a kinect by id, starting with 0 (sorted by serial # lexicographically))
+ //kinect.open("A00362A08602047A"); // open a kinect using it's unique serial #
+
+
+ if( !XML.loadFile("settings.xml") ){
+ printf("unable to load settings.xml check data/ folder\n");
+ }else{
+ printf("settings loaded!\n");
+ midiPort=ofToInt(XML.getAttribute("liveEngine", "port", "0")); //default to 0/all
+ midiChannel=ofToInt(XML.getAttribute("liveEngine", "channel", "0"));
+ if (midiChannel) printf("listening on port %d, midi channel %d\n",midiPort,midiChannel);
+ else printf("listening on port %d, all midi channels\n",midiPort);
+ if(XML.pushTag("liveEngine")) {
+ int numViews=XML.getNumTags("viewport");
+ if(numViews) {
+ for (int i=0;i<numViews;i++) {
+ int w=XML.getAttribute("viewport", "w",0,i);
+ int h=XML.getAttribute("viewport", "h",0,i);
+ int x=XML.getAttribute("viewport", "x",0,i);
+ int y=XML.getAttribute("viewport", "y",0,i);
+ int rot=XML.getAttribute("viewport", "rot",0,i);
+ int ox=XML.getAttribute("viewport", "ox",0,i);
+ int oy=XML.getAttribute("viewport", "oy",0,i);
+ printf("viewport %i: %ix%i\n",i,w,h);
+ viewports.push_back(new viewport(w,h,x,y,rot,ox,oy));
+ viewports[i]->setKinect(&kinect);
+ XML.pushTag("viewport",i);
+ vector<string>keys;
+ XML.getAttributeNames("settings", keys, 0);
+ map<string,float>settings;
+ for (int k=0;k<keys.size();k++) {
+ settings[keys[k]]=XML.getAttribute("settings",keys[k],0.0f,0);
+ }
+ viewports[i]->setcam(settings);
+ XML.popTag();
+ }
+ }
+ else printf("no viewports!\n");
+
+ XML.popTag();
+
+ }
+
+ }
+
+
+
+ activeView=-1;
+
+ midiIn.listPorts();
+ midiIn.openPort(midiPort);
+ midiIn.addListener(this);
+
+
+ showFPS=false;
+ ofBackground(0,0,0);
+
+ ofSetBackgroundAuto(false);
+
+ ofSetFrameRate(60);
+
+
+ //preview window stuff
+ prevWin=new previewWindow();
+ win=ofxFensterManager::get()->createFenster(0, 0, 512,384, OF_WINDOW);
+ ofAddListener(win->events.mouseDragged, this, &testApp::mousePressedEvent);
+ ofAddListener(win->events.mousePressed, this, &testApp::mousePressedEvent);
+ ofAddListener(win->events.keyPressed, this, &testApp::keyPressedEvent);
+ win->setWindowTitle("preview");
+ win->addListener(prevWin);
+ prevWin->setup();
+ prevWin->setBuffer(&viewports[0]->rb2);
+
+ fullscreenoutput=false;
+
+ guiWin=new guiWindow();
+ gui.setup("","panel.xml",0,0);
+ /*
+ gui.add(reversemain.setup("reverse main", false));
+ gui.add(controlColours.setup("control colours", false));
+ gui.add(noteRandomiseColours.setup("randomise note colours", false));
+ 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));
+ */
+
+ fade=255;
+ gui.add(fadectl.setup("fade level",fade,0,255,255));
+ decimate=255;
+ gui.add(decimatectl.setup("decimate",decimate,0,255,255));
+
+ //resetDrawscale.addListener(this,&testApp::resetDrawscalePressed);
+ //resetFBscale.addListener(this,&testApp::resetFBscalePressed);
+
+ //gui window stuff
+ ofxFenster* win2=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW);
+
+ ofAddListener(win2->events.windowResized, this, &testApp::windowEvent);
+
+ win2->setWindowTitle("config");
+ win2->addListener(guiWin);
+ guiWin->setup();
+ guiWin->setParent(this);
+
+
+}
+
+void testApp::fadeSet(int amt) {
+ printf("fader set to %i\n",amt);
+}
+
+
+//--------------------------------------------------------------
+void testApp::update(){
+
+ kinect.update();
+}
+void testApp::saveSettings(string filename){
+
+ if(XML.pushTag("liveEngine")) {
+ for (int i=0;i<viewports.size();i++){
+ XML.pushTag("viewport",i);
+ vector<string>keys;
+ XML.getAttributeNames("settings", keys, 0);
+ for (int k=0;k<keys.size();k++) {
+ XML.setAttribute("settings", keys[k], viewports[i]->getSetting(keys[k]),0);
+ }
+ XML.popTag();
+ }
+ XML.popTag();
+ }
+ XML.saveFile(filename);
+ printf("saved %s\n",filename.c_str());
+}
+//--------------------------------------------------------------
+void testApp::draw(){
+
+ for (int i=0;i<viewports.size();i++) {
+ viewports[i]->draw(fade,decimate);
+ }
+
+
+
+
+
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed(int key, ofxFenster* win){
+ if(key == ' '){
+ fullscreenoutput=!fullscreenoutput;
+ win->setFullscreen(fullscreenoutput);
+ printf("resolution: %ix%i %s\n",win->getWidth(),win->getHeight(),fullscreenoutput?"fullscreen":"windowed");
+ }
+ else keyPressed(key);
+}
+void testApp::keyPressed(int key){
+
+ if (activeView<0) for (int i=0;i<viewports.size();i++) viewports[i]->keyPressed(key);
+ else if (activeView<viewports.size()) viewports[activeView]->keyPressed(key);
+
+
+ if (key>='0' && key <='5'){
+ activeView=min(key-'2',(int)viewports.size());
+ switch (activeView){
+ case -2:
+ printf("deactivating viewport adjustment\n");
+ break;
+ case -1:
+ printf("adjusting all viewports\n");
+ break;
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ printf("adjusting viewport %i\n",activeView );
+ break;
+ }
+ }
+
+ if(key == 'p'){
+ saveSettings("settings.xml");
+ printf("settings saved!\n");
+ }
+ if(key == 'f'){
+ toggleFPS();
+ }
+
+}
+
+//--------------------------------------------------------------
+void testApp::keyReleased(int key){
+ if (activeView<0) for (int i=0;i<viewports.size();i++) viewports[i]->keyReleased(key);
+ else if (activeView<viewports.size()) viewports[activeView]->keyReleased(key);
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+
+}
+void testApp::mousePressed(int x, int y, int button) {
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
+//--------------------------------------------------------------
+void testApp::gotMessage(ofMessage msg){
+
+}
+
+//--------------------------------------------------------------
+
+void testApp::dragEvent(ofDragInfo dragInfo, ofxFenster* win){
+ dragEvent(dragInfo);
+}
+void testApp::dragEvent(ofDragInfo dragInfo){
+ if (DEBUG) printf("got draginfo: %s\n",dragInfo.files[0].c_str());
+ int sta=dragInfo.files[0].find_last_of("\\/")+1;
+ int len=(dragInfo.files[0].find_last_of(".")+4)-sta;
+ string filename=dragInfo.files[0].substr(sta,len);
+ printf("loading %s\n",filename.c_str());
+
+ //list.load(filename);
+}
+void testApp::windowEvent(ofResizeEventArgs &args){
+ printf("window event\n");
+}
+
+void testApp::mousePressedEvent(ofMouseEventArgs &args) {
+
+ int xs=0;
+ int ys=0;
+ float sc=1.0f;
+ float fs=1.0f;
+
+ switch (args.button) {
+ case 0:
+ xs=args.x-(win->getWidth()/2);
+ ys=args.y-(win->getHeight()/2);
+ break;
+ case 1:
+ sc=pow(pow(args.x-(win->getWidth()/2),2)+pow(args.y-(win->getHeight()/2),2),0.5)/(win->getWidth()*.1);
+ break;
+ case 2:
+ fs=(pow(pow(args.x-(win->getWidth()/2),2)+pow(args.y-(win->getHeight()/2),2),0.5)/(win->getWidth()))+0.5;
+ break;
+ }
+
+
+
+ for (int i=0;i<viewports.size();i++) viewports[i]->mousePressedEvent(xs,ys,sc,fs);
+}
+
+void testApp::keyPressedEvent(ofKeyEventArgs &args) {
+ //printf("window key pressed: %i (%c)\n",args.key,args.key);
+ keyPressed(args.key);
+}
+
+void testApp::toggleFPS(){
+ showFPS=!showFPS;
+}
+
+void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){
+
+ //newMessage(eventArgs.port, eventArgs.channel, eventArgs.byteTwo, eventArgs.timestamp);
+
+//byteOne : message type
+
+ /*
+ int port;
+ int channel;
+ int status;
+ int byteOne;
+ int byteTwo;
+ double timestamp;
+ */
+
+ //printf("%d %d %d %d %d\n",eventArgs.port,eventArgs.channel,eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo);
+
+ bool noteOn; //this old thing!
+
+ if ((midiChannel==0)||(eventArgs.channel==midiChannel)) {
+ switch(eventArgs.status) {
+ case 144: //noteon-off channel 0
+ noteOn=(eventArgs.byteTwo==0?false:true);
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
+ //}
+ if (DEBUG) printf("note: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
+
+ break;
+ case 176: //control change channel 0
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->mix==eventArgs.byteOne) layers[i]->setMixAmt(((float)eventArgs.byteTwo)/127.0f);
+ //}
+ if (DEBUG) printf("cc: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
+
+ }
+ }
+}
+
diff --git a/src/testApp.h b/src/testApp.h
new file mode 100755
index 0000000..f99df9f
--- /dev/null
+++ b/src/testApp.h
@@ -0,0 +1,143 @@
+#pragma once
+
+//#include <GL/glxew.h>
+
+
+#include "ofMain.h"
+#include "ofxXmlSettings.h"
+
+
+#define OF_ADDON_USING_OFXMIDIIN
+
+
+#include "ofxMidi.h"
+#include "ofxFensterManager.h"
+
+#include "ofxGui.h"
+
+
+#include "viewport.h"
+
+#include "ofxKinect.h"
+
+
+
+class previewWindow;
+class guiWindow;
+class kinectWindow;
+
+
+class testApp : public ofxFensterListener, public ofxMidiListener{
+
+ public:
+
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed(int key, ofxFenster* win);
+ void keyPressed(int key);
+ void keyReleased(int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void windowResized(int w, int h);
+ void gotMessage(ofMessage msg);
+ void dragEvent(ofDragInfo dragInfo);
+ void dragEvent(ofDragInfo dragInfo,ofxFenster* win);
+
+ void saveSettings(string filename);
+
+ void mousePressedEvent(ofMouseEventArgs &args);
+ void keyPressedEvent(ofKeyEventArgs &args);
+ void windowEvent(ofResizeEventArgs &args);
+
+ void makeColours();
+
+ void toggleFPS();
+ bool showFPS;
+
+ ofxXmlSettings XML;
+
+
+ bool fullscreenoutput;
+
+ viewport vp1,vp2;
+ vector<viewport*> viewports;
+ int activeView;
+
+ previewWindow *prevWin;
+ guiWindow *guiWin;
+ kinectWindow *kinectWin;
+
+ ofxFenster* win;
+
+ int midiChannel;
+
+ ofxMidiIn midiIn;
+
+ void newMidiMessage(ofxMidiEventArgs& eventArgs);
+
+
+ ofxPanel gui;
+ ofxToggle reversemain;
+ ofxToggle controlColours;
+ ofxToggle noteRandomiseColours;
+ ofxToggle transparentBlack;
+ ofxButton resetDrawscale;
+ ofxButton resetFBscale;
+ ofxToggle drawCloud;
+
+ ofxIntSlider fadectl;
+ ofxParameter<int> fade;
+ ofxIntSlider decimatectl;
+ ofxParameter<int> decimate;
+
+
+ void resetDrawscalePressed(bool & pressed);
+ void resetFBscalePressed(bool & pressed);
+
+ void fadeSet(int amt);
+
+
+ //kinect stuff
+
+ bool useKinect;
+
+ ofxKinect kinect;
+
+};
+
+class kinectWindow: public ofxFensterListener{
+public:
+ ~kinectWindow();
+ testApp *parent;
+ void setup();
+ void setParent(testApp *p);
+ void draw();
+ void mousePressed( int x, int y, int button );
+};
+
+
+class previewWindow: public ofxFensterListener{
+public:
+ ~previewWindow();
+ ofFbo *rb;
+ void setup();
+ void setBuffer(ofFbo *buffer);
+ void draw();
+};
+
+class guiWindow: public ofxFensterListener{
+public:
+ ~guiWindow();
+ testApp *parent;
+ void setup();
+ void setParent(testApp *p);
+ void draw();
+ void dragEvent(ofDragInfo dragInfo,ofxFenster* win);
+ void windowMoved(int x, int y);
+};
+
+
diff --git a/src/viewport.cpp b/src/viewport.cpp
new file mode 100755
index 0000000..513b954
--- /dev/null
+++ b/src/viewport.cpp
@@ -0,0 +1,227 @@
+#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;
+}
+
+void viewport::draw(int fade,int decimate){
+ /*
+ 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();
+
+ //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;i<w*2;i+=(w*fscale)) {
+ for (int j=starty;j<h*2;j+=(h*fscale)) {
+ rb2.draw(i,j,w*fscale,h*fscale);
+ }
+ }
+
+ if (fade>254) ofClear(0,0,0);
+ else if (fade>0) {
+ ofEnableAlphaBlending();
+ ofSetColor(0,0,0,fade);
+ ofRect(0,0,w,h);
+ ofDisableAlphaBlending();
+ }
+
+
+ camera.begin();
+
+
+ glBegin(GL_POINTS);
+
+ float step = 255.0f/(float)decimate;
+
+ float scale=w/640.0f;
+
+ 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();
+
+ 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);
+ ofPopMatrix();
+
+}
+
+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<string,float>&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<string,keyVar>::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<string,keyVar>::iterator iter;
+ for (iter=vars.begin();iter!=vars.end();++iter) iter->second.keyReleased(key);
+};
+
+
diff --git a/src/viewport.h b/src/viewport.h
new file mode 100755
index 0000000..1ffda0a
--- /dev/null
+++ b/src/viewport.h
@@ -0,0 +1,50 @@
+#ifndef VIEWPORT_H
+#define VIEWPORT_H
+
+
+#include "ofxKinect.h"
+#include "ofMain.h"
+#include "keyVar.h"
+
+
+class viewport
+{
+ public:
+ 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);
+ virtual ~viewport();
+ void setKinect(ofxKinect *k);
+ void setFade(int f);
+
+ void setcam(map<string,float>&settings);
+ double getSetting(const string& setting);
+
+ void mousePressedEvent(int xs,int ys,float sc,float fs);
+
+ void draw(int fade,int decimate);
+ 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);
+
+ protected:
+ int x, y,w,h,ox,oy,r;
+ int xshift, yshift;
+ float scale,fscale;
+
+ 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<string,keyVar> vars; //change to midimappedkeyvars
+
+ //has its own own camera
+ ofCamera camera;
+ ofNode target;
+
+
+};
+
+
+#endif // VIEWPORT_H