-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideowall.pde
195 lines (173 loc) · 4.51 KB
/
videowall.pde
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
// Kinect photo booth + boxing game
import org.openkinect.*;
import org.openkinect.processing.*;
import interfascia.*;
import unlekker.util.*;
import unlekker.geom.*;
import unlekker.data.*;
// UI
GUIController c;
//IFTextField email;
IFLabel question;
IFLabel response;
boolean do_update = true;
// Kinect Library object
Kinect kinect;
Kinectutils ku;
// calibration
char controlled_parm = ' ';
float delta = 0.1;
boolean translation_on = false;
// interface functions
UXComms ux = new UXComms();
void setup() {
size(800,600,P3D);
frameRate(15);
colorMode(HSB,100);
// Kinect setup:
kinect = new Kinect(this);
kinect.start();
kinect.enableDepth(true);
// kinect.enableRGB(true);
// We don't need the grayscale image in this example
// so this makes it more efficient
kinect.processDepthImage(false);
ku = new Kinectutils(kinect);
ku.loadSettings(); // always load settings from disk
// GUI features
c = new GUIController(this);
// email = new IFTextField("Email Field", 25, 50, 150);
question = new IFLabel("", 25, 20);
response = new IFLabel("", 25, 80);
// c.add(email);
c.add(question);
c.add(response);
//email.addActionListener(this);
// ui color
IFLookAndFeel white = new IFLookAndFeel(this, IFLookAndFeel.DEFAULT);
white.textColor = color(100,0,100);
question.setLookAndFeel(white);
response.setLookAndFeel(white);
}
void draw() {
if (do_update) {
pushMatrix();
background(100,0,10);
fill(255);
textMode(SCREEN);
// Get the raw depth as array of integers
ku.update(true);
// Translate and rotate
translate(width/2,height/2,-50);
rotateY(sin(0.0*3.14f)); // don't need to mangle the angle like this - use a fixed perspective (slightly from side)
// print("(min , max) = " + ku.minz + "," + ku.maxz + " stats fixed? + " + !ku.enable_stats + " \n");
PVector weighted2d = new PVector();
float mass2d = 0;
for(int x=0; x<ku.w; x+=ku.skip) {
for(int y=0; y<ku.h; y+=ku.skip) {
int offset = x+y*ku.w;
PVector v = ku.world[offset];
// draw only pixels in desirable box of pixels.....
if (v.z<ku.maxz-ku.back && ku.minz-ku.front < v.z) {
stroke(255);
pushMatrix();
float factor = 600;
translate(-v.x*factor,v.y*factor,factor-v.z*factor);
float visX = screenX(0,0,0);
float visY = screenY(0,0,0);
float weight = 1.0/(v.z-ku.minz);
if (0 < visX && visX < width && 0 < visY && visY < height) {
weighted2d.x += visX*weight;
weighted2d.y += visY*weight;
mass2d += weight;
// Draw a point
color c = color(100-((v.z-ku.minz)/0.8*100)/2,100,100);
stroke(c);
fill(c);
beginShape();
vertex(0,-1);
vertex(1,0);
vertex(0,1);
vertex(-1,0);
endShape();
}
popMatrix();
}
}
}
popMatrix();
if (ku.is_stale) {
ux.signalReload();
return;
}
if (mass2d > 0.0) {
color c = color(80,100,100);
stroke(c);
fill(c);
weighted2d.div(mass2d);
ellipse(weighted2d.x,weighted2d.y,20,20);
ux.observe(weighted2d,mass2d);
} else {
ux.observe_empty();
}
}
}
void keyPressed() {
if (key == 'x' || key == 'y' || key == 'z' || key == 'f' || key == 'b' || key == ' ') {
controlled_parm = key;
}
else if (key == CODED) {
if (keyCode == UP) {
ku.reConfigure(controlled_parm,translation_on,delta);
}
else if (keyCode == DOWN) {
ku.reConfigure(controlled_parm,translation_on,-delta);
}
}
else if (key == 'c') {
ku.center();
}
else if (key == 't') {
translation_on = !translation_on;
}
else if (key == 'u') {
delta = delta*10;
}
else if (key == 'd') {
delta = delta/10;
}
else if (key == 'r') {
ku.reset();
}
else if (key == 'k') {
ku.toggleStats();
}
else if (key == 'l') {
// load settings from disk
ku.loadSettings();
}
else if (key == 's') {
// save settings to disk
ku.saveSettings();
}
else if (key == 'q') {
ux.signalReload();
}
if (controlled_parm != ' ') {
question.setLabel("Calibrating " + controlled_parm);
String details = "";
if (translation_on) {
details = "Translation on. ";
}
details = details + " delta=" + delta;
response.setLabel(details);
}
else {
question.setLabel("");
response.setLabel("");
}
}
void stop() {
kinect.quit();
super.stop();
}