summaryrefslogtreecommitdiff
path: root/06_performance/src/oni.h
blob: b0b9303f544f6978b4d5442bec7d7074da233287 (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
#include "ofMain.h"
#include "ofxXmlSettings.h"
#include "ofxOpenNI.h"

//1. fix gravity
//2. make sure figure never gets lost - pull back a bit
//3. a way to trigger the figure w/no sound

//a colour video particle
class fpoint{
	public:
		fpoint(){active=false;};
		fpoint(float _x,float _y, float _z, unsigned char _r,unsigned char _g,unsigned char _b){
			setup(x,y,z,r,g,b);
		}
		void setup(float _x,float _y, float _z, unsigned char _r,unsigned char _g,unsigned char _b){
			x=_x;y=_y;z=_z;r=_r;g=_g;b=_b;st=ofGetElapsedTimef();active=true;
		}
		float x,y,z;
		float st;
		unsigned char r,g,b;
		bool active;
		bool draw(float life,float dx,float dy,float dz,float size=5.0f,float interval=0.05f){
			if (!active) {
				return true;
			}
			float l=ofGetElapsedTimef()-st;
			if (life>l) {
				glPointSize((1.0f-(l/life))*size);
				glBegin(GL_POINTS);
				glColor3ub(r,g,b);
				//glColor4ub(r,g,b,(unsigned char)255); // ((l/life)*255.0f));
	            glVertex3f(x-(pow(l,2)*dx),y-(pow(l,2)*dy),z-(pow(l,2)*dz));
	            glEnd();
	            return true;
	        }
	        else {
	        	active=false;
	        	return false;
	        }
		}
		bool drawdx(float life,float dx,float dy,float dz,float size,float interval){
			if (!active) {
				return true;
			}
			float l=ofGetElapsedTimef()-st;
			if (life>l) {
				x-=(pow(interval,2)*dx);
				y-=(pow(interval,2)*dy);
				z-=(pow(interval,2)*dz);
				glPointSize((1.0f-(l/life))*size);
				glBegin(GL_POINTS);
				glColor3ub(r,g,b);
				//glColor4ub(r,g,b,(unsigned char)255); // ((l/life)*255.0f));
	            glVertex3f(x,y,z);
	            glEnd();
	            return true;
	        }
	        else {
	        	active=false;
	        	return false;
	        }
		}
};
class syncOniPlayer{
	public:
		syncOniPlayer() {
			drawable=false;
			gamma=3.0f;
			LUT=NULL;
			makeLUT();
			playerActive=false;
//<<<<<<< HEAD
			points.reserve(100000); //operator new seems to be causing crshes?
//=======
//>>>>>>> fd8dc2aa23c4bbc297e835e4f920aaf5342aba5e
		}
		~syncOniPlayer(){
			stop();
			//if (LUT) delete[] LUT;
		}
		void makeLUT(){
			if (NULL==LUT){
				LUT=new uint8_t[0xff];
			}
			for (int i=0;i<0xFF;i++) {
				LUT[i]=(uint8_t)(pow(((float)i)/255.0f,gamma)*255.0f);
			}
		}
		void addPlayer(string name);
		void play();
		void update();
		void pause();
		bool isPlaying();
		int getCurrentFrame();
		float getPosition();
		int getNumParticles();
		string getCurrentFile();
		void drawWindows();
		void drawCloud(int step);
		void drawPoints(float birth,float life,float dx,float dy, float dz,float size);
		void stop();
		string audio;
		
	private:
		vector<ofxOpenNI*> players;
		vector<string> filenames;
		ofSoundPlayer soundplayer;
		bool drawable;
		vector<fpoint> points;
		set<int> pointPool;
		float gamma;
		uint8_t *LUT;
		float startTime;
		bool playerActive;
		float lastTime;
};
//========================================
class oniManager{
	public:
		void init(const char* filename);
		void startPlayer(int num);
		int getNumClips();
		int getNumParticles();
		syncOniPlayer* getCurrentPlayer();
//<<<<<<< HEAD
		string getCurrentFile();
//=======
//>>>>>>> fd8dc2aa23c4bbc297e835e4f920aaf5342aba5e
		void update();
		void drawWindows();
		void drawCloud(int step);
		void drawPoints(float size,float birth,float life,float dx,float dy, float dz);
		void previous();
		void next();
		int playing;
		ofxXmlSettings XML;
    	vector<syncOniPlayer> players;
};