-
Notifications
You must be signed in to change notification settings - Fork 0
/
Processing_Hand_Modeling_code.pde
292 lines (283 loc) · 6.65 KB
/
Processing_Hand_Modeling_code.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*------Proccessing Modeling code for the Motion Capture Glove------*/
import processing.serial.*;
Serial myPort;
float e = 0;
int xPos = 1;
float prevYaw = 0;
float yaw1 = 0;
float yaw2 = 0;
float yaw3 = 0;
float yaw4 = 0;
float prevPitch = 0;
float pitch1 = 0;
float pitch2 = 0;
float pitch3 = 0;
float pitch4 = 0;
float prevRoll = 0;
float roll1 = 0;
float roll2 = 0;
float roll3 = 0;
float roll4 = 0;
float inByte = 0;
float rotation = 0;
int index1;
int index2;
float movePitch1 = 0;
float movePitch2 = 0;
float xMove = 0;
float yMove = 0;
float zMove = 0;
int flex1 = 0;
int flex2 = 0;
int flex3 = 0;
int flex4 = 0;
int flex5 = 0;
int flex6 = 0;
int flex7 = 0;
int flex8 = 0;
int flex9 = 0;
int flex10 = 0;
int flex11 = 0;
int flex12 = 0;
int flex13 = 0;
int flex14 = 0;
float initalYawDiff2 = 0;
float initalPitchDiff2 = 0;
int prevX = 0;
int prevY = 0;
float pastE = 0;
void setup () {
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 250000);
background(0);
size(1000, 1000, P3D);
noStroke();
fill(255);
rectMode(CENTER);
initalYawDiff2 = roll2-roll1-flex9;
initalPitchDiff2 = pitch2-pitch1;
}
void draw () {
background(100);
pushMatrix();
translate(width/2, height/2,0);
pointLight(255, 200, 200, 400, 400, 500);
pointLight(200, 200, 255, -400, 400, 500);
pointLight(255, 255, 255, 0, 0, -500);
rotateY(radians(mouseX));
rotateZ(radians(mouseY));
rotateX(radians(pastE));
prevY = mouseY;
prevX = mouseX;
rotateY(radians(yaw4));
rotateZ(radians(roll4));
rotateX(radians(pitch4));
box(200,50,100);
translate(100,-15,0);
rotateY(radians(yaw1-yaw4));
rotateZ(radians(roll1-roll4));
rotateX(radians(pitch1-pitch4));
beginShape();
vertex(0,0,-60);
vertex(0,30,-60);
vertex(0,30,60);
vertex(0,0,60);
endShape();
beginShape();
vertex(0,30,60);
vertex(0,0,60);
vertex(181,0,76);
vertex(181,30,76);
endShape();
beginShape();
vertex(181,0,76);
vertex(181,30,76);
vertex(211,30,-5);
vertex(211,0,-5);
endShape();
beginShape();
vertex(211,30,-5);
vertex(211,0,-5);
vertex(211,0,-73);
vertex(211,30,-73);
endShape();
beginShape();
vertex(211,0,-73);
vertex(211,30,-73);
vertex(43,30,-82);
vertex(43,0,-82);
endShape();
beginShape();
vertex(43,30,-82);
vertex(43,0,-82);
vertex(0,0,-60);
vertex(0,30,-60);
endShape();
beginShape();
vertex(0,30,-60);
vertex(0,30,60);
vertex(0,30,60);
vertex(181,30,76);
vertex(181,30,76);
vertex(211,30,-5);
vertex(211,30,-5);
vertex(211,30,-73);
vertex(211,30,-73);
vertex(43,30,-82);
vertex(43,30,-82);
vertex(0,30,-60);
endShape();
beginShape();
vertex(0,0,-60);
vertex(0,0,60);
vertex(0,0,60);
vertex(181,0,76);
vertex(181,0,76);
vertex(211,0,-5);
vertex(211,0,-5);
vertex(211,0,-73);
vertex(211,0,-73);
vertex(43,0,-82);
vertex(43,0,-82);
vertex(0,0,-60);
endShape();
pushMatrix();
translate(211,15,-50);
rotateZ(radians(flex3));
rotateY(radians(10));
box(10,20, 20);
translate(41,0,0);
box(72,30,30);
translate(36,0,0);
rotateZ(radians(flex5));
box(10,20,20);
translate(33,0,0);
box(56,30,30);
translate(28,0,0);
rotateZ(radians(flex11));
box(10,20,20);
translate(27,0,0);
box(44,30, 30);
popMatrix();
pushMatrix();
translate(211,15,-5);
rotateZ(radians(flex2));
box(10,20, 20);
translate(50,0,0);
box(90,30,30);
translate(45,0,0);
rotateZ(radians(flex6));
box(10,20,20);
translate(34,0,0);
box(58,30,30);
translate(29,0,0);
rotateZ(radians(flex12));
box(10,20,20);
translate(27,0,0);
box(44,30, 30);
popMatrix();
pushMatrix();
translate(197,15,33);
rotateZ(radians(flex1));
rotateY(radians(-7));
box(10,20, 20);
translate(46,0,0);
box(82,30,30);
translate(41,0,0);
rotateZ(radians(flex7));
box(10,20,20);
translate(34,0,0);
box(58,30,30);
translate(29,0,0);
rotateZ(radians(flex13));
box(10,20,20);
translate(27,0,0);
box(44,30, 30);
popMatrix();
pushMatrix();
translate(181,15,76);
rotateZ(radians(flex4));
rotateX(radians(-12));
rotateY(radians(-20));
box(10,20, 20);
translate(32,0,0);
box(56,30,30);
translate(28,0,0);
rotateZ(radians(flex8/1.5));
box(10,25,25);
translate(21,0,0);
box(32,25,25);
translate(16,0,0);
rotateZ(radians(flex8/1.5));
box(10,20,20);
translate(21,0,0);
box(32,25, 25);
popMatrix();
translate(33,30,-82);
rotateX(radians(pitch3-pitch1));
rotateY(radians(yaw2+19-yaw1));
rotateZ(radians(roll3-roll1+15));
box(10,20,20);
translate(10,0,0);
println(yaw2 + " - " +yaw1 + " = "+(yaw2-yaw1) + " ");
//println(pitch1);
box(10,20, 20);
translate(44.5,0,0);
box(79,30,30);
translate(37,0,0);
rotateX(radians(pitch2-pitch3));
//rotateX(radians(20));
//rotateY(radians(yaw2-yaw3));
rotateZ(radians(roll2-roll3));
box(10,20,20);
translate(45,0,0);
//box(30,20, 20);
box(80,30, 30);
translate(40,0,0);
rotateZ(radians(flex10));
box(10,20,20);
translate(32,0,0);
box(54,30, 30);
popMatrix();
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null && inString.length()>8) {
String temp[] = splitTokens(inString, " ");
if(temp.length>16){
yaw1 = float(temp[0]);
pitch1 = float(temp[1]);
roll1 = float(temp[2]);
yaw2 = float(temp[3]);
pitch2 = float(temp[4]);
roll2 = float(temp[5]);
yaw3 = float(temp[6]);
pitch3 = float(temp[7]);
roll3 = float(temp[8]);
flex1 = int(temp[9]);
flex2 = int(temp[10]);
flex3 = int(temp[11]);
flex4 = int(temp[12]);
flex5 = int(temp[13]);
flex6 = int(temp[14]);
flex7 = int(temp[15]);
flex8 = int(temp[16]);
flex9 = int(temp[17]);
flex10 = int(temp[18]);
flex11 = int(temp[19]);
flex12 = int(temp[20]);
flex13 = int(temp[21]);
yaw4 = float(temp[22]);
pitch4 = float(temp[23]);
roll4 = float(temp[24]);
}
else{
println("no data detected");
}
}
}
void mouseWheel(MouseEvent event) {
e = event.getCount();
pastE+= e;
//println(e);
}