summaryrefslogtreecommitdiff
path: root/04_playobjects/src/testApp.h
blob: 32e6dadd4bceda77a7d1c17332c7cdf88a29e30a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef _TEST_APP
#define _TEST_APP

#include "ofxOpenNI.h"
#include "ofMain.h"
#include "ofxXmlSettings.h"
#include "ofxMayaCam.h"

#include "ofxOsc.h"

#define OSCPORT 12345

#define MAX_DEVICES 2

struct record{
	vector<string> data;
	string audio;
};

//in order to play different clips it seems necessary to have a player per clip
class syncOniPlayer{
	public:
		~syncOniPlayer(){
			stop();
		}
		void 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 play(){
			for (int i=0;i<players.size();i++) {
				players[i]=new ofxOpenNI();
				//players[i]->setSafeThreading(true);
				players[i]->setupFromONI(filenames[i],false);
				//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();
				};
			}
		}
		void update(){
			for (int i=0;i<players.size();i++) {
				players[i]->update();
			}
		}
		void pause(){
			for (int i=0;i<players.size();i++) {
				//players[players.size()-1]->setSpeed(0.0f);
				players[i]->setPaused(true);
			}
		}
		int getCurrentFrame(){
			if (players.size()) return players[0]->getCurrentFrame();
			else return -1;
		}
		void drawWindows(){
			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 drawCloud(){
			/*
			int num=0;
			for (int i=0;i<players.size();i++) {
				ofPushMatrix();
			    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
			    int numUsers = players[i]->getNumTrackedUsers();
			    for (int nID = 0; nID < numUsers; nID++){
			        ofxOpenNIUser & user = players[i]->getTrackedUser(nID);
			        //user.drawMask();
			        ofPushMatrix();
			        ofTranslate(0,0,-1000);
			        user.drawPointCloud();
			        ofPopMatrix();
			    }
			    num+=numUsers;
			    ofDisableBlendMode();
			    ofPopMatrix();
			}
			return num;
			*/
			//cerr<<"drawing "<<players.size()<<" clouds"<<endl; we are getting to here when unititialised

				int count;
				for (int i=0;i<players.size();i++) {

		            const XnDepthPixel* depthmap=players[i]->getDepthGenerator().GetDepthMap();
		            //uint16_t* depthpixels=depthmap.getPixels();
		            int range=2500;

		            if (players[i]==NULL) {
						cerr<<"more spooky shit....!";
						return;
					}
		            int dmw=players[i]->getWidth();
		            
	                for (int i=0;i<players[i]->getWidth();i+=2) {

	                    glBegin(GL_LINES);

	                    for (int j=0;j<players[i]->getHeight();j+=2) {



	                        ofPoint p= players[i]->projectiveToWorld(ofPoint(i,j,(float)(depthmap[j*dmw+i])));
	                        //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
	                        
	                        if (p.z == 0 || p.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(p.x, p.y, p.z);
	                        //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl;
	                    }

	                    glEnd();
	                }
	            }

            return;
		}
		void stop(){
			soundplayer.stop();
			for (int i=0;i<players.size();i++) {
				if (players[i]!=NULL) {
					players[i]->stop();
					delete players[i];
					players[i]=NULL;
				}
			}
		}
		string audio;
		
	private:
		vector<ofxOpenNI*> players;
		vector<string> filenames;
		ofSoundPlayer soundplayer;
		
};

//however creating losts of ofxOpenNI doesn't seem viable
//we know we want to play seperate clips
//however we know that when we stop and start a player it comes back single threaded

class testApp : public ofBaseApp{

public:
	void setup();
	void update();
	void draw();
    void exit();
    
	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 startPlayers(int which);

    int numDevices;
	ofxOpenNI openNIPlayers[MAX_DEVICES];

	int playing;
    
    ofTrueTypeFont verdana;

    ofxXmlSettings XML;

    vector<syncOniPlayer> players;

    ofxOscReceiver receiver;

    bool drawmovies,drawcloud;
    int offset;

    ofxMayaCam cam;
    
};

#endif