Normand Briere
2019-05-13 f924d3e00db476c06f55f3d5aaef307e17575340
Mocap.java
....@@ -26,6 +26,574 @@
2626 public class Mocap extends Object3D
2727 {
2828 static final long serialVersionUID = 7437391692559853707L;
29
+
30
+ void Fade()
31
+ {
32
+ if (currentbones == null || CameraPane.fullreset)
33
+ return;
34
+
35
+ cVector temp = new cVector();
36
+
37
+ int numframes = bvh.animation.getNumFrames();
38
+
39
+ int b;
40
+ float[] data;
41
+ Quat4d quatstart = new Quat4d();
42
+ Quat4d quatend = new Quat4d();
43
+ Quat4d quat = new Quat4d();
44
+ Matrix4d mat4d = new Matrix4d();
45
+ double[][] rot = new double[4][4];
46
+ for (b=numbones; --b>=0;) // HIP ROTATION: 0;)
47
+ {
48
+ // int hipindex = get(0)._index;
49
+
50
+// assert(get(0).get(0)._isHip);
51
+
52
+ // if (b == hipindex)
53
+ // continue;
54
+
55
+ data = bvh.animation.getBoneData(b);
56
+
57
+ int dof = 3; // data.length/numframes;
58
+
59
+ if (b == 0)
60
+ {
61
+ dof = 6;
62
+ }
63
+ // assert(dof == 3);
64
+
65
+ int boneframe3 = (b-1)*3; // dof;
66
+
67
+ // System.err.println("Bone #" + b + ": dof = " + dof);
68
+ int fadein = 45; // 120;
69
+
70
+ // if (b == hipindex)
71
+ // fadein *= 5;
72
+
73
+ if (fadein > numframes)
74
+ fadein = 0; // numframes;
75
+
76
+ for (int fi=fadein; --fi>=0;)
77
+ //for (int f=numframes; --f>=0;)
78
+ {
79
+ int f = fi + GetFirstFrame();
80
+
81
+ int f3 = f*dof;
82
+
83
+ float k = fi;
84
+
85
+ k /= fadein - 1;
86
+
87
+ if (Float.isNaN(k))
88
+ k = 1; // 0/0
89
+
90
+ k = (float) (-Math.cos(k*Math.PI));
91
+ k += 1;
92
+ k /= 2;
93
+
94
+ int start = 3;
95
+ int end = 0;
96
+
97
+ if (dof == 6)
98
+ {
99
+ start = 6;
100
+ end = 3;
101
+ }
102
+
103
+ if (b == 0)
104
+ {
105
+ for (int i=start; --i>=end;)
106
+ {
107
+ //data[f3 + i] += pos[i] - data[frame3 + i];
108
+// data[f3 + i] = k*data[f3+i] + (1-k)*
109
+// currentbones[boneframe3 + i-end];
110
+// data[f3 + i] = (float)CurveAngle(data[f3+i], currenthip[i], 1-k);
111
+ }
112
+
113
+ // TODO: translation
114
+
115
+// _t1.setIdentity();
116
+// _t2.setIdentity();
117
+// _t2.rotZ(currentbones[boneframe3 + start-1-end]);
118
+// _t1.mul(_t2);
119
+// _t2.setIdentity();
120
+// if (b == 0)
121
+// {
122
+// _t2.rotY(currentbones[boneframe3 + start-2-end]);
123
+// _t1.mul(_t2);
124
+// _t2.setIdentity();
125
+// _t2.rotX(currentbones[boneframe3 + start-3-end]);
126
+// }
127
+// else
128
+// {
129
+// _t2.rotX(currentbones[boneframe3 + start-2-end]);
130
+// _t1.mul(_t2);
131
+// _t2.setIdentity();
132
+// _t2.rotY(currentbones[boneframe3 + start-3-end]);
133
+// }
134
+// _t1.mul(_t2);
135
+// _t2.setIdentity();
136
+//
137
+// _t1.get(mat4d);
138
+//
139
+// mat4d.get(quatstart);
140
+//
141
+// _t1.setIdentity();
142
+// _t2.setIdentity();
143
+// _t2.rotZ(data[f3 + start-1]);
144
+// _t1.mul(_t2);
145
+// _t2.setIdentity();
146
+// if (b == 0)
147
+// {
148
+// _t2.rotY(data[f3 + start-2]);
149
+// _t1.mul(_t2);
150
+// _t2.setIdentity();
151
+// _t2.rotX(data[f3 + start-3]);
152
+// }
153
+// else
154
+// {
155
+// _t2.rotX(data[f3 + start-2]);
156
+// _t1.mul(_t2);
157
+// _t2.setIdentity();
158
+// _t2.rotY(data[f3 + start-3]);
159
+// }
160
+//
161
+// _t1.mul(_t2);
162
+// _t2.setIdentity();
163
+//
164
+// _t1.get(mat4d);
165
+//
166
+// mat4d.get(quatend);
167
+//
168
+// double dot = quatstart.x*quatend.x +
169
+// quatstart.y*quatend.y +
170
+// quatstart.z*quatend.z +
171
+// quatstart.w*quatend.w
172
+// ;
173
+//
174
+// if (dot < 0)
175
+// {
176
+// quatend.x *= -1;
177
+// quatend.y *= -1;
178
+// quatend.z *= -1;
179
+// quatend.w *= -1;
180
+// }
181
+//
182
+// // k = 1-k;
183
+//
184
+// quat.x = (1-k)*quatstart.x + k*quatend.x;
185
+// quat.y = (1-k)*quatstart.y + k*quatend.y;
186
+// quat.z = (1-k)*quatstart.z + k*quatend.z;
187
+// quat.w = (1-k)*quatstart.w + k*quatend.w;
188
+//
189
+// quat.normalize();
190
+//
191
+// mat4d.set(quat);
192
+//
193
+// cJ3D.SetTransform(rot, mat4d);
194
+//
195
+// matrixToEulerXYZ(rot, temp);
196
+//
197
+// data[f3 + start-1] = -(float)temp.z;
198
+//
199
+// if (b == 0)
200
+// {
201
+// data[f3 + start-2] = -(float)temp.y;
202
+// data[f3 + start-3] = -(float)temp.x;
203
+// }
204
+// else
205
+// {
206
+// data[f3 + start-2] = -(float)temp.x;
207
+// data[f3 + start-3] = -(float)temp.y;
208
+// }
209
+ }
210
+ else
211
+ {
212
+ for (int i=start; --i>=end;)
213
+ {
214
+ //data[f3 + i] += pos[i] - data[frame3 + i];
215
+// data[f3 + i] = k*data[f3+i] + (1-k)*
216
+// currentbones[boneframe3 + i-end];
217
+ data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i/*-end*/], 1-k);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ // Updates the toParent matrix to keep the same position and orientation
225
+ // before resetting the mocap data.
226
+ void SetGlobalTransform()
227
+ {
228
+ //SetCurrentBones(frame);
229
+
230
+ cVector temp = new cVector();
231
+ cVector pos = new cVector();
232
+ cVector poship = new cVector();
233
+
234
+ double angleY = 0;
235
+ double angleYhip = 0;
236
+
237
+ Object3D hip = get(0);
238
+
239
+ if (hip.get(0).toParent == null)
240
+ {
241
+ hip.get(0).toParent = LA.newMatrix();
242
+ hip.get(0).fromParent = LA.newMatrix();
243
+ }
244
+
245
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
246
+ poship.x = matrix[3][0];
247
+ poship.y = matrix[3][1];
248
+ poship.z = matrix[3][2];
249
+
250
+ temp.x = 1;
251
+ temp.y = 0;
252
+ temp.z = 0;
253
+
254
+ LA.xformDir(temp, matrix, temp);
255
+
256
+ angleYhip = Math.atan2(-temp.z, temp.x);
257
+
258
+ LA.matIdentity(toParent);
259
+ LA.matYRotate(toParent, angleYhip);
260
+ LA.matTranslate(toParent, poship.x, poship.y, poship.z);
261
+
262
+// LA.matConcat(toParent, hip.get(0).toParent, toParent);
263
+
264
+ CameraPane.debugpointG.toParent[3][0] = poship.x;
265
+ CameraPane.debugpointG.toParent[3][1] = poship.y;
266
+ CameraPane.debugpointG.toParent[3][2] = poship.z;
267
+
268
+ LA.matInvert(toParent, fromParent);
269
+
270
+ LA.matIdentity(hip.get(0).toParent);
271
+ LA.matIdentity(hip.get(0).fromParent);
272
+
273
+// if (true)
274
+// return;
275
+
276
+ // Updates hip.get(0).toParent
277
+ setPose(hip, GetFirstFrame(), bvh.animation.getBoneData(hip._index));
278
+
279
+ // A = toParent; B = hip.get(0).toParent
280
+ // A'*B = A
281
+ // A' = A * B-1
282
+
283
+ poship.x = hip.get(0).toParent[3][0];
284
+ poship.y = hip.get(0).toParent[3][1];
285
+ poship.z = hip.get(0).toParent[3][2];
286
+
287
+ temp.x = 1;
288
+ temp.y = 0;
289
+ temp.z = 0;
290
+
291
+ LA.xformDir(temp, hip.get(0).toParent, temp);
292
+
293
+ angleYhip = Math.atan2(-temp.z, temp.x);
294
+
295
+ LA.matIdentity(matrix);
296
+ LA.matYRotate(matrix, angleYhip);
297
+ LA.matTranslate(matrix, poship.x, poship.y, poship.z);
298
+
299
+ //LA.matInvert(hip.get(0).toParent, matrix);
300
+ LA.matInvert(matrix, matrix);
301
+
302
+ //LA.matIdentity(matrix);
303
+ //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
304
+
305
+ LA.matConcat(toParent, matrix, toParent);
306
+
307
+
308
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
309
+ pos.x = hip.get(0).toParent[3][0];
310
+ pos.y = hip.get(0).toParent[3][1];
311
+ pos.z = hip.get(0).toParent[3][2];
312
+ LA.xformPos(new cVector(), hip.get(0).toParent, pos);
313
+ LA.xformPos(pos, toParent, pos);
314
+
315
+// temp.x = 1;
316
+// temp.y = 0;
317
+// temp.z = 0;
318
+//
319
+// LA.xformDir(temp, toParent, temp);
320
+//
321
+// angleY = Math.atan2(-temp.z, temp.x);
322
+//
323
+// LA.matIdentity(toParent);
324
+// LA.matYRotate(toParent, angleY - angleYhip);
325
+// LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
326
+
327
+ CameraPane.debugpointP.toParent[3][0] = pos.x;
328
+ CameraPane.debugpointP.toParent[3][1] = pos.y;
329
+ CameraPane.debugpointP.toParent[3][2] = pos.z;
330
+
331
+ CameraPane.debugpointC.toParent[3][0] = poship.x;
332
+ CameraPane.debugpointC.toParent[3][1] = poship.y;
333
+ CameraPane.debugpointC.toParent[3][2] = poship.z;
334
+
335
+ poship.x = toParent[3][0];
336
+ poship.y = toParent[3][1];
337
+ poship.z = toParent[3][2];
338
+
339
+ CameraPane.debugpointR.toParent[3][0] = poship.x;
340
+ CameraPane.debugpointR.toParent[3][1] = poship.y;
341
+ CameraPane.debugpointR.toParent[3][2] = poship.z;
342
+
343
+ LA.matInvert(toParent, fromParent);
344
+ }
345
+
346
+ void LoadData()
347
+ {
348
+ float[] thedata = bvh.animation.getBoneData(0);
349
+
350
+// thedata[0] = 0;
351
+// thedata[1] = 0;
352
+// thedata[2] = 0;
353
+// thedata[3] = 0;
354
+// thedata[4] = 0;
355
+// thedata[5] = 0;
356
+
357
+ if (true)
358
+ return;
359
+
360
+ for (int b=numbones; --b>=0;)
361
+ //int b = 0;
362
+ {
363
+ thedata = bvh.animation.getBoneData(b);
364
+
365
+ int numframes = bvh.animation.getNumFrames();
366
+
367
+ int dof = 6; // thedata.length/numframes;
368
+
369
+ if (b > 0)
370
+ dof = 3;
371
+
372
+ if (dof != thedata.length/numframes)
373
+ {
374
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
375
+ dof = thedata.length/numframes;
376
+ }
377
+
378
+ //for (int f=numframes; --f>=offset;)
379
+ int firstframe = GetFirstFrame();
380
+ for (int f=0; f<numframes-firstframe; f++)
381
+ {
382
+ int f3 = f*dof;
383
+
384
+ //for (int i=3/*dof*/; --i>=0;)
385
+ for (int i=dof; --i>=0;)
386
+ {
387
+ //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
388
+ thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
389
+ }
390
+ }
391
+ }
392
+ }
393
+
394
+ void ResetZero()
395
+ {
396
+ for (int b=numbones; --b>=0;)
397
+ {
398
+ float[] thedata = bvh.animation.getBoneData(b);
399
+
400
+ int numframes = bvh.animation.getNumFrames();
401
+
402
+ int dof = 6;
403
+
404
+ if (b > 0)
405
+ dof = 3;
406
+
407
+ for (int i=dof; --i>=0;)
408
+ {
409
+ thedata[i] = 0;
410
+ }
411
+ }
412
+ }
413
+
414
+ void SetCurrentBones(int frame)
415
+ {
416
+ if (frame == 0)
417
+ {
418
+ //frame = 1;
419
+ }
420
+
421
+ if (currentbones == null)
422
+ {
423
+ currentbones = new double[(numbones-1)*3];
424
+ currenthip = new double[6];
425
+ }
426
+
427
+ for (int b=numbones; --b>=1;) // HIP ROTATION: 0;)
428
+ //int b = 0;
429
+ {
430
+ float[] data = bvh.animation.getBoneData(b);
431
+
432
+ // int numframes = bvh.animation.getNumFrames();
433
+
434
+ int dof = 6; // data.length/numframes;
435
+
436
+ if (b > 0)
437
+ dof = 3;
438
+
439
+ //assert(dof == 3);
440
+
441
+ // System.err.println("Bone #" + b + ": dof = " + dof);
442
+ int theframe = // 1; // baseframe;
443
+ frame;
444
+
445
+ int frame3 = theframe*dof;
446
+ int bone3 = (b-1)*dof;
447
+
448
+ int start = 3;
449
+ int end = 0;
450
+
451
+ if (dof == 6)
452
+ {
453
+ start = 6;
454
+ //end = 3;
455
+ }
456
+
457
+ for (int i=start; --i>=end;)
458
+ {
459
+ currentbones[bone3 + i/*-end*/] = data[frame3 + i];
460
+ }
461
+ }
462
+
463
+ float[] data = bvh.animation.getBoneData(0);
464
+
465
+ int dof = 6;
466
+
467
+ int theframe = frame;
468
+
469
+ int frame3 = theframe*dof;
470
+
471
+ int start = 6;
472
+ int end = 0;
473
+
474
+ for (int i=start; --i>=end;)
475
+ {
476
+ currenthip[i] = data[frame3 + i];
477
+ }
478
+ }
479
+
480
+ static cVector centroid = new cVector();
481
+ static cVector mocaporigin = new cVector();
482
+
483
+ void SetHipOrientation()
484
+ {
485
+ Object3D hip = get(0);
486
+
487
+ if (toParent == null)
488
+ {
489
+ toParent = LA.newMatrix();
490
+ fromParent = LA.newMatrix();
491
+ }
492
+
493
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
494
+
495
+ mocaporigin.x = matrix[3][0];
496
+ mocaporigin.y = matrix[3][1];
497
+ mocaporigin.z = matrix[3][2];
498
+
499
+ centroid.x = matrix[3][0];
500
+ centroid.y = matrix[3][1];
501
+ centroid.z = matrix[3][2];
502
+// this.getCentroid(centroid, true);
503
+
504
+ CameraPane.debugpointG.name = "";
505
+ CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
506
+ CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
507
+ CameraPane.debugpointG.toParent[3][2] = mocaporigin.z;
508
+
509
+ CameraPane.debugpointP.name = "";
510
+ CameraPane.debugpointP.toParent[3][0] = centroid.x;
511
+ CameraPane.debugpointP.toParent[3][1] = centroid.y;
512
+ CameraPane.debugpointP.toParent[3][2] = centroid.z;
513
+
514
+ cVector goal = GetGoal(centroid);
515
+ if (goal != null)
516
+ {
517
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
518
+
519
+ goalposx = goal.x;
520
+ goalposz = goal.z;
521
+ targetdirx = targetdirz = 0;
522
+ }
523
+
524
+ if (goalposx == 0 && goalposz == 0)
525
+ {
526
+ // No target
527
+ if (ScriptNode.speaker != null)
528
+ {
529
+ Object3D sourcenode = GetFileRoot();
530
+ Object3D speakernode = ScriptNode.speaker.GetFileRoot();
531
+
532
+ //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker);
533
+
534
+ Object3D speaker = ScriptNode.speaker;
535
+
536
+ if (speakernode == sourcenode)
537
+ {
538
+ if (ScriptNode.lastspeaker != null)
539
+ {
540
+ speakernode = ScriptNode.lastspeaker.GetFileRoot();
541
+ speaker = ScriptNode.lastspeaker;
542
+ }
543
+ else
544
+ return;
545
+ }
546
+
547
+ cVector dst = new cVector();
548
+
549
+ boolean success = speakernode.getCentroid(dst); // , true);
550
+
551
+ if (!success)
552
+ new Exception().printStackTrace();
553
+
554
+ //speakernode.parent.TransformToWorld(dst);
555
+ //sourcenode.parent.TransformToLocal(dst);
556
+ this.parent.TransformToLocal(dst);
557
+
558
+ goalposx = dst.x;
559
+ goalposz = dst.z;
560
+ }
561
+ else
562
+ return;
563
+ }
564
+
565
+ cVector temp = new cVector();
566
+
567
+ temp.x = 1;
568
+ temp.y = 0;
569
+ temp.z = 0;
570
+
571
+ LA.xformDir(temp, matrix, temp);
572
+
573
+ double angleYhip = Math.atan2(-temp.z, temp.x);
574
+
575
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
576
+
577
+ LA.matIdentity(matrix);
578
+ LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
579
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
580
+ LA.matYRotate(matrix, angle);
581
+ LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
582
+
583
+ LA.matConcat(matrix, toParent, toParent);
584
+
585
+ LA.matInvert(toParent, fromParent);
586
+
587
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
588
+
589
+ centroid.x = matrix[3][0];
590
+ centroid.y = matrix[3][1];
591
+ centroid.z = matrix[3][2];
592
+
593
+ double dist = LA.distance(centroid, mocaporigin);
594
+
595
+ CheckForAction(centroid);
596
+ }
29597
30598 void WriteTo(java.io.Writer writer) throws Exception
31599 {
....@@ -99,11 +667,11 @@
99667 double pinx;
100668 double pinz;
101669
102
- double targetx;
103
- double targetz;
670
+ double targetdirx;
671
+ double targetdirz;
104672
105
- double goalx;
106
- double goalz;
673
+ double goalposx = 0; // -20;
674
+ double goalposz = 0; // -10;
107675
108676 boolean followpath;
109677
....@@ -174,7 +742,7 @@
174742 scriptactions.clear();
175743 }
176744
177
- static double EPSACTION = 0.1; // 0.075; // 0.1;
745
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
178746
179747 void AddFromTo(cVector from, cVector to)
180748 {
....@@ -359,7 +927,7 @@
359927 // //GetFileRoot();
360928
361929 // sept 2014: //
362
- GrafreeD.RENDERME = 3; // patch for Merge objects
930
+ Grafreed.RENDERME = 3; // patch for Merge objects
363931 float[] thedata = bvh.animation.getBoneData(0);
364932
365933 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -460,6 +1028,8 @@
4601028 testvect.set(from);
4611029 testvect.sub(fromto.from);
4621030
1031
+ testvect.y = 0; // PATCH
1032
+
4631033 int factor = 1;
4641034
4651035 //if (CameraPane.FAST)
....@@ -501,6 +1071,8 @@
5011071
5021072 testvect.set(from);
5031073 testvect.sub(fromto.from);
1074
+
1075
+ testvect.y = 0; // PATCH
5041076
5051077 int factor = 1;
5061078
....@@ -705,7 +1277,7 @@
7051277 // skip first node: translation
7061278 // Object3D b = input.get(0);
7071279
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1280
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091281 }
7101282
7111283 //mocap.figure.Bone[] children = b.getChildren();
....@@ -736,6 +1308,7 @@
7361308
7371309 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
7381310 {
1311
+ assert(false);
7391312 //assert(CameraPane.drawMode == CameraPane.SHADOW);
7401313
7411314 Object3D transformnode = new Object3D();
....@@ -921,7 +1494,7 @@
9211494 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221495 }
9231496
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1497
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251498
9261499 if (footcontact && ground != -123456)
9271500 {
....@@ -939,9 +1512,9 @@
9391512 groundid = floorid;
9401513
9411514 // green
942
- CameraPane.debugpoint.toParent[3][0] = groundx;
943
- CameraPane.debugpoint.toParent[3][1] = floor.y;
944
- CameraPane.debugpoint.toParent[3][2] = groundz;
1515
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1516
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1517
+ CameraPane.debugpointG.toParent[3][2] = groundz;
9451518
9461519 if (true) // slow && stepout && onein)
9471520 {
....@@ -952,7 +1525,7 @@
9521525 // mywave = currentwave++;
9531526 // }
9541527 // sound
955
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1528
+ cVector eye = Globals.theRenderer.EyeCamera().location;
9561529
9571530 // if (sourcenode.parent.parent != null)
9581531 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -997,9 +1570,9 @@
9971570 //GraphreeD.
9981571 wav.play(volume * usedvolume); //, mywave);
9991572
1000
- lastsoundtime = CameraPane.framecount;
1573
+ lastsoundtime = Globals.framecount;
10011574
1002
- GrafreeD.hassound = true;
1575
+ Grafreed.hassound = true;
10031576 }
10041577 // else
10051578 // System.out.println("skipped");
....@@ -1018,9 +1591,9 @@
10181591
10191592 // System.out.println("Allo " + sourcenode);
10201593 // purple
1021
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1022
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1023
- CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
1594
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1595
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1596
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
10241597
10251598
10261599 if (false) // dist2 > 0.1)
....@@ -1086,9 +1659,9 @@
10861659 this.get(0).TransformToWorld(v0);
10871660
10881661 // cyan
1089
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1090
- CameraPane.debugpoint3.toParent[3][1] = ground;
1091
- CameraPane.debugpoint3.toParent[3][2] = v0.z;
1662
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1663
+ CameraPane.debugpointC.toParent[3][1] = ground;
1664
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
10921665
10931666 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10941667 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1098,9 +1671,9 @@
10981671 this.get(0).TransformToWorld(v0);
10991672
11001673 // red
1101
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1102
- CameraPane.debugpoint4.toParent[3][1] = ground;
1103
- CameraPane.debugpoint4.toParent[3][2] = v0.z;
1674
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1675
+ CameraPane.debugpointR.toParent[3][1] = ground;
1676
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
11041677 }
11051678 }
11061679
....@@ -1140,11 +1713,11 @@
11401713
11411714 if (goal != null)
11421715 {
1143
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1716
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11441717 //sourcenode.parent.parent.Dump();
1145
- goalx = goal.x;
1146
- goalz = goal.z;
1147
- targetx = targetz = 0;
1718
+ goalposx = goal.x;
1719
+ goalposz = goal.z;
1720
+ targetdirx = targetdirz = 0;
11481721
11491722 followpath = true;
11501723 }
....@@ -1195,16 +1768,16 @@
11951768 // }
11961769 if (false) // !uselast)
11971770 {
1198
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1199
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1200
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1771
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1772
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1773
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
12011774 }
12021775 }
12031776
1204
- if (goalx != 0 || goalz != 0) // TODO
1777
+ if (goalposx != 0 || goalposz != 0) // TODO
12051778 {
12061779 // overwrite speaker orientation
1207
- dst.set(goalx,0,goalz);
1780
+ dst.set(goalposx,0,goalposz);
12081781 if (sourcenode.parent != null) // july 2014
12091782 sourcenode.parent.
12101783 TransformToLocal(dst);
....@@ -1220,6 +1793,7 @@
12201793 src.x = 0;
12211794 src.y = 0;
12221795 src.z = 0;
1796
+ LA.xformPos(src, get(0).get(0).toParent, src);
12231797 LA.xformPos(src, get(0).toParent, src);
12241798 LA.xformPos(src, toParent, src);
12251799 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1255,26 +1829,26 @@
12551829 // mars 2014
12561830 if (false) // goalx != 0 || goalz != 0)
12571831 {
1258
- targetx = dst.x - src.x;
1259
- targetz = dst.z - src.z;
1832
+ targetdirx = dst.x - src.x;
1833
+ targetdirz = dst.z - src.z;
12601834
1261
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1835
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12621836 {
12631837 // far enough from goal. keep the goal position.
1264
- targetx = 0;
1265
- targetz = 0;
1838
+ targetdirx = 0;
1839
+ targetdirz = 0;
12661840 }
12671841 else
12681842 {
12691843 // too close to goal. switch to target direction instead.
1270
- goalx = 0;
1271
- goalz = 0;
1844
+ goalposx = 0;
1845
+ goalposz = 0;
12721846 }
12731847 }
12741848
12751849 //sourcenode.getCentroid(src, true);
12761850
1277
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1851
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12781852 {
12791853 if (ScriptNode.lastspeaker != null)
12801854 new Exception().printStackTrace();
....@@ -1283,13 +1857,13 @@
12831857
12841858 // LA.xformPos(src, fromParent, src);
12851859
1286
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1860
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
12871861 dst.sub(src);
12881862 else
12891863 // vector mode
12901864 {
1291
- dst.x = targetx;
1292
- dst.z = targetz;
1865
+ dst.x = targetdirx;
1866
+ dst.z = targetdirz;
12931867
12941868 // TEST TARGET
12951869 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1563,6 +2137,7 @@
15632137 toParent = LA.newMatrix();
15642138 fromParent = LA.newMatrix();
15652139 }
2140
+
15662141 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15672142 LA.matInvert(toParent, fromParent);
15682143
....@@ -1698,7 +2273,7 @@
16982273 }
16992274
17002275 if (!smoothed)
1701
- for (int i=4; --i>=0;)
2276
+ for (int i=10; --i>=0;)
17022277 SmoothAnimData(); // much reduces shakiness
17032278
17042279 smoothed = true;
....@@ -1736,9 +2311,16 @@
17362311 toVector.x = LA.cos(to);
17372312 toVector.y = LA.sin(to);
17382313
2314
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2315
+ double toA = Math.atan2(toVector.y, toVector.x);
2316
+
17392317 Vector2d currentVector = Slerp(fromVector, toVector, step);
17402318
1741
- return Math.atan2(currentVector.y, currentVector.x);
2319
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2320
+
2321
+ double angle2 = (1-step) * fromA + step * toA;
2322
+
2323
+ return angle;
17422324 }
17432325
17442326 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1780,12 +2362,28 @@
17802362 if (!live) // aout 2013
17812363 return;
17822364
1783
- cVector centroid = new cVector();
1784
- cVector floor = new cVector();
1785
-
1786
- Object3D sourcenode = GetFileRoot();
2365
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2366
+ try
2367
+ {
2368
+ SetPose(GetSkeleton(), bvh.animation, f);
2369
+ SetCurrentBones(frame);
2370
+ }
2371
+ catch (Exception e)
2372
+ {
2373
+ e.printStackTrace();
2374
+ }
17872375
1788
- boolean success; // = sourcenode.getCentroid(centroid);
2376
+ SetHipOrientation();
2377
+
2378
+ if (true)
2379
+ return;
2380
+
2381
+ cVector centroid = new cVector();
2382
+ cVector floor = new cVector();
2383
+
2384
+ Object3D sourcenode = GetFileRoot();
2385
+
2386
+ boolean success; // = sourcenode.getCentroid(centroid);
17892387 // if (!success)
17902388 // {
17912389 // //assert(success);
....@@ -1793,16 +2391,6 @@
17932391 // System.out.println("No centroid for " + sourcenode);
17942392 // }
17952393
1796
- //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
1797
- try
1798
- {
1799
- SetPose(GetSkeleton(), bvh.animation, f);
1800
- }
1801
- catch (Exception e)
1802
- {
1803
- e.printStackTrace();
1804
- }
1805
-
18062394 if (sourcenode.parent == null && sourcenode.fileparent == null)
18072395 {
18082396 // No GFD
....@@ -2050,7 +2638,7 @@
20502638 * @param frame
20512639 * Frame number
20522640 */
2053
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2641
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20542642 {
20552643 if (!live) // aout 2013
20562644 return;
....@@ -2058,6 +2646,33 @@
20582646 cVector temp = new cVector();
20592647 cVector temp0 = new cVector();
20602648 double pos[] = new double[3];
2649
+ double angleY = 0;
2650
+ double sinY = 0;
2651
+ double cosY = 0;
2652
+
2653
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2654
+ {
2655
+ bone.get(0).GlobalTransformInv();
2656
+
2657
+ temp.x = bone.get(0).globalTransform[3][0];
2658
+ temp.y = bone.get(0).globalTransform[3][1];
2659
+ temp.z = bone.get(0).globalTransform[3][2];
2660
+
2661
+ pos[0] = temp.x;
2662
+ pos[1] = temp.y;
2663
+ pos[2] = temp.z;
2664
+
2665
+ temp.x = 1;
2666
+ temp.y = 0;
2667
+ temp.z = 0;
2668
+
2669
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2670
+
2671
+ sinY = temp.z;
2672
+ cosY = temp.x;
2673
+
2674
+ angleY = Math.atan2(-sinY, cosY);
2675
+ }
20612676
20622677 // Object3D obj = get(0);
20632678 // Object3D gp = this.parent;
....@@ -2189,13 +2804,14 @@
21892804 if (//frame > 0 &&
21902805 !bone.skipmocap &&
21912806 !bone.name.contains("head") &&
2807
+ !bone.name.contains("Head") // &&
21922808 // !bone.name.contains("rFoot") &&
21932809 // !bone.name.contains("lFoot") &&
2194
- !bone.name.contains("Pinky") &&
2195
- !bone.name.contains("Ring") &&
2196
- !bone.name.contains("Mid") &&
2197
- !bone.name.contains("Index") &&
2198
- !bone.name.contains("Thumb")
2810
+// !bone.name.contains("Pinky") &&
2811
+// !bone.name.contains("Ring") &&
2812
+// !bone.name.contains("Mid") &&
2813
+// !bone.name.contains("Index") &&
2814
+// !bone.name.contains("Thumb")
21992815 )
22002816 {
22012817 //_rotTG.setTransform(_t1);
....@@ -2228,15 +2844,17 @@
22282844 // CROWD
22292845 //cJ3D.GetTranslation(bone, _trans0);
22302846 //_trans.add(_trans0);
2231
- _transTF.setIdentity();
2847
+ //_transTF.setIdentity();
2848
+ _transTF.set(_t1);
22322849 _transTF.setTranslation(_trans);
22332850 // System.err.println("Translate: " + _transTF);
22342851 //_transTG.setTransform(_transTF);
2235
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2852
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2853
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22362854 }
22372855 }
22382856
2239
- if (bone._isRoot && firsttimeafterload && frame > 0)
2857
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22402858 {
22412859 assert(bone == get(0));
22422860
....@@ -2252,17 +2870,17 @@
22522870 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22532871 //
22542872
2255
- Invariants();
2256
- bone.Invariants();
2257
- bone.get(0).Invariants();
2258
- // if (origin == null)
2259
- // origin = null;
2260
- origin.Invariants();
2261
- origin0.Invariants();
2873
+ Invariants();
2874
+ bone.Invariants();
2875
+ bone.get(0).Invariants();
2876
+ // if (origin == null)
2877
+ // origin = null;
2878
+ origin.Invariants();
2879
+ origin0.Invariants();
22622880
2263
-
2264
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2265
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2881
+
2882
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2883
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22662884
22672885 // matrixToEulerXYZ(toParent, temp);
22682886 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2296,7 +2914,7 @@
22962914 //
22972915 // mat4d.get(quat);
22982916
2299
- if (true) // hip correction
2917
+ if (false) // hip correction
23002918 {
23012919 _t2.setIdentity();
23022920
....@@ -2337,13 +2955,13 @@
23372955 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23382956 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23392957
2340
- LA.matInvert(toParent, fromParent);
2958
+//?? LA.matInvert(toParent, fromParent);
23412959
2342
- Invariants();
2343
- bone.Invariants();
2344
- bone.get(0).Invariants();
2345
- origin.Invariants();
2346
- origin0.Invariants();
2960
+ Invariants();
2961
+ bone.Invariants();
2962
+ bone.get(0).Invariants();
2963
+ origin.Invariants();
2964
+ origin0.Invariants();
23472965
23482966 // LA.matInvert(fromParent, tempmatrix);
23492967 //
....@@ -2364,33 +2982,39 @@
23642982 // temp.x = data[0];
23652983 // temp.y = data[1];
23662984 // temp.z = data[2];
2367
- LA.xformPos(temp, origin0.toParent, temp0);
2985
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23682986
2369
-// bone.GlobalTransformInv();
2370
-
2371
- temp0.x = bone.globalTransform[3][0];
2372
- temp0.y = bone.globalTransform[3][1];
2373
- temp0.z = bone.globalTransform[3][2];
2374
-
2987
+// bone.get(0).GlobalTransformInv();
2988
+//
2989
+// temp0.x = bone.get(0).globalTransform[3][0];
2990
+// temp0.y = bone.get(0).globalTransform[3][1];
2991
+// temp0.z = bone.get(0).globalTransform[3][2];
2992
+//
23752993 // MEGA TEST // june 2014: necessary for precision? otherwise comment works
2376
-fromParent[3][0] = 0;
2377
-fromParent[3][1] = 0;
2378
-fromParent[3][2] = 0;
2379
-LA.matInvert(fromParent, toParent);
2994
+//fromParent[3][0] = 0;
2995
+//fromParent[3][1] = 0;
2996
+//fromParent[3][2] = 0;
2997
+//LA.matInvert(fromParent, toParent);
23802998
2381
- LA.xformPos(temp0, fromParent, temp);
2999
+ LA.xformPos(temp0, fromParent, temp); // NU
23823000 //LA.xformPos(temp, bone.fromParent, temp);
23833001 // float[] data;
23843002
2385
- pos[0] = temp.x;
2386
- pos[1] = temp.y;
2387
- pos[2] = temp.z;
3003
+// pos[0] = temp.x;
3004
+// pos[1] = temp.y;
3005
+// pos[2] = temp.z;
3006
+//
3007
+// temp.x = 1;
3008
+// temp.y = 0;
3009
+// temp.z = 0;
3010
+//
3011
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23883012
23893013 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23903014 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23913015 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23923016
2393
- int numframes = bvh.animation.getNumFrames();
3017
+ int numframes = bvh.animation.getNumFrames();
23943018
23953019 int b = 0;
23963020 {
....@@ -2398,12 +3022,12 @@
23983022
23993023 int dof = 6; /// data.length/numframes;
24003024
2401
- // july 2014
2402
- if (dof != data.length/numframes)
2403
- {
2404
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2405
- dof = data.length/numframes;
2406
- }
3025
+ // july 2014
3026
+ if (dof != data.length/numframes)
3027
+ {
3028
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
3029
+ dof = data.length/numframes;
3030
+ }
24073031
24083032
24093033 int theframe = 0; // baseframe;
....@@ -2455,17 +3079,26 @@
24553079 // }
24563080 // }
24573081
2458
- data[f3 + i] += pos[i] - data[frame3 + i];
3082
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24593083
24603084 // if (f < 3)
24613085 // {
24623086 // System.out.print(data[f3 + i] + " ");
24633087 // }
24643088 }
2465
-// if (f < 3)
2466
-// {
2467
-// System.out.println();
2468
-// }
3089
+
3090
+ double t1 = data[f3 + 0];
3091
+ double t2 = data[f3 + 2];
3092
+
3093
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
3094
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
3095
+
3096
+ for (int i=3/*dof*/; --i>=0;)
3097
+ {
3098
+ data[f3 + i] += pos[i];
3099
+ }
3100
+
3101
+ data[f3 + 4] += angleY - data[frame3 + 4];
24693102 }
24703103 }
24713104
....@@ -2479,186 +3112,17 @@
24793112 // temp.y = data[1];
24803113 // temp.z = data[2];
24813114
2482
- if (fade && currentbones != null && !CameraPane.fullreset)
2483
- {
2484
- Quat4d quatstart = new Quat4d();
2485
- Quat4d quatend = new Quat4d();
2486
- Quat4d quat = new Quat4d();
2487
- Matrix4d mat4d = new Matrix4d();
2488
- double[][] rot = new double[4][4];
2489
-
2490
- for (b=numbones; --b>=1;) // HIP ROTATION: 0;)
2491
- {
2492
- int hipindex = get(0)._index;
2493
-
2494
-// assert(get(0).get(0)._isHip);
2495
-
2496
- // if (b == hipindex)
2497
- // continue;
2498
-
2499
- data = bvh.animation.getBoneData(b);
2500
-
2501
- int dof = 3; // data.length/numframes;
2502
-
2503
- // assert(dof == 3);
2504
-
2505
- int boneframe3 = b*3; // dof;
2506
-
2507
- // System.err.println("Bone #" + b + ": dof = " + dof);
2508
- int fadein = 45; // 120;
2509
-
2510
- // if (b == hipindex)
2511
- // fadein *= 5;
2512
-
2513
- if (fadein > numframes)
2514
- fadein = 0; // numframes;
2515
-
2516
- for (int fi=fadein; --fi>=0;)
2517
- //for (int f=numframes; --f>=0;)
2518
- {
2519
- int f = fi + GetFirstFrame();
2520
-
2521
- int f3 = f*dof;
2522
-
2523
- float k = fi;
2524
-
2525
- k /= fadein - 1;
2526
-
2527
- if (Float.isNaN(k))
2528
- k = 1; // 0/0
2529
-
2530
- k = (float) (-Math.cos(k*Math.PI));
2531
- k += 1;
2532
- k /= 2;
2533
-
2534
- int start = 3;
2535
- int end = 0;
2536
-
2537
- if (dof == 6)
2538
- {
2539
- start = 6;
2540
- end = 3;
2541
- }
2542
-
2543
- if (b == 0)
2544
- {
2545
- _t1.setIdentity();
2546
- _t2.setIdentity();
2547
- _t2.rotZ(currentbones[boneframe3 + start-1-end]);
2548
- _t1.mul(_t2);
2549
- _t2.setIdentity();
2550
- if (b == 0)
2551
- {
2552
- _t2.rotY(currentbones[boneframe3 + start-2-end]);
2553
- _t1.mul(_t2);
2554
- _t2.setIdentity();
2555
- _t2.rotX(currentbones[boneframe3 + start-3-end]);
2556
- }
2557
- else
2558
- {
2559
- _t2.rotX(currentbones[boneframe3 + start-2-end]);
2560
- _t1.mul(_t2);
2561
- _t2.setIdentity();
2562
- _t2.rotY(currentbones[boneframe3 + start-3-end]);
2563
- }
2564
- _t1.mul(_t2);
2565
- _t2.setIdentity();
2566
-
2567
- _t1.get(mat4d);
2568
-
2569
- mat4d.get(quatstart);
2570
-
2571
- _t1.setIdentity();
2572
- _t2.setIdentity();
2573
- _t2.rotZ(data[f3 + start-1]);
2574
- _t1.mul(_t2);
2575
- _t2.setIdentity();
2576
- if (b == 0)
2577
- {
2578
- _t2.rotY(data[f3 + start-2]);
2579
- _t1.mul(_t2);
2580
- _t2.setIdentity();
2581
- _t2.rotX(data[f3 + start-3]);
2582
- }
2583
- else
2584
- {
2585
- _t2.rotX(data[f3 + start-2]);
2586
- _t1.mul(_t2);
2587
- _t2.setIdentity();
2588
- _t2.rotY(data[f3 + start-3]);
2589
- }
2590
-
2591
- _t1.mul(_t2);
2592
- _t2.setIdentity();
2593
-
2594
- _t1.get(mat4d);
2595
-
2596
- mat4d.get(quatend);
2597
-
2598
- double dot = quatstart.x*quatend.x +
2599
- quatstart.y*quatend.y +
2600
- quatstart.z*quatend.z +
2601
- quatstart.w*quatend.w
2602
- ;
2603
-
2604
- if (dot < 0)
2605
- {
2606
- quatend.x *= -1;
2607
- quatend.y *= -1;
2608
- quatend.z *= -1;
2609
- quatend.w *= -1;
2610
- }
2611
-
2612
- // k = 1-k;
2613
-
2614
- quat.x = (1-k)*quatstart.x + k*quatend.x;
2615
- quat.y = (1-k)*quatstart.y + k*quatend.y;
2616
- quat.z = (1-k)*quatstart.z + k*quatend.z;
2617
- quat.w = (1-k)*quatstart.w + k*quatend.w;
2618
-
2619
- quat.normalize();
2620
-
2621
- mat4d.set(quat);
2622
-
2623
- cJ3D.SetTransform(rot, mat4d);
2624
-
2625
- matrixToEulerXYZ(rot, temp);
2626
-
2627
- data[f3 + start-1] = -(float)temp.z;
2628
-
2629
- if (b == 0)
2630
- {
2631
- data[f3 + start-2] = -(float)temp.y;
2632
- data[f3 + start-3] = -(float)temp.x;
2633
- }
2634
- else
2635
- {
2636
- data[f3 + start-2] = -(float)temp.x;
2637
- data[f3 + start-3] = -(float)temp.y;
2638
- }
2639
- }
2640
- else
2641
- {
2642
- for (int i=start; --i>=end;)
2643
- {
2644
- //data[f3 + i] += pos[i] - data[frame3 + i];
2645
- // data[f3 + i] = k*data[f3+i] + (1-k)*
2646
- // currentbones[boneframe3 + i-end];
2647
- data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);
2648
- }
2649
- }
2650
-
2651
- }
2652
- }
2653
-
2654
- }
3115
+// if (fade && currentbones != null && !CameraPane.fullreset)
3116
+// {
3117
+// Fade();
3118
+// }
26553119 }
2656
-
3120
+
26573121 if (false) // doesn't change anything bone._isRoot)
26583122 {
26593123 // Reset orientation
26603124 _t2.setIdentity();
2661
-
3125
+
26623126 double tx = bone.toParent[3][0];
26633127 double ty = bone.toParent[3][1];
26643128 double tz = bone.toParent[3][2];
....@@ -2667,9 +3131,9 @@
26673131 temp.y = 0;
26683132 temp.z = 0;
26693133 LA.xformDir(temp, bone.toParent, temp);
2670
-
3134
+
26713135 double angle = Math.atan2(-temp.z, temp.x);
2672
-
3136
+
26733137 _t2.rotY(angle);
26743138 // _t1.setIdentity();
26753139 // _t1.rotX(temp.x);
....@@ -2682,56 +3146,21 @@
26823146 // _t1.setIdentity();
26833147 // _t1.rotZ(temp.z);
26843148 // _t2.mul(_t1);
2685
-
3149
+
26863150 cJ3D.ResetTransform(bone, _t2, false);
2687
-
3151
+
26883152 bone.toParent[3][0] = tx;
26893153 bone.toParent[3][1] = ty;
26903154 bone.toParent[3][2] = tz;
26913155 }
26923156 }
26933157
2694
- if (currentbones == null)
2695
- currentbones = new double[numbones*3];
2696
-
2697
- for (int b=numbones; --b>=1;) // 0;)
2698
- //int b = 0;
2699
- {
2700
- data = bvh.animation.getBoneData(b);
2701
-
2702
- int numframes = bvh.animation.getNumFrames();
2703
-
2704
- int dof = 6; // data.length/numframes;
2705
-
2706
- if (b > 0)
2707
- dof = 3;
2708
-
2709
- //assert(dof == 3);
2710
-
2711
- // System.err.println("Bone #" + b + ": dof = " + dof);
2712
- int theframe = // 1; // baseframe;
2713
- frame;
2714
-
2715
- int frame3 = theframe*dof;
2716
- int bone3 = b*3; // dof;
2717
-
2718
- int start = 3;
2719
- int end = 0;
2720
-
2721
- if (dof == 6)
2722
- {
2723
- start = 6;
2724
- end = 3;
2725
- }
2726
- for (int i=start; --i>=end;)
2727
- {
2728
- currentbones[bone3 + i-end] = data[frame3 + i];
2729
- }
2730
- }
3158
+ // SetCurrentBones(frame);
27313159 }
27323160 }
27333161
2734
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3162
+ // skip initial "T"
3163
+ static int offset = 1; // 5; // 10; // 5; // 100;
27353164
27363165 void ReadBVH()
27373166 {
....@@ -2760,14 +3189,14 @@
27603189
27613190 void Reset()
27623191 {
2763
- if (fullname != null)
2764
- ReadBVH();
3192
+// if (fullname != null)
3193
+// ReadBVH();
27653194
27663195 Object3D hip = get(0);
27673196
27683197 // assert(obj.name.equals("hip"));
27693198
2770
- Object3D rot = hip.get(0);
3199
+ //Object3D rot = hip.get(0);
27713200
27723201 // assert(obj.name == null); // .equals("hip#"));
27733202
....@@ -2777,8 +3206,8 @@
27773206 hip.fromParent = LA.newMatrix();
27783207 }
27793208
2780
- hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
2781
- hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
3209
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3210
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27823211
27833212 if (toParent == null)
27843213 {
....@@ -2790,26 +3219,29 @@
27903219 LA.matIdentity(fromParent);
27913220 // LA.matIdentity(hip.toParent);
27923221 // LA.matIdentity(hip.fromParent);
2793
- if (rot.toParent == null)
2794
- {
2795
- // june 2014
2796
- rot.toParent = LA.newMatrix();
2797
- rot.fromParent = LA.newMatrix();
2798
- }
2799
- LA.matIdentity(rot.toParent);
2800
- LA.matIdentity(rot.fromParent);
3222
+// if (rot.toParent == null)
3223
+// {
3224
+// // june 2014
3225
+// rot.toParent = LA.newMatrix();
3226
+// rot.fromParent = LA.newMatrix();
3227
+// }
3228
+// LA.matIdentity(rot.toParent);
3229
+// LA.matIdentity(rot.fromParent);
28013230
28023231 // july 2014
2803
- goalx = goalz = 0;
2804
- targetx = targetz = 0;
3232
+// goalx = goalz = 0;
3233
+ targetdirx = targetdirz = 0;
28053234
2806
- SetPositionDelta(true, true, true, false);
3235
+ //SetPositionDelta(true, true, true, false);
3236
+// LoadData();
3237
+// Rewind();
28073238
28083239 baseframe = frame = 0; // T pose. No offset.
28093240
28103241 // aout 2013 endframe = 0; // june 2013
28113242
2812
- setPose(frame);
3243
+ ResetZero();
3244
+ //setPose(frame);
28133245 }
28143246
28153247 static int mocapsupport = 0;
....@@ -2827,12 +3259,13 @@
28273259
28283260 int step = 1;
28293261
3262
+ // patch for running hare
28303263 if (speedup) // fev 2014
28313264 step *= 2; // 4;
28323265 if (rewind) // mars 2014
28333266 step *= 4;
28343267
2835
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3268
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
28363269 step *= CameraPane.STEP;
28373270
28383271 //System.err.println("Step Mocap frame # " + frame);
....@@ -2840,7 +3273,7 @@
28403273 baseframe += step;
28413274
28423275 //frame = baseframe;
2843
- frame += step;
3276
+ //frame += step;
28443277
28453278 // if (frame != baseframe)
28463279 // {
....@@ -2854,6 +3287,7 @@
28543287 if (lastframetest == 0)
28553288 lastframetest = bvh.animation.getNumFrames();
28563289
3290
+ // WARNING: RESET DESTROYS EVERYTHING
28573291 if (baseframe >= lastframetest) // july 2013 // - GetFirstFrame())
28583292 {
28593293 System.out.println("MOCAP reset: " + this.GetFileRoot() +
....@@ -2863,7 +3297,7 @@
28633297 "; fullname = " + fullname);
28643298
28653299 //int delta = frame - baseframe;
2866
- if (CameraPane.CROWD)
3300
+ if (Globals.CROWD)
28673301 {
28683302 baseframe = GetFirstFrame(); // 0 initial point
28693303 }
....@@ -2872,29 +3306,53 @@
28723306 // SetPositionDelta(false, true, false); // ?? false);
28733307 {
28743308 if (support == null)
2875
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
2876
- else
28773309 {
2878
- try
3310
+ if (bvh == null && new File(fullname).exists())
3311
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3312
+ else
28793313 {
2880
- bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
2881
-
2882
- SetPositionDelta(false, true, true, true);
2883
- }
2884
- catch (Exception e)
2885
- {
2886
- e.printStackTrace();
2887
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3314
+ SetGlobalTransform();
3315
+ Rewind();
3316
+ Fade();
28883317 }
28893318 }
3319
+ else
3320
+ {
3321
+// try
3322
+// {
3323
+ bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
3324
+
3325
+ // SetPositionDelta(false, true, true, true);
3326
+ LoadData();
3327
+ Rewind();
3328
+ Fade();
3329
+// }
3330
+// catch (Exception e)
3331
+// {
3332
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3333
+// //e.printStackTrace();
3334
+// try
3335
+// {
3336
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3337
+// }
3338
+// catch (Exception e2)
3339
+// {
3340
+// System.err.println("Motion file not found: " + fullname);
3341
+// }
3342
+// }
3343
+ }
28903344 }
3345
+
3346
+ frame = GetFirstFrame();
28913347 }
3348
+ else
3349
+ frame += step;
28923350
28933351 //SetPositionDelta(false);
28943352
2895
- if (frame >= bvh.animation.getNumFrames())
2896
- //baseframe =
2897
- frame = GetFirstFrame(); // 0; // offset; // initial point
3353
+// if (frame >= bvh.animation.getNumFrames())
3354
+// //baseframe =
3355
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28983356
28993357 //System.err.println("frame = " + frame);
29003358 if (lastframe != 0)
....@@ -3063,6 +3521,7 @@
30633521 // filters out bad input data
30643522 void FilterAnimData()
30653523 {
3524
+ new Exception().printStackTrace();
30663525 System.exit(0);
30673526
30683527 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3192,6 +3651,8 @@
31923651 //static
31933652 transient
31943653 double[] currentbones;
3654
+ double[] currenthip;
3655
+
31953656 transient boolean inbetween;
31963657
31973658 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3202,38 +3663,9 @@
32023663 //assert(dim == numframes*6);
32033664
32043665 if (load)
3205
- for (int b=numbones; --b>=0;)
3206
- //int b = 0;
3207
- {
3208
- float[] thedata = bvh.animation.getBoneData(b);
3209
-
3210
- int numframes = bvh.animation.getNumFrames();
3211
-
3212
- int dof = 6; // thedata.length/numframes;
3213
-
3214
- if (b > 0)
3215
- dof = 3;
3216
-
3217
- if (dof != thedata.length/numframes)
3218
- {
3219
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3220
- dof = thedata.length/numframes;
3221
- }
3222
-
3223
- //for (int f=numframes; --f>=offset;)
3224
- int firstframe = GetFirstFrame();
3225
- for (int f=0; f<numframes-firstframe; f++)
3226
- {
3227
- int f3 = f*dof;
3228
-
3229
- //for (int i=3/*dof*/; --i>=0;)
3230
- for (int i=dof; --i>=0;)
3231
- {
3232
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3233
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3234
- }
3235
- }
3236
- }
3666
+ {
3667
+ LoadData();
3668
+ }
32373669
32383670 // assert(thedata[0] == 0);
32393671 // assert(thedata[1] == 0);
....@@ -3243,11 +3675,11 @@
32433675 // assert(thedata[7] == 0);
32443676 // assert(thedata[8] == 0);
32453677
3246
- Object3D obj = get(0);
3678
+ Object3D hip = get(0);
32473679
32483680 // assert(obj.name.equals("hip"));
32493681
3250
- Object3D rot = obj.get(0);
3682
+ Object3D rot = hip.get(0);
32513683
32523684 // if (toParent == null)
32533685 // {
....@@ -3259,7 +3691,7 @@
32593691 // // assert(obj.name == null); // .equals("hip#"));
32603692
32613693 Invariants();
3262
- obj.Invariants();
3694
+ hip.Invariants();
32633695 rot.Invariants();
32643696
32653697 if (origin == null)
....@@ -3280,16 +3712,16 @@
32803712 fromParent = LA.newMatrix();
32813713 }
32823714
3283
- if (obj.toParent == null) // june 2014
3715
+ if (hip.toParent == null) // june 2014
32843716 {
3285
- obj.toParent = LA.newMatrix();
3286
- obj.fromParent = LA.newMatrix();
3717
+ hip.toParent = LA.newMatrix();
3718
+ hip.fromParent = LA.newMatrix();
32873719 }
32883720
3289
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3721
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32903722 Object3D gp = this.parent;
32913723 this.parent = null;
3292
- obj.GlobalTransformInv();
3724
+ hip.GlobalTransformInv();
32933725 this.parent = gp;
32943726
32953727 if (rot.toParent == null)
....@@ -3312,41 +3744,41 @@
33123744 LA.matInvert(origin.toParent, origin.fromParent);
33133745
33143746 Invariants();
3315
- obj.Invariants();
3747
+ hip.Invariants();
33163748 rot.Invariants();
33173749 origin.Invariants();
33183750 origin0.Invariants();
33193751
3320
- firsttimeafterload = true;
3752
+ firsttimeafterload = false; // true;
33213753
33223754 if (rewind)
33233755 Rewind();
33243756
3325
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3757
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33263758
3327
- if (true)
3328
- return;
3759
+ if (true)
3760
+ return;
33293761
33303762 double pos[] = new double[6];
33313763
33323764 if (!reset)
33333765 {
3334
- assert(obj.tx == obj.toParent[3][0]);
3335
- assert(obj.ty == obj.toParent[3][1]);
3336
- assert(obj.tz == obj.toParent[3][2]);
3766
+ assert(hip.tx == hip.toParent[3][0]);
3767
+ assert(hip.ty == hip.toParent[3][1]);
3768
+ assert(hip.tz == hip.toParent[3][2]);
33373769
3338
- pos[0] = obj.tx; // obj.toParent[3][0];
3339
- pos[1] = obj.ty; // obj.toParent[3][1];
3340
- pos[2] = obj.tz; // obj.toParent[3][2];
3341
- pos[3] = obj.rz;
3342
- pos[4] = obj.ry;
3343
- pos[5] = obj.rx;
3770
+ pos[0] = hip.tx; // obj.toParent[3][0];
3771
+ pos[1] = hip.ty; // obj.toParent[3][1];
3772
+ pos[2] = hip.tz; // obj.toParent[3][2];
3773
+ pos[3] = hip.rz;
3774
+ pos[4] = hip.ry;
3775
+ pos[5] = hip.rx;
33443776 }
33453777
33463778 cVector temp = new cVector();
3347
- temp.x = obj.globalTransform[3][0];
3348
- temp.y = obj.globalTransform[3][1];
3349
- temp.z = obj.globalTransform[3][2];
3779
+ temp.x = hip.globalTransform[3][0];
3780
+ temp.y = hip.globalTransform[3][1];
3781
+ temp.z = hip.globalTransform[3][2];
33503782 // LA.xformPos(temp, origin0.toParent, temp);
33513783 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33523784
....@@ -3430,7 +3862,7 @@
34303862 }
34313863
34323864 // Rewind();
3433
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3865
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34343866 }
34353867
34363868 void Rewind()
....@@ -3447,7 +3879,7 @@
34473879
34483880 transient boolean restarted; // CROWD issue?
34493881
3450
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3882
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
34513883 {
34523884 //System.err.println("drawSelf Mocap frame # " + frame);
34533885 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3464,17 +3896,22 @@
34643896 // if (firstframe)
34653897 // return;
34663898
3467
- if (!restarted && /*display.restartframe &&*/
3468
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3899
+ if (//!restarted && /*display.restartframe &&*/
3900
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW))
34693901 {
34703902 //display.restartframe = false;
34713903 restarted = true;
3904
+ //System.err.println("restarted = true");
34723905 Step();
34733906 }
34743907 else
34753908 {
3476
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3909
+ //System.err.println("restarted");
3910
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3911
+ {
34773912 restarted = false;
3913
+ //System.err.println("restarted = false");
3914
+ }
34783915 }
34793916
34803917 super.drawSelf(display, root, selected, blocked);