summaryrefslogtreecommitdiff
path: root/06_performance/src/oni.cpp
diff options
context:
space:
mode:
authorTim <tim@Admins-Mac-Pro-2.local>2013-06-20 10:04:58 +0100
committerTim <tim@Admins-Mac-Pro-2.local>2013-06-20 10:04:58 +0100
commitd836325685bfcb269a46881fc0cb67628f15bc11 (patch)
treea4864321a8806322eedb7a02a5c403be3bef970f /06_performance/src/oni.cpp
parent51d327513ba268d245527ff59bd208ed907ffe6e (diff)
parent39bcb5346b1f746399192391b6699e81d0d8ad3a (diff)
Merge branch 'master' of eclectronics.org@eclectronics.org:TRSS
Conflicts: 04_playobjects/src/testApp.h
Diffstat (limited to '06_performance/src/oni.cpp')
-rw-r--r--06_performance/src/oni.cpp159
1 files changed, 158 insertions, 1 deletions
diff --git a/06_performance/src/oni.cpp b/06_performance/src/oni.cpp
index a202f41..550d56e 100644
--- a/06_performance/src/oni.cpp
+++ b/06_performance/src/oni.cpp
@@ -1 +1,158 @@
-#include "oni.h" \ No newline at end of file
+#include "oni.h"
+
+void syncOniPlayer::addPlayer(string name){
+ //ofxOpenNI *o=new ofxOpenNI;
+ //o->setupFromONI(name,true);
+ //o->setPaused(true);
+ //players.push_back(o);
+ players.push_back(NULL);
+ filenames.push_back(name);
+ soundplayer.setLoop(false);
+ //players[players.size()-1]->setSpeed(0.0f);
+ //players[players.size()-1]->setup(true);
+ //players[players.size()-1]->start();
+ //players[players.size()-1]->startPlayer(name);
+}
+void syncOniPlayer::play(){
+ for (int i=0;i<players.size();i++) {
+ players[i]=new ofxOpenNI();
+ //players[i]->setSafeThreading(true);
+ players[i]->setupFromONI(filenames[i],true);
+ //players[i]->addDepthGenerator();
+ //players[i]->addImageGenerator();
+ //players[i]->setRegister(true);
+ players[i]->setLooped(false);
+ //players[i]->setBaseUserClass(user);
+ players[i]->start();
+ //players[players.size()-1]->setSpeed(1.0f);
+ if (audio!="") {
+ soundplayer.loadSound(audio);
+ soundplayer.play();
+ };
+ //sleep(2);
+ drawable=true;
+ }
+}
+void syncOniPlayer::update(){
+ for (int i=0;i<players.size();i++) {
+ players[i]->update();
+ }
+}
+void syncOniPlayer::pause(){
+ for (int i=0;i<players.size();i++) {
+ //players[players.size()-1]->setSpeed(0.0f);
+ players[i]->setPaused(true);
+ }
+}
+int syncOniPlayer::getCurrentFrame(){
+ if (players.size()) return players[0]->getCurrentFrame();
+ else return -1;
+}
+void syncOniPlayer::drawWindows(){
+ if (!drawable) return;
+ for (int i=0;i<players.size();i++) {
+ if (players[i]==NULL) break;
+ ofTranslate(0, i * 400);
+ players[i]->drawDepth(50, 0,520,390);
+ players[i]->drawImage(600, 0,520,390);
+
+
+ }
+}
+void syncOniPlayer::drawCloud(int step){
+ int count;
+ for (int n=0;n<players.size();n++) {
+
+
+ const XnDepthPixel* depthmap=players[n]->getDepthGenerator().GetDepthMap();
+ //uint16_t* depthpixels=depthmap.getPixels();
+ int range=1700;
+
+ int depthW=players[n]->getWidth();
+ int depthH=players[n]->getHeight();
+
+ for (int i=0;i<depthW;i+=step) {
+
+ glBegin(GL_LINES);
+
+ for (int j=0;j<depthH;j+=step) {
+
+
+ ofPoint p= players[n]->projectiveToWorld(ofPoint(i,j,(float)(depthmap[j*depthW+i])));
+ //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
+
+ if (p.z == 0 || p.z>range) continue; // gets rid of background
+
+
+ glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255);
+ glVertex3f(p.x, p.y, p.z);
+ //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl;
+ }
+
+ glEnd();
+ }
+
+ }
+
+ return;
+}
+void syncOniPlayer::stop(){
+ soundplayer.stop();
+ for (int i=0;i<players.size();i++) {
+ if (players[i]!=NULL) {
+ players[i]->stop();
+ delete players[i];
+ players[i]=NULL;
+ }
+ }
+ drawable=false;
+}
+//=================
+void oniManager::init(const char* filename){
+ playing=-1;
+ int numDevices=1;
+ string f=string(filename);
+ if( !XML.loadFile(f) ){
+ printf("unable to load recordings, check data/ folder\n");
+ }else{
+ if(XML.pushTag("TRSS")) {
+ int num=XML.getNumTags("rec");
+ if(num) {
+ for (int i=0;i<num;i++) {
+ players.push_back(syncOniPlayer());
+ players[i].addPlayer(XML.getAttribute("rec","left","",i));
+ if (numDevices==2) {
+ players[i].addPlayer(XML.getAttribute("rec","right","",i));
+ }
+ players[i].audio=XML.getAttribute("rec","audio","",i);
+ }
+ }
+ else printf("no recordings found!\n");
+ }
+ }
+}
+void oniManager::startPlayer(int newplayer){
+ if (players.size()>newplayer){
+ if (playing>-1) players[playing].stop();
+ usleep(100000);
+ playing=newplayer;
+ players[playing].play();
+ }
+}
+void oniManager::update(){
+ if (players.size()>playing&&playing>-1) players[playing].update();
+}
+void oniManager::drawWindows(){
+ if (players.size()>playing&&playing>-1) players[playing].drawWindows();
+}
+void oniManager::drawCloud(int step){
+ if (players.size()>playing&&playing>-1) players[playing].drawCloud(step);
+}
+void oniManager::previous(){
+ int newp=(playing+1)%players.size();
+ startPlayer(newp);
+}
+void oniManager::next(){
+ int newp=playing-1<0?players.size()-1:playing-1;
+ startPlayer(newp);
+} \ No newline at end of file