/
Kinect_Aurav2.pde
249 lines (207 loc) · 9.41 KB
/
Kinect_Aurav2.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import SimpleOpenNI.*;
import oscP5.*;
import netP5.*;
import processing.sound.*;
SoundFile soundfile1;
SoundFile soundfile2;
SoundFile soundfile3;
SimpleOpenNI kinect;
NetAddress myRemoteLocation;
OscP5 oscP5Receiver;
int currentState;
//figure variables
float volatility;
float flux;
color poseColor;
//aura-ring variables
float avgX;
float avgY;
float size;
int formResolution = int(random(3, 10));
int stepSize = 5;
int count = 100;
float tempstrokeWeight = 1;
int look02 = 200;
float centerX, centerY;
float[] x = new float[formResolution];
float[] y = new float[formResolution];
void setup() {
size(displayWidth, displayHeight, OPENGL);
background(0);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
kinect.enableUser();
myRemoteLocation = new NetAddress("127.0.0.1", 6448);
oscP5Receiver = new OscP5(this, 12000);
soundfile1 = new SoundFile(this, "Pose_1.mp3");
soundfile2 = new SoundFile(this, "Pose_2.mp3");
soundfile3 = new SoundFile (this, "Pose_3.mp3");
//aura-ring//
strokeWeight(tempstrokeWeight);
smooth();
stroke(0, 50);
}
void getProjective(int userId, int jointID, PVector convertedJoint) {
PVector joint = new PVector();
float confidence = kinect.getJointPositionSkeleton(userId, jointID, joint);
if (confidence < 0.5) {
return;
}
kinect.convertRealWorldToProjective(joint, convertedJoint);
}
void draw() {
scale(2);
translate(150,0);
fill(0, 15);
rect(-155, 0, width, height);
kinect.update();
IntVector userList = new IntVector();
kinect.getUsers(userList);
OscMessage myMessage = new OscMessage("/wek/inputs");
if (userList.size() > 0) {
for (int i = 0; i < userList.size(); i++) {
int userId = userList.get(i);
ArrayList<PVector> joints = new ArrayList<PVector>();
ArrayList<Integer> jointIds = new ArrayList<Integer>();
jointIds.add(SimpleOpenNI.SKEL_LEFT_FOOT); //Id# = 13
jointIds.add(SimpleOpenNI.SKEL_LEFT_KNEE); //Id# = 11
jointIds.add(SimpleOpenNI.SKEL_LEFT_HIP); //Id# = 9
jointIds.add(SimpleOpenNI.SKEL_TORSO); //Id# = 8
jointIds.add(SimpleOpenNI.SKEL_LEFT_SHOULDER); //Id# = 2
jointIds.add(SimpleOpenNI.SKEL_LEFT_ELBOW); //Id# = 4
jointIds.add(SimpleOpenNI.SKEL_LEFT_HAND); //Id# = 6
jointIds.add(SimpleOpenNI.SKEL_NECK); //Id# = 1
jointIds.add(SimpleOpenNI.SKEL_HEAD); //Id# = 0
jointIds.add(SimpleOpenNI.SKEL_NECK); //Id# = 1
jointIds.add(SimpleOpenNI.SKEL_RIGHT_HAND); //Id# = 7
jointIds.add(SimpleOpenNI.SKEL_RIGHT_ELBOW); //Id# = 5
jointIds.add(SimpleOpenNI.SKEL_RIGHT_SHOULDER); //Id# = 3
jointIds.add(SimpleOpenNI.SKEL_TORSO); //Id# = 8
jointIds.add(SimpleOpenNI.SKEL_RIGHT_HIP); //Id# = 10
jointIds.add(SimpleOpenNI.SKEL_RIGHT_KNEE); //Id# = 12
jointIds.add(SimpleOpenNI.SKEL_RIGHT_FOOT); //Id# = 14
for (int k = 0; k < jointIds.size(); k++) {
int jid = jointIds.get(k);
PVector newJoint = new PVector();
getProjective(userId, jid, newJoint);
joints.add(newJoint);
}
if (userList.size() == 2) {
myMessage.add(joints.get(3).x);
myMessage.add(joints.get(3).y);
myMessage.add(joints.get(6).x - joints.get(3).x);
myMessage.add(joints.get(6).y - joints.get(3).y);
myMessage.add(joints.get(10).x - joints.get(3).x);
myMessage.add(joints.get(10).y - joints.get(3).y);
myMessage.add(joints.get(8).x - joints.get(3).x);
myMessage.add(joints.get(8).y - joints.get(3).y);
}
// State Changer
if (kinect.isTrackingSkeleton(userId)) {
if (currentState == 1) {
flux = 5;
volatility = 0.2;
poseColor = lerpColor(color(76, 82, 240), color(7, 200, 249), 0.5+0.5*sin(frameCount*0.015));
} else if (currentState == 2) {
flux = 10;
volatility = 0.5;
poseColor = (lerpColor(color(255, 7, 7), color(243, 73, 11), 0.5+0.5*sin(frameCount*0.015)));
} else if (currentState == 3) {
flux = 10;
volatility = 0.1;
poseColor = (lerpColor(color(156, 15, 178), color(172, 130, 203), 0.5+0.5*sin(frameCount*0.015)));
avgX = ((joints.get(0).x + joints.get(1).x + joints.get(2).x + joints.get(3).x + joints.get(4).x + joints.get(5).x + joints.get(6).x + joints.get(7).x + joints.get(9).x + joints.get(10).x + joints.get(11).x + joints.get(12).x + joints.get(13).x + joints.get(14).x + joints.get(15).x + joints.get(16).x)/17);
avgY = ((joints.get(0).y + joints.get(1).y + joints.get(2).y + joints.get(3).y + joints.get(4).y + joints.get(5).y + joints.get(6).y + joints.get(7).y + joints.get(9).y + joints.get(10).y + joints.get(11).y + joints.get(12).y + joints.get(13).y + joints.get(14).y + joints.get(15).y + joints.get(16).y)/17);
centerX = avgX;
centerY = avgY;
float d = dist(joints.get(8).x, joints.get(8).y, joints.get(15).x, joints.get(15).y);
float s = map(d, 400, height, 200, 800);
float initRadius = random(350, s);
float angle = radians(360/float(formResolution));
for (int q=0; q<formResolution; q++) {
x[q] = cos(angle*q) * initRadius;
y[q] = sin(angle*q) * initRadius;
}
for (int k=0; k<count; k++) {
stroke(0, (255/count*k), 120, 30);
for (int q=0; q<formResolution; q++) {
x[q] += random(-stepSize, stepSize);
y[q] += random(-stepSize, stepSize);
x[q] += random(cos(angle*q) * initRadius /look02);
y[q] += random(sin(angle*q) * initRadius /look02);
}
noFill();
beginShape();
curveVertex(x[formResolution-1]+centerX, y[formResolution-1]+centerY);
for (int q=0; q<formResolution; q++) {
curveVertex(x[q]+centerX, y[q]+centerY);
}
curveVertex(x[0]+centerX, y[0]+centerY);
curveVertex(x[1]+centerX, y[1]+centerY);
endShape();
}
} else {
flux = 5;
volatility = 0.2;
poseColor = color(0, 0, 255);
}
float fatWidthOff = flux*sin(volatility*frameCount);
float thinWidthOff = flux*cos(volatility*frameCount);
float fatHeightOff = flux*sin(volatility*frameCount);
float thinHeightOff = flux*cos(volatility*frameCount);
pushStyle();
fill(poseColor);
createShape();
beginShape();
curveVertex(joints.get(1).x, joints.get(1).y); //Left Knee
curveVertex(joints.get(0).x, joints.get(0).y); //Left Foot
curveVertex(joints.get(0).x - fatWidthOff, joints.get(0).y); //Left Foot Offset
curveVertex(joints.get(1).x - fatWidthOff, joints.get(1).y); //Left Knee Offset
curveVertex(joints.get(2).x - fatWidthOff, joints.get(2).y); //Left Hip Offset
curveVertex(joints.get(3).x - thinWidthOff, joints.get(3).y); //Torso Offset
curveVertex(joints.get(4).x, joints.get(4).y + thinHeightOff); //Left Shoulder offset
curveVertex(joints.get(5).x - thinWidthOff, joints.get(5).y); //Left Elbow
curveVertex(joints.get(6).x - thinWidthOff, joints.get(6).y); //Left Hand
curveVertex(joints.get(6).x - thinWidthOff, joints.get(6).y - fatHeightOff); //Left Hand Offset
curveVertex(joints.get(5).x - thinWidthOff, joints.get(5).y - fatHeightOff); // Left Elbow Offset
curveVertex(joints.get(4).x, joints.get(4).y - thinHeightOff); //Left Shoulder
curveVertex(joints.get(7).x - thinWidthOff, joints.get(7).y); //Neck Offset
curveVertex(joints.get(8).x - fatWidthOff, joints.get(8).y); //Head Offset
curveVertex(joints.get(8).x, joints.get(8).y - fatHeightOff); //Head Offset
curveVertex(joints.get(8).x + fatWidthOff, joints.get(8).y); //Head Offset
curveVertex(joints.get(9).x + thinWidthOff, joints.get(9).y); //Neck Offset
curveVertex(joints.get(12).x, joints.get(12).y - thinHeightOff); //Right Shoulder
curveVertex(joints.get(11).x + thinWidthOff, joints.get(11).y - fatHeightOff); //Right Elbow Offset
curveVertex(joints.get(10).x + thinWidthOff, joints.get(10).y - fatHeightOff); //Right Hand Offset
curveVertex(joints.get(10).x + thinWidthOff, joints.get(10).y); //Right Hand
curveVertex(joints.get(11).x + thinWidthOff, joints.get(11).y); //Right Elbow
curveVertex(joints.get(12).x, joints.get(12).y + thinHeightOff); //Right Shoulder Offset
curveVertex(joints.get(13).x + thinWidthOff, joints.get(13).y); //Torso Offset
curveVertex(joints.get(14).x + fatWidthOff, joints.get(14).y); //Right Hip Offset
curveVertex(joints.get(15).x + fatWidthOff, joints.get(15).y); //Right Knee Offset
curveVertex(joints.get(16).x + fatWidthOff, joints.get(16).y); //Right Foot Offset
curveVertex(joints.get(16).x, joints.get(16).y); //Right Foot
curveVertex(joints.get(15).x, joints.get(15).y); //Right Knee
endShape(CLOSE);
popStyle();
}
}
}
if (userList.size() == 2) {
oscP5Receiver.send(myMessage, myRemoteLocation);
}
pushStyle();
textSize(64);
fill(225, 0, 0);
text(currentState, width/2, height/2);
popStyle();
}
void oscEvent(OscMessage message) {
if (message.checkAddrPattern("/wek/outputs") == true) {
currentState = (int) message.get(0).floatValue();
}
}
void onNewUser(SimpleOpenNI kinect, int userID) {
println("Start skeleton tracking");
kinect.startTrackingSkeleton(userID);
}