Normand Briere
2019-06-16 372b7fd481a476cd659713a4a01bf28bf6760cbe
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 {
....@@ -76,6 +644,24 @@
76644 // transient // aout 2013
77645 Object3D skeleton;
78646
647
+ void ExtractBigData(Object3D o)
648
+ {
649
+ super.ExtractBigData(o);
650
+
651
+ o.bvh = this.bvh;
652
+ o.skeleton = this.skeleton;
653
+ this.bvh = null;
654
+ this.skeleton = null;
655
+ }
656
+
657
+ void RestoreBigData(Object3D o)
658
+ {
659
+ super.RestoreBigData(o);
660
+
661
+ this.bvh = o.bvh;
662
+ this.skeleton = o.skeleton;
663
+ }
664
+
79665 boolean smoothed;
80666
81667 //boolean touched;
....@@ -99,11 +685,11 @@
99685 double pinx;
100686 double pinz;
101687
102
- double targetx;
103
- double targetz;
688
+ double targetdirx;
689
+ double targetdirz;
104690
105
- double goalx;
106
- double goalz;
691
+ double goalposx = 0; // -20;
692
+ double goalposz = 0; // -10;
107693
108694 boolean followpath;
109695
....@@ -174,7 +760,7 @@
174760 scriptactions.clear();
175761 }
176762
177
- static double EPSACTION = 0.1; // 0.075; // 0.1;
763
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
178764
179765 void AddFromTo(cVector from, cVector to)
180766 {
....@@ -359,7 +945,7 @@
359945 // //GetFileRoot();
360946
361947 // sept 2014: //
362
- GraphreeD.RENDERME = 3; // patch for Merge objects
948
+ Grafreed.RENDERME = 3; // patch for Merge objects
363949 float[] thedata = bvh.animation.getBoneData(0);
364950
365951 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -460,6 +1046,8 @@
4601046 testvect.set(from);
4611047 testvect.sub(fromto.from);
4621048
1049
+ testvect.y = 0; // PATCH
1050
+
4631051 int factor = 1;
4641052
4651053 //if (CameraPane.FAST)
....@@ -501,6 +1089,8 @@
5011089
5021090 testvect.set(from);
5031091 testvect.sub(fromto.from);
1092
+
1093
+ testvect.y = 0; // PATCH
5041094
5051095 int factor = 1;
5061096
....@@ -705,7 +1295,7 @@
7051295 // skip first node: translation
7061296 // Object3D b = input.get(0);
7071297
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1298
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091299 }
7101300
7111301 //mocap.figure.Bone[] children = b.getChildren();
....@@ -736,6 +1326,7 @@
7361326
7371327 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
7381328 {
1329
+ assert(false);
7391330 //assert(CameraPane.drawMode == CameraPane.SHADOW);
7401331
7411332 Object3D transformnode = new Object3D();
....@@ -754,7 +1345,7 @@
7541345 //long
7551346 // june 2014 floorid = sourcenode.getFloor(floor); // , sourcenode.parent);
7561347
757
- CameraPane.debugpoints[0].name = "Floor = " + floorid;
1348
+ CameraPane.debugpoints[0].name = ""; // "Floor = " + 0; // floorid;
7581349 CameraPane.debugpoints[0].toParent[3][0] = floor.x;
7591350 CameraPane.debugpoints[0].toParent[3][1] = floor.y;
7601351 CameraPane.debugpoints[0].toParent[3][2] = floor.z;
....@@ -770,7 +1361,7 @@
7701361
7711362 this.count--; // currently drawing itself
7721363
773
- CameraPane.debugpoints[7].name = "Centroid = " + groundid; // centroid;
1364
+ CameraPane.debugpoints[7].name = ""; // Centroid = " + 0; // groundid; // centroid;
7741365 CameraPane.debugpoints[7].toParent[3][0] = centroid.x;
7751366 CameraPane.debugpoints[7].toParent[3][1] = centroid.y;
7761367 CameraPane.debugpoints[7].toParent[3][2] = centroid.z;
....@@ -795,7 +1386,7 @@
7951386
7961387 // jan 2014 sourcenode.parent.TransformToWorld(tmp);
7971388
798
- CameraPane.debugpoints[1].name = "C+";
1389
+ CameraPane.debugpoints[1].name = ""; // "C+";
7991390 CameraPane.debugpoints[1].toParent[3][0] = tmp.x;
8001391 CameraPane.debugpoints[1].toParent[3][1] = tmp.y;
8011392 CameraPane.debugpoints[1].toParent[3][2] = tmp.z;
....@@ -814,7 +1405,7 @@
8141405 tmp.z = pinz;
8151406 }
8161407
817
- CameraPane.debugpoints[2].name = "Pin";
1408
+ CameraPane.debugpoints[2].name = ""; // "Pin";
8181409 CameraPane.debugpoints[2].toParent[3][0] = tmp.x;
8191410 CameraPane.debugpoints[2].toParent[3][1] = tmp.y;
8201411 CameraPane.debugpoints[2].toParent[3][2] = tmp.z;
....@@ -822,7 +1413,7 @@
8221413 //if (sourcenode.parent.parent != null)
8231414 // jan 2014 sourcenode.parent.TransformToLocal(tmp); //, tmp);
8241415
825
- CameraPane.debugpoints[3].name = "C-";
1416
+ CameraPane.debugpoints[3].name = ""; // "C-";
8261417 CameraPane.debugpoints[3].toParent[3][0] = tmp.x;
8271418 CameraPane.debugpoints[3].toParent[3][1] = tmp.y;
8281419 CameraPane.debugpoints[3].toParent[3][2] = tmp.z;
....@@ -895,14 +1486,14 @@
8951486 // if (sourcenode.parent.parent != null)
8961487 // sourcenode.parent.parent.TransformToWorld(floor); //, floor);
8971488
898
- CameraPane.debugpoints[5].name = "F++";
1489
+ CameraPane.debugpoints[5].name = ""; // "F++";
8991490 CameraPane.debugpoints[5].toParent[3][0] = floor.x;
9001491 CameraPane.debugpoints[5].toParent[3][1] = floor.y;
9011492 CameraPane.debugpoints[5].toParent[3][2] = floor.z;
9021493
9031494 floor.y = tempg;
9041495
905
- CameraPane.debugpoints[6].name = "F+-";
1496
+ CameraPane.debugpoints[6].name = ""; // "F+-";
9061497 CameraPane.debugpoints[6].toParent[3][0] = floor.x;
9071498 CameraPane.debugpoints[6].toParent[3][1] = floor.y;
9081499 CameraPane.debugpoints[6].toParent[3][2] = floor.z;
....@@ -921,7 +1512,7 @@
9211512 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221513 }
9231514
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1515
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251516
9261517 if (footcontact && ground != -123456)
9271518 {
....@@ -938,9 +1529,10 @@
9381529
9391530 groundid = floorid;
9401531
941
- CameraPane.debugpoint.toParent[3][0] = groundx;
942
- CameraPane.debugpoint.toParent[3][1] = floor.y;
943
- CameraPane.debugpoint.toParent[3][2] = groundz;
1532
+ // green
1533
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1534
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1535
+ CameraPane.debugpointG.toParent[3][2] = groundz;
9441536
9451537 if (true) // slow && stepout && onein)
9461538 {
....@@ -951,7 +1543,7 @@
9511543 // mywave = currentwave++;
9521544 // }
9531545 // sound
954
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1546
+ cVector eye = Globals.theRenderer.EyeCamera().location;
9551547
9561548 // if (sourcenode.parent.parent != null)
9571549 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -996,9 +1588,9 @@
9961588 //GraphreeD.
9971589 wav.play(volume * usedvolume); //, mywave);
9981590
999
- lastsoundtime = CameraPane.framecount;
1591
+ lastsoundtime = Globals.framecount;
10001592
1001
- GraphreeD.hassound = true;
1593
+ Grafreed.hassound = true;
10021594 }
10031595 // else
10041596 // System.out.println("skipped");
....@@ -1016,9 +1608,10 @@
10161608 // floor.z += posz;
10171609
10181610 // System.out.println("Allo " + sourcenode);
1019
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1020
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1021
- CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
1611
+ // purple
1612
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1613
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1614
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
10221615
10231616
10241617 if (false) // dist2 > 0.1)
....@@ -1052,7 +1645,7 @@
10521645 v0.z = groundz - floor.z;
10531646
10541647 double distance = Math.sqrt(v0.dot(v0));
1055
- double maxdist = 0.004;
1648
+ double maxdist = 0.04;
10561649
10571650 if (distance > maxdist)
10581651 {
....@@ -1078,8 +1671,27 @@
10781671 sourcenode.toParent = LA.newMatrix();
10791672 sourcenode.fromParent = LA.newMatrix();
10801673 }
1674
+
1675
+ v0.x = v0.z = 0;
1676
+
1677
+ this.get(0).TransformToWorld(v0);
1678
+
1679
+ // cyan
1680
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1681
+ CameraPane.debugpointC.toParent[3][1] = ground;
1682
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
1683
+
10811684 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10821685 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
1686
+
1687
+ v0.x = v0.z = 0;
1688
+
1689
+ this.get(0).TransformToWorld(v0);
1690
+
1691
+ // red
1692
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1693
+ CameraPane.debugpointR.toParent[3][1] = ground;
1694
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
10831695 }
10841696 }
10851697
....@@ -1119,11 +1731,11 @@
11191731
11201732 if (goal != null)
11211733 {
1122
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1734
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11231735 //sourcenode.parent.parent.Dump();
1124
- goalx = goal.x;
1125
- goalz = goal.z;
1126
- targetx = targetz = 0;
1736
+ goalposx = goal.x;
1737
+ goalposz = goal.z;
1738
+ targetdirx = targetdirz = 0;
11271739
11281740 followpath = true;
11291741 }
....@@ -1174,16 +1786,16 @@
11741786 // }
11751787 if (false) // !uselast)
11761788 {
1177
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1178
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1179
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1789
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1790
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1791
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
11801792 }
11811793 }
11821794
1183
- if (goalx != 0 || goalz != 0) // TODO
1795
+ if (goalposx != 0 || goalposz != 0) // TODO
11841796 {
11851797 // overwrite speaker orientation
1186
- dst.set(goalx,0,goalz);
1798
+ dst.set(goalposx,0,goalposz);
11871799 if (sourcenode.parent != null) // july 2014
11881800 sourcenode.parent.
11891801 TransformToLocal(dst);
....@@ -1199,6 +1811,7 @@
11991811 src.x = 0;
12001812 src.y = 0;
12011813 src.z = 0;
1814
+ LA.xformPos(src, get(0).get(0).toParent, src);
12021815 LA.xformPos(src, get(0).toParent, src);
12031816 LA.xformPos(src, toParent, src);
12041817 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1234,26 +1847,26 @@
12341847 // mars 2014
12351848 if (false) // goalx != 0 || goalz != 0)
12361849 {
1237
- targetx = dst.x - src.x;
1238
- targetz = dst.z - src.z;
1850
+ targetdirx = dst.x - src.x;
1851
+ targetdirz = dst.z - src.z;
12391852
1240
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1853
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12411854 {
12421855 // far enough from goal. keep the goal position.
1243
- targetx = 0;
1244
- targetz = 0;
1856
+ targetdirx = 0;
1857
+ targetdirz = 0;
12451858 }
12461859 else
12471860 {
12481861 // too close to goal. switch to target direction instead.
1249
- goalx = 0;
1250
- goalz = 0;
1862
+ goalposx = 0;
1863
+ goalposz = 0;
12511864 }
12521865 }
12531866
12541867 //sourcenode.getCentroid(src, true);
12551868
1256
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1869
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12571870 {
12581871 if (ScriptNode.lastspeaker != null)
12591872 new Exception().printStackTrace();
....@@ -1262,13 +1875,13 @@
12621875
12631876 // LA.xformPos(src, fromParent, src);
12641877
1265
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1878
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
12661879 dst.sub(src);
12671880 else
12681881 // vector mode
12691882 {
1270
- dst.x = targetx;
1271
- dst.z = targetz;
1883
+ dst.x = targetdirx;
1884
+ dst.z = targetdirz;
12721885
12731886 // TEST TARGET
12741887 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1318,7 +1931,7 @@
13181931
13191932 rotsourcenode.TransformToWorld(test);
13201933
1321
- CameraPane.debugpoints[4].name = "ROT = "; // + test;
1934
+ CameraPane.debugpoints[4].name = ""; // "ROT = "; // + test;
13221935 CameraPane.debugpoints[4].toParent[3][0] = test.x;
13231936 CameraPane.debugpoints[4].toParent[3][1] = test.y;
13241937 CameraPane.debugpoints[4].toParent[3][2] = test.z;
....@@ -1542,6 +2155,7 @@
15422155 toParent = LA.newMatrix();
15432156 fromParent = LA.newMatrix();
15442157 }
2158
+
15452159 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15462160 LA.matInvert(toParent, fromParent);
15472161
....@@ -1677,7 +2291,7 @@
16772291 }
16782292
16792293 if (!smoothed)
1680
- for (int i=4; --i>=0;)
2294
+ for (int i=10; --i>=0;)
16812295 SmoothAnimData(); // much reduces shakiness
16822296
16832297 smoothed = true;
....@@ -1715,9 +2329,16 @@
17152329 toVector.x = LA.cos(to);
17162330 toVector.y = LA.sin(to);
17172331
2332
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2333
+ double toA = Math.atan2(toVector.y, toVector.x);
2334
+
17182335 Vector2d currentVector = Slerp(fromVector, toVector, step);
17192336
1720
- return Math.atan2(currentVector.y, currentVector.x);
2337
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2338
+
2339
+ double angle2 = (1-step) * fromA + step * toA;
2340
+
2341
+ return angle;
17212342 }
17222343
17232344 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1759,12 +2380,28 @@
17592380 if (!live) // aout 2013
17602381 return;
17612382
1762
- cVector centroid = new cVector();
1763
- cVector floor = new cVector();
1764
-
1765
- Object3D sourcenode = GetFileRoot();
2383
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2384
+ try
2385
+ {
2386
+ SetPose(GetSkeleton(), bvh.animation, f);
2387
+ SetCurrentBones(frame);
2388
+ }
2389
+ catch (Exception e)
2390
+ {
2391
+ e.printStackTrace();
2392
+ }
17662393
1767
- boolean success; // = sourcenode.getCentroid(centroid);
2394
+ SetHipOrientation();
2395
+
2396
+ if (true)
2397
+ return;
2398
+
2399
+ cVector centroid = new cVector();
2400
+ cVector floor = new cVector();
2401
+
2402
+ Object3D sourcenode = GetFileRoot();
2403
+
2404
+ boolean success; // = sourcenode.getCentroid(centroid);
17682405 // if (!success)
17692406 // {
17702407 // //assert(success);
....@@ -1772,16 +2409,6 @@
17722409 // System.out.println("No centroid for " + sourcenode);
17732410 // }
17742411
1775
- //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
1776
- try
1777
- {
1778
- SetPose(GetSkeleton(), bvh.animation, f);
1779
- }
1780
- catch (Exception e)
1781
- {
1782
- e.printStackTrace();
1783
- }
1784
-
17852412 if (sourcenode.parent == null && sourcenode.fileparent == null)
17862413 {
17872414 // No GFD
....@@ -1835,7 +2462,7 @@
18352462 {
18362463 SetRotation(sourcenode, new cVector(floor), new cVector(centroid));
18372464 }
1838
-
2465
+
18392466 if (setposition)
18402467 {
18412468 if (floorobject != null)
....@@ -2029,7 +2656,7 @@
20292656 * @param frame
20302657 * Frame number
20312658 */
2032
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2659
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20332660 {
20342661 if (!live) // aout 2013
20352662 return;
....@@ -2037,6 +2664,33 @@
20372664 cVector temp = new cVector();
20382665 cVector temp0 = new cVector();
20392666 double pos[] = new double[3];
2667
+ double angleY = 0;
2668
+ double sinY = 0;
2669
+ double cosY = 0;
2670
+
2671
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2672
+ {
2673
+ bone.get(0).GlobalTransformInv();
2674
+
2675
+ temp.x = bone.get(0).globalTransform[3][0];
2676
+ temp.y = bone.get(0).globalTransform[3][1];
2677
+ temp.z = bone.get(0).globalTransform[3][2];
2678
+
2679
+ pos[0] = temp.x;
2680
+ pos[1] = temp.y;
2681
+ pos[2] = temp.z;
2682
+
2683
+ temp.x = 1;
2684
+ temp.y = 0;
2685
+ temp.z = 0;
2686
+
2687
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2688
+
2689
+ sinY = temp.z;
2690
+ cosY = temp.x;
2691
+
2692
+ angleY = Math.atan2(-sinY, cosY);
2693
+ }
20402694
20412695 // Object3D obj = get(0);
20422696 // Object3D gp = this.parent;
....@@ -2168,13 +2822,14 @@
21682822 if (//frame > 0 &&
21692823 !bone.skipmocap &&
21702824 !bone.name.contains("head") &&
2825
+ !bone.name.contains("Head") // &&
21712826 // !bone.name.contains("rFoot") &&
21722827 // !bone.name.contains("lFoot") &&
2173
- !bone.name.contains("Pinky") &&
2174
- !bone.name.contains("Ring") &&
2175
- !bone.name.contains("Mid") &&
2176
- !bone.name.contains("Index") &&
2177
- !bone.name.contains("Thumb")
2828
+// !bone.name.contains("Pinky") &&
2829
+// !bone.name.contains("Ring") &&
2830
+// !bone.name.contains("Mid") &&
2831
+// !bone.name.contains("Index") &&
2832
+// !bone.name.contains("Thumb")
21782833 )
21792834 {
21802835 //_rotTG.setTransform(_t1);
....@@ -2207,15 +2862,17 @@
22072862 // CROWD
22082863 //cJ3D.GetTranslation(bone, _trans0);
22092864 //_trans.add(_trans0);
2210
- _transTF.setIdentity();
2865
+ //_transTF.setIdentity();
2866
+ _transTF.set(_t1);
22112867 _transTF.setTranslation(_trans);
22122868 // System.err.println("Translate: " + _transTF);
22132869 //_transTG.setTransform(_transTF);
2214
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2870
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2871
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22152872 }
22162873 }
22172874
2218
- if (bone._isRoot && firsttimeafterload && frame > 0)
2875
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22192876 {
22202877 assert(bone == get(0));
22212878
....@@ -2231,17 +2888,17 @@
22312888 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22322889 //
22332890
2234
- Invariants();
2235
- bone.Invariants();
2236
- bone.get(0).Invariants();
2237
- // if (origin == null)
2238
- // origin = null;
2239
- origin.Invariants();
2240
- origin0.Invariants();
2891
+ Invariants();
2892
+ bone.Invariants();
2893
+ bone.get(0).Invariants();
2894
+ // if (origin == null)
2895
+ // origin = null;
2896
+ origin.Invariants();
2897
+ origin0.Invariants();
22412898
2242
-
2243
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2244
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2899
+
2900
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2901
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22452902
22462903 // matrixToEulerXYZ(toParent, temp);
22472904 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2275,7 +2932,7 @@
22752932 //
22762933 // mat4d.get(quat);
22772934
2278
- if (true) // hip correction
2935
+ if (false) // hip correction
22792936 {
22802937 _t2.setIdentity();
22812938
....@@ -2316,13 +2973,13 @@
23162973 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23172974 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23182975
2319
- LA.matInvert(toParent, fromParent);
2976
+//?? LA.matInvert(toParent, fromParent);
23202977
2321
- Invariants();
2322
- bone.Invariants();
2323
- bone.get(0).Invariants();
2324
- origin.Invariants();
2325
- origin0.Invariants();
2978
+ Invariants();
2979
+ bone.Invariants();
2980
+ bone.get(0).Invariants();
2981
+ origin.Invariants();
2982
+ origin0.Invariants();
23262983
23272984 // LA.matInvert(fromParent, tempmatrix);
23282985 //
....@@ -2343,33 +3000,39 @@
23433000 // temp.x = data[0];
23443001 // temp.y = data[1];
23453002 // temp.z = data[2];
2346
- LA.xformPos(temp, origin0.toParent, temp0);
3003
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23473004
2348
-// bone.GlobalTransformInv();
2349
-
2350
- temp0.x = bone.globalTransform[3][0];
2351
- temp0.y = bone.globalTransform[3][1];
2352
- temp0.z = bone.globalTransform[3][2];
2353
-
3005
+// bone.get(0).GlobalTransformInv();
3006
+//
3007
+// temp0.x = bone.get(0).globalTransform[3][0];
3008
+// temp0.y = bone.get(0).globalTransform[3][1];
3009
+// temp0.z = bone.get(0).globalTransform[3][2];
3010
+//
23543011 // MEGA TEST // june 2014: necessary for precision? otherwise comment works
2355
-fromParent[3][0] = 0;
2356
-fromParent[3][1] = 0;
2357
-fromParent[3][2] = 0;
2358
-LA.matInvert(fromParent, toParent);
3012
+//fromParent[3][0] = 0;
3013
+//fromParent[3][1] = 0;
3014
+//fromParent[3][2] = 0;
3015
+//LA.matInvert(fromParent, toParent);
23593016
2360
- LA.xformPos(temp0, fromParent, temp);
3017
+ LA.xformPos(temp0, fromParent, temp); // NU
23613018 //LA.xformPos(temp, bone.fromParent, temp);
23623019 // float[] data;
23633020
2364
- pos[0] = temp.x;
2365
- pos[1] = temp.y;
2366
- pos[2] = temp.z;
3021
+// pos[0] = temp.x;
3022
+// pos[1] = temp.y;
3023
+// pos[2] = temp.z;
3024
+//
3025
+// temp.x = 1;
3026
+// temp.y = 0;
3027
+// temp.z = 0;
3028
+//
3029
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23673030
23683031 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23693032 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23703033 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23713034
2372
- int numframes = bvh.animation.getNumFrames();
3035
+ int numframes = bvh.animation.getNumFrames();
23733036
23743037 int b = 0;
23753038 {
....@@ -2377,12 +3040,12 @@
23773040
23783041 int dof = 6; /// data.length/numframes;
23793042
2380
- // july 2014
2381
- if (dof != data.length/numframes)
2382
- {
2383
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2384
- dof = data.length/numframes;
2385
- }
3043
+ // july 2014
3044
+ if (dof != data.length/numframes)
3045
+ {
3046
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
3047
+ dof = data.length/numframes;
3048
+ }
23863049
23873050
23883051 int theframe = 0; // baseframe;
....@@ -2434,17 +3097,26 @@
24343097 // }
24353098 // }
24363099
2437
- data[f3 + i] += pos[i] - data[frame3 + i];
3100
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24383101
24393102 // if (f < 3)
24403103 // {
24413104 // System.out.print(data[f3 + i] + " ");
24423105 // }
24433106 }
2444
-// if (f < 3)
2445
-// {
2446
-// System.out.println();
2447
-// }
3107
+
3108
+ double t1 = data[f3 + 0];
3109
+ double t2 = data[f3 + 2];
3110
+
3111
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
3112
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
3113
+
3114
+ for (int i=3/*dof*/; --i>=0;)
3115
+ {
3116
+ data[f3 + i] += pos[i];
3117
+ }
3118
+
3119
+ data[f3 + 4] += angleY - data[frame3 + 4];
24483120 }
24493121 }
24503122
....@@ -2458,186 +3130,17 @@
24583130 // temp.y = data[1];
24593131 // temp.z = data[2];
24603132
2461
- if (fade && currentbones != null && !CameraPane.fullreset)
2462
- {
2463
- Quat4d quatstart = new Quat4d();
2464
- Quat4d quatend = new Quat4d();
2465
- Quat4d quat = new Quat4d();
2466
- Matrix4d mat4d = new Matrix4d();
2467
- double[][] rot = new double[4][4];
2468
-
2469
- for (b=numbones; --b>=1;) // HIP ROTATION: 0;)
2470
- {
2471
- int hipindex = get(0)._index;
2472
-
2473
-// assert(get(0).get(0)._isHip);
2474
-
2475
- // if (b == hipindex)
2476
- // continue;
2477
-
2478
- data = bvh.animation.getBoneData(b);
2479
-
2480
- int dof = 3; // data.length/numframes;
2481
-
2482
- // assert(dof == 3);
2483
-
2484
- int boneframe3 = b*3; // dof;
2485
-
2486
- // System.err.println("Bone #" + b + ": dof = " + dof);
2487
- int fadein = 45; // 120;
2488
-
2489
- // if (b == hipindex)
2490
- // fadein *= 5;
2491
-
2492
- if (fadein > numframes)
2493
- fadein = 0; // numframes;
2494
-
2495
- for (int fi=fadein; --fi>=0;)
2496
- //for (int f=numframes; --f>=0;)
2497
- {
2498
- int f = fi + GetFirstFrame();
2499
-
2500
- int f3 = f*dof;
2501
-
2502
- float k = fi;
2503
-
2504
- k /= fadein - 1;
2505
-
2506
- if (Float.isNaN(k))
2507
- k = 1; // 0/0
2508
-
2509
- k = (float) (-Math.cos(k*Math.PI));
2510
- k += 1;
2511
- k /= 2;
2512
-
2513
- int start = 3;
2514
- int end = 0;
2515
-
2516
- if (dof == 6)
2517
- {
2518
- start = 6;
2519
- end = 3;
2520
- }
2521
-
2522
- if (b == 0)
2523
- {
2524
- _t1.setIdentity();
2525
- _t2.setIdentity();
2526
- _t2.rotZ(currentbones[boneframe3 + start-1-end]);
2527
- _t1.mul(_t2);
2528
- _t2.setIdentity();
2529
- if (b == 0)
2530
- {
2531
- _t2.rotY(currentbones[boneframe3 + start-2-end]);
2532
- _t1.mul(_t2);
2533
- _t2.setIdentity();
2534
- _t2.rotX(currentbones[boneframe3 + start-3-end]);
2535
- }
2536
- else
2537
- {
2538
- _t2.rotX(currentbones[boneframe3 + start-2-end]);
2539
- _t1.mul(_t2);
2540
- _t2.setIdentity();
2541
- _t2.rotY(currentbones[boneframe3 + start-3-end]);
2542
- }
2543
- _t1.mul(_t2);
2544
- _t2.setIdentity();
2545
-
2546
- _t1.get(mat4d);
2547
-
2548
- mat4d.get(quatstart);
2549
-
2550
- _t1.setIdentity();
2551
- _t2.setIdentity();
2552
- _t2.rotZ(data[f3 + start-1]);
2553
- _t1.mul(_t2);
2554
- _t2.setIdentity();
2555
- if (b == 0)
2556
- {
2557
- _t2.rotY(data[f3 + start-2]);
2558
- _t1.mul(_t2);
2559
- _t2.setIdentity();
2560
- _t2.rotX(data[f3 + start-3]);
2561
- }
2562
- else
2563
- {
2564
- _t2.rotX(data[f3 + start-2]);
2565
- _t1.mul(_t2);
2566
- _t2.setIdentity();
2567
- _t2.rotY(data[f3 + start-3]);
2568
- }
2569
-
2570
- _t1.mul(_t2);
2571
- _t2.setIdentity();
2572
-
2573
- _t1.get(mat4d);
2574
-
2575
- mat4d.get(quatend);
2576
-
2577
- double dot = quatstart.x*quatend.x +
2578
- quatstart.y*quatend.y +
2579
- quatstart.z*quatend.z +
2580
- quatstart.w*quatend.w
2581
- ;
2582
-
2583
- if (dot < 0)
2584
- {
2585
- quatend.x *= -1;
2586
- quatend.y *= -1;
2587
- quatend.z *= -1;
2588
- quatend.w *= -1;
2589
- }
2590
-
2591
- // k = 1-k;
2592
-
2593
- quat.x = (1-k)*quatstart.x + k*quatend.x;
2594
- quat.y = (1-k)*quatstart.y + k*quatend.y;
2595
- quat.z = (1-k)*quatstart.z + k*quatend.z;
2596
- quat.w = (1-k)*quatstart.w + k*quatend.w;
2597
-
2598
- quat.normalize();
2599
-
2600
- mat4d.set(quat);
2601
-
2602
- cJ3D.SetTransform(rot, mat4d);
2603
-
2604
- matrixToEulerXYZ(rot, temp);
2605
-
2606
- data[f3 + start-1] = -(float)temp.z;
2607
-
2608
- if (b == 0)
2609
- {
2610
- data[f3 + start-2] = -(float)temp.y;
2611
- data[f3 + start-3] = -(float)temp.x;
2612
- }
2613
- else
2614
- {
2615
- data[f3 + start-2] = -(float)temp.x;
2616
- data[f3 + start-3] = -(float)temp.y;
2617
- }
2618
- }
2619
- else
2620
- {
2621
- for (int i=start; --i>=end;)
2622
- {
2623
- //data[f3 + i] += pos[i] - data[frame3 + i];
2624
- // data[f3 + i] = k*data[f3+i] + (1-k)*
2625
- // currentbones[boneframe3 + i-end];
2626
- data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);
2627
- }
2628
- }
2629
-
2630
- }
2631
- }
2632
-
2633
- }
3133
+// if (fade && currentbones != null && !CameraPane.fullreset)
3134
+// {
3135
+// Fade();
3136
+// }
26343137 }
2635
-
3138
+
26363139 if (false) // doesn't change anything bone._isRoot)
26373140 {
26383141 // Reset orientation
26393142 _t2.setIdentity();
2640
-
3143
+
26413144 double tx = bone.toParent[3][0];
26423145 double ty = bone.toParent[3][1];
26433146 double tz = bone.toParent[3][2];
....@@ -2646,9 +3149,9 @@
26463149 temp.y = 0;
26473150 temp.z = 0;
26483151 LA.xformDir(temp, bone.toParent, temp);
2649
-
3152
+
26503153 double angle = Math.atan2(-temp.z, temp.x);
2651
-
3154
+
26523155 _t2.rotY(angle);
26533156 // _t1.setIdentity();
26543157 // _t1.rotX(temp.x);
....@@ -2661,56 +3164,21 @@
26613164 // _t1.setIdentity();
26623165 // _t1.rotZ(temp.z);
26633166 // _t2.mul(_t1);
2664
-
3167
+
26653168 cJ3D.ResetTransform(bone, _t2, false);
2666
-
3169
+
26673170 bone.toParent[3][0] = tx;
26683171 bone.toParent[3][1] = ty;
26693172 bone.toParent[3][2] = tz;
26703173 }
26713174 }
26723175
2673
- if (currentbones == null)
2674
- currentbones = new double[numbones*3];
2675
-
2676
- for (int b=numbones; --b>=1;) // 0;)
2677
- //int b = 0;
2678
- {
2679
- data = bvh.animation.getBoneData(b);
2680
-
2681
- int numframes = bvh.animation.getNumFrames();
2682
-
2683
- int dof = 6; // data.length/numframes;
2684
-
2685
- if (b > 0)
2686
- dof = 3;
2687
-
2688
- //assert(dof == 3);
2689
-
2690
- // System.err.println("Bone #" + b + ": dof = " + dof);
2691
- int theframe = // 1; // baseframe;
2692
- frame;
2693
-
2694
- int frame3 = theframe*dof;
2695
- int bone3 = b*3; // dof;
2696
-
2697
- int start = 3;
2698
- int end = 0;
2699
-
2700
- if (dof == 6)
2701
- {
2702
- start = 6;
2703
- end = 3;
2704
- }
2705
- for (int i=start; --i>=end;)
2706
- {
2707
- currentbones[bone3 + i-end] = data[frame3 + i];
2708
- }
2709
- }
3176
+ // SetCurrentBones(frame);
27103177 }
27113178 }
27123179
2713
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3180
+ // skip initial "T"
3181
+ static int offset = 1; // 5; // 10; // 5; // 100;
27143182
27153183 void ReadBVH()
27163184 {
....@@ -2739,14 +3207,14 @@
27393207
27403208 void Reset()
27413209 {
2742
- if (fullname != null)
2743
- ReadBVH();
3210
+// if (fullname != null)
3211
+// ReadBVH();
27443212
27453213 Object3D hip = get(0);
27463214
27473215 // assert(obj.name.equals("hip"));
27483216
2749
- Object3D rot = hip.get(0);
3217
+ //Object3D rot = hip.get(0);
27503218
27513219 // assert(obj.name == null); // .equals("hip#"));
27523220
....@@ -2756,8 +3224,8 @@
27563224 hip.fromParent = LA.newMatrix();
27573225 }
27583226
2759
- hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
2760
- hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
3227
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3228
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27613229
27623230 if (toParent == null)
27633231 {
....@@ -2769,26 +3237,29 @@
27693237 LA.matIdentity(fromParent);
27703238 // LA.matIdentity(hip.toParent);
27713239 // LA.matIdentity(hip.fromParent);
2772
- if (rot.toParent == null)
2773
- {
2774
- // june 2014
2775
- rot.toParent = LA.newMatrix();
2776
- rot.fromParent = LA.newMatrix();
2777
- }
2778
- LA.matIdentity(rot.toParent);
2779
- LA.matIdentity(rot.fromParent);
3240
+// if (rot.toParent == null)
3241
+// {
3242
+// // june 2014
3243
+// rot.toParent = LA.newMatrix();
3244
+// rot.fromParent = LA.newMatrix();
3245
+// }
3246
+// LA.matIdentity(rot.toParent);
3247
+// LA.matIdentity(rot.fromParent);
27803248
27813249 // july 2014
2782
- goalx = goalz = 0;
2783
- targetx = targetz = 0;
3250
+// goalx = goalz = 0;
3251
+ targetdirx = targetdirz = 0;
27843252
2785
- SetPositionDelta(true, true, true, false);
3253
+ //SetPositionDelta(true, true, true, false);
3254
+// LoadData();
3255
+// Rewind();
27863256
27873257 baseframe = frame = 0; // T pose. No offset.
27883258
27893259 // aout 2013 endframe = 0; // june 2013
27903260
2791
- setPose(frame);
3261
+ ResetZero();
3262
+ //setPose(frame);
27923263 }
27933264
27943265 static int mocapsupport = 0;
....@@ -2806,12 +3277,13 @@
28063277
28073278 int step = 1;
28083279
3280
+ // patch for running hare
28093281 if (speedup) // fev 2014
28103282 step *= 2; // 4;
28113283 if (rewind) // mars 2014
28123284 step *= 4;
28133285
2814
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3286
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
28153287 step *= CameraPane.STEP;
28163288
28173289 //System.err.println("Step Mocap frame # " + frame);
....@@ -2819,7 +3291,7 @@
28193291 baseframe += step;
28203292
28213293 //frame = baseframe;
2822
- frame += step;
3294
+ //frame += step;
28233295
28243296 // if (frame != baseframe)
28253297 // {
....@@ -2833,6 +3305,7 @@
28333305 if (lastframetest == 0)
28343306 lastframetest = bvh.animation.getNumFrames();
28353307
3308
+ // WARNING: RESET DESTROYS EVERYTHING
28363309 if (baseframe >= lastframetest) // july 2013 // - GetFirstFrame())
28373310 {
28383311 System.out.println("MOCAP reset: " + this.GetFileRoot() +
....@@ -2842,7 +3315,7 @@
28423315 "; fullname = " + fullname);
28433316
28443317 //int delta = frame - baseframe;
2845
- if (CameraPane.CROWD)
3318
+ if (Globals.CROWD)
28463319 {
28473320 baseframe = GetFirstFrame(); // 0 initial point
28483321 }
....@@ -2851,29 +3324,53 @@
28513324 // SetPositionDelta(false, true, false); // ?? false);
28523325 {
28533326 if (support == null)
2854
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
2855
- else
28563327 {
2857
- try
3328
+ if (bvh == null && new File(fullname).exists())
3329
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3330
+ else
28583331 {
2859
- bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
2860
-
2861
- SetPositionDelta(false, true, true, true);
2862
- }
2863
- catch (Exception e)
2864
- {
2865
- e.printStackTrace();
2866
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3332
+ SetGlobalTransform();
3333
+ Rewind();
3334
+ Fade();
28673335 }
28683336 }
3337
+ else
3338
+ {
3339
+// try
3340
+// {
3341
+ bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
3342
+
3343
+ // SetPositionDelta(false, true, true, true);
3344
+ LoadData();
3345
+ Rewind();
3346
+ Fade();
3347
+// }
3348
+// catch (Exception e)
3349
+// {
3350
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3351
+// //e.printStackTrace();
3352
+// try
3353
+// {
3354
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3355
+// }
3356
+// catch (Exception e2)
3357
+// {
3358
+// System.err.println("Motion file not found: " + fullname);
3359
+// }
3360
+// }
3361
+ }
28693362 }
3363
+
3364
+ frame = GetFirstFrame();
28703365 }
3366
+ else
3367
+ frame += step;
28713368
28723369 //SetPositionDelta(false);
28733370
2874
- if (frame >= bvh.animation.getNumFrames())
2875
- //baseframe =
2876
- frame = GetFirstFrame(); // 0; // offset; // initial point
3371
+// if (frame >= bvh.animation.getNumFrames())
3372
+// //baseframe =
3373
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28773374
28783375 //System.err.println("frame = " + frame);
28793376 if (lastframe != 0)
....@@ -3042,6 +3539,7 @@
30423539 // filters out bad input data
30433540 void FilterAnimData()
30443541 {
3542
+ new Exception().printStackTrace();
30453543 System.exit(0);
30463544
30473545 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3171,6 +3669,8 @@
31713669 //static
31723670 transient
31733671 double[] currentbones;
3672
+ double[] currenthip;
3673
+
31743674 transient boolean inbetween;
31753675
31763676 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3181,38 +3681,9 @@
31813681 //assert(dim == numframes*6);
31823682
31833683 if (load)
3184
- for (int b=numbones; --b>=0;)
3185
- //int b = 0;
3186
- {
3187
- float[] thedata = bvh.animation.getBoneData(b);
3188
-
3189
- int numframes = bvh.animation.getNumFrames();
3190
-
3191
- int dof = 6; // thedata.length/numframes;
3192
-
3193
- if (b > 0)
3194
- dof = 3;
3195
-
3196
- if (dof != thedata.length/numframes)
3197
- {
3198
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3199
- dof = thedata.length/numframes;
3200
- }
3201
-
3202
- //for (int f=numframes; --f>=offset;)
3203
- int firstframe = GetFirstFrame();
3204
- for (int f=0; f<numframes-firstframe; f++)
3205
- {
3206
- int f3 = f*dof;
3207
-
3208
- //for (int i=3/*dof*/; --i>=0;)
3209
- for (int i=dof; --i>=0;)
3210
- {
3211
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3212
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3213
- }
3214
- }
3215
- }
3684
+ {
3685
+ LoadData();
3686
+ }
32163687
32173688 // assert(thedata[0] == 0);
32183689 // assert(thedata[1] == 0);
....@@ -3222,11 +3693,11 @@
32223693 // assert(thedata[7] == 0);
32233694 // assert(thedata[8] == 0);
32243695
3225
- Object3D obj = get(0);
3696
+ Object3D hip = get(0);
32263697
32273698 // assert(obj.name.equals("hip"));
32283699
3229
- Object3D rot = obj.get(0);
3700
+ Object3D rot = hip.get(0);
32303701
32313702 // if (toParent == null)
32323703 // {
....@@ -3238,7 +3709,7 @@
32383709 // // assert(obj.name == null); // .equals("hip#"));
32393710
32403711 Invariants();
3241
- obj.Invariants();
3712
+ hip.Invariants();
32423713 rot.Invariants();
32433714
32443715 if (origin == null)
....@@ -3259,16 +3730,16 @@
32593730 fromParent = LA.newMatrix();
32603731 }
32613732
3262
- if (obj.toParent == null) // june 2014
3733
+ if (hip.toParent == null) // june 2014
32633734 {
3264
- obj.toParent = LA.newMatrix();
3265
- obj.fromParent = LA.newMatrix();
3735
+ hip.toParent = LA.newMatrix();
3736
+ hip.fromParent = LA.newMatrix();
32663737 }
32673738
3268
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3739
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32693740 Object3D gp = this.parent;
32703741 this.parent = null;
3271
- obj.GlobalTransformInv();
3742
+ hip.GlobalTransformInv();
32723743 this.parent = gp;
32733744
32743745 if (rot.toParent == null)
....@@ -3291,41 +3762,41 @@
32913762 LA.matInvert(origin.toParent, origin.fromParent);
32923763
32933764 Invariants();
3294
- obj.Invariants();
3765
+ hip.Invariants();
32953766 rot.Invariants();
32963767 origin.Invariants();
32973768 origin0.Invariants();
32983769
3299
- firsttimeafterload = true;
3770
+ firsttimeafterload = false; // true;
33003771
33013772 if (rewind)
33023773 Rewind();
33033774
3304
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3775
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33053776
3306
- if (true)
3307
- return;
3777
+ if (true)
3778
+ return;
33083779
33093780 double pos[] = new double[6];
33103781
33113782 if (!reset)
33123783 {
3313
- assert(obj.tx == obj.toParent[3][0]);
3314
- assert(obj.ty == obj.toParent[3][1]);
3315
- assert(obj.tz == obj.toParent[3][2]);
3784
+ assert(hip.tx == hip.toParent[3][0]);
3785
+ assert(hip.ty == hip.toParent[3][1]);
3786
+ assert(hip.tz == hip.toParent[3][2]);
33163787
3317
- pos[0] = obj.tx; // obj.toParent[3][0];
3318
- pos[1] = obj.ty; // obj.toParent[3][1];
3319
- pos[2] = obj.tz; // obj.toParent[3][2];
3320
- pos[3] = obj.rz;
3321
- pos[4] = obj.ry;
3322
- pos[5] = obj.rx;
3788
+ pos[0] = hip.tx; // obj.toParent[3][0];
3789
+ pos[1] = hip.ty; // obj.toParent[3][1];
3790
+ pos[2] = hip.tz; // obj.toParent[3][2];
3791
+ pos[3] = hip.rz;
3792
+ pos[4] = hip.ry;
3793
+ pos[5] = hip.rx;
33233794 }
33243795
33253796 cVector temp = new cVector();
3326
- temp.x = obj.globalTransform[3][0];
3327
- temp.y = obj.globalTransform[3][1];
3328
- temp.z = obj.globalTransform[3][2];
3797
+ temp.x = hip.globalTransform[3][0];
3798
+ temp.y = hip.globalTransform[3][1];
3799
+ temp.z = hip.globalTransform[3][2];
33293800 // LA.xformPos(temp, origin0.toParent, temp);
33303801 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33313802
....@@ -3409,7 +3880,7 @@
34093880 }
34103881
34113882 // Rewind();
3412
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3883
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34133884 }
34143885
34153886 void Rewind()
....@@ -3426,7 +3897,7 @@
34263897
34273898 transient boolean restarted; // CROWD issue?
34283899
3429
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3900
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
34303901 {
34313902 //System.err.println("drawSelf Mocap frame # " + frame);
34323903 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3443,17 +3914,22 @@
34433914 // if (firstframe)
34443915 // return;
34453916
3446
- if (!restarted && /*display.restartframe &&*/
3447
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3917
+ if (//!restarted && /*display.restartframe &&*/
3918
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW))
34483919 {
34493920 //display.restartframe = false;
34503921 restarted = true;
3922
+ //System.err.println("restarted = true");
34513923 Step();
34523924 }
34533925 else
34543926 {
3455
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3927
+ //System.err.println("restarted");
3928
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3929
+ {
34563930 restarted = false;
3931
+ //System.err.println("restarted = false");
3932
+ }
34573933 }
34583934
34593935 super.drawSelf(display, root, selected, blocked);