Normand Briere
2018-12-15 6ed65dcb597fb2153cef75bf1845978f1115658c
Mocap.java
....@@ -29,7 +29,7 @@
2929
3030 void Fade()
3131 {
32
- if (true) // currentbones == null || CameraPane.fullreset)
32
+ if (currentbones == null || CameraPane.fullreset)
3333 return;
3434
3535 cVector temp = new cVector();
....@@ -107,7 +107,7 @@
107107 //data[f3 + i] += pos[i] - data[frame3 + i];
108108 // data[f3 + i] = k*data[f3+i] + (1-k)*
109109 // currentbones[boneframe3 + i-end];
110
- data[f3 + i] = (float)CurveAngle(data[f3+i], currenthip[i], 1-k);
110
+// data[f3 + i] = (float)CurveAngle(data[f3+i], currenthip[i], 1-k);
111111 }
112112
113113 // TODO: translation
....@@ -225,7 +225,7 @@
225225 // before resetting the mocap data.
226226 void SetGlobalTransform()
227227 {
228
- SetCurrentBones(frame);
228
+ //SetCurrentBones(frame);
229229
230230 cVector temp = new cVector();
231231 cVector pos = new cVector();
....@@ -235,6 +235,12 @@
235235 double angleYhip = 0;
236236
237237 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
+ }
238244
239245 LA.matConcat(toParent, hip.get(0).toParent, matrix);
240246 poship.x = matrix[3][0];
....@@ -255,9 +261,9 @@
255261
256262 // LA.matConcat(toParent, hip.get(0).toParent, toParent);
257263
258
- CameraPane.debugpoint.toParent[3][0] = poship.x;
259
- CameraPane.debugpoint.toParent[3][1] = poship.y;
260
- CameraPane.debugpoint.toParent[3][2] = poship.z;
264
+ CameraPane.debugpointG.toParent[3][0] = poship.x;
265
+ CameraPane.debugpointG.toParent[3][1] = poship.y;
266
+ CameraPane.debugpointG.toParent[3][2] = poship.z;
261267
262268 LA.matInvert(toParent, fromParent);
263269
....@@ -277,28 +283,28 @@
277283 poship.x = hip.get(0).toParent[3][0];
278284 poship.y = hip.get(0).toParent[3][1];
279285 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);
280294
281
- // AT*AR = A'T*BT*A'R*BR
282
- //
283
- LA.matInvert(hip.get(0).toParent, matrix);
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);
284301
285302 //LA.matIdentity(matrix);
286303 //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
287304
288305 LA.matConcat(toParent, matrix, toParent);
289306
290
-// poship.x = hip.get(0).toParent[3][0];
291
-// poship.y = hip.get(0).toParent[3][1];
292
-// poship.z = hip.get(0).toParent[3][2];
293
-//
294
-// temp.x = 1;
295
-// temp.y = 0;
296
-// temp.z = 0;
297
-//
298
-// LA.xformDir(temp, hip.get(0).toParent, temp);
299
-//
300
-// angleYhip = Math.atan2(-temp.z, temp.x);
301
-
307
+
302308 LA.matConcat(toParent, hip.get(0).toParent, matrix);
303309 pos.x = hip.get(0).toParent[3][0];
304310 pos.y = hip.get(0).toParent[3][1];
....@@ -318,21 +324,21 @@
318324 // LA.matYRotate(toParent, angleY - angleYhip);
319325 // LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
320326
321
- CameraPane.debugpoint2.toParent[3][0] = pos.x;
322
- CameraPane.debugpoint2.toParent[3][1] = pos.y;
323
- CameraPane.debugpoint2.toParent[3][2] = pos.z;
327
+ CameraPane.debugpointP.toParent[3][0] = pos.x;
328
+ CameraPane.debugpointP.toParent[3][1] = pos.y;
329
+ CameraPane.debugpointP.toParent[3][2] = pos.z;
324330
325
- CameraPane.debugpoint3.toParent[3][0] = poship.x;
326
- CameraPane.debugpoint3.toParent[3][1] = poship.y;
327
- CameraPane.debugpoint3.toParent[3][2] = poship.z;
331
+ CameraPane.debugpointC.toParent[3][0] = poship.x;
332
+ CameraPane.debugpointC.toParent[3][1] = poship.y;
333
+ CameraPane.debugpointC.toParent[3][2] = poship.z;
328334
329335 poship.x = toParent[3][0];
330336 poship.y = toParent[3][1];
331337 poship.z = toParent[3][2];
332338
333
- CameraPane.debugpoint4.toParent[3][0] = poship.x;
334
- CameraPane.debugpoint4.toParent[3][1] = poship.y;
335
- CameraPane.debugpoint4.toParent[3][2] = poship.z;
339
+ CameraPane.debugpointR.toParent[3][0] = poship.x;
340
+ CameraPane.debugpointR.toParent[3][1] = poship.y;
341
+ CameraPane.debugpointR.toParent[3][2] = poship.z;
336342
337343 LA.matInvert(toParent, fromParent);
338344 }
....@@ -470,6 +476,118 @@
470476 currenthip[i] = data[frame3 + i];
471477 }
472478 }
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
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
488
+
489
+ mocaporigin.x = matrix[3][0];
490
+ mocaporigin.y = matrix[3][1];
491
+ mocaporigin.z = matrix[3][2];
492
+
493
+ centroid.x = matrix[3][0];
494
+ centroid.y = matrix[3][1];
495
+ centroid.z = matrix[3][2];
496
+// this.getCentroid(centroid, true);
497
+
498
+ CameraPane.debugpointG.name = "";
499
+ CameraPane.debugpointG.toParent[3][0] = mocaporigin.x;
500
+ CameraPane.debugpointG.toParent[3][1] = mocaporigin.y;
501
+ CameraPane.debugpointG.toParent[3][2] = mocaporigin.z;
502
+
503
+ CameraPane.debugpointP.name = "";
504
+ CameraPane.debugpointP.toParent[3][0] = centroid.x;
505
+ CameraPane.debugpointP.toParent[3][1] = centroid.y;
506
+ CameraPane.debugpointP.toParent[3][2] = centroid.z;
507
+
508
+ cVector goal = GetGoal(centroid);
509
+ if (goal != null)
510
+ {
511
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
512
+
513
+ goalposx = goal.x;
514
+ goalposz = goal.z;
515
+ targetdirx = targetdirz = 0;
516
+ }
517
+
518
+ if (goalposx == 0 && goalposz == 0)
519
+ {
520
+ // No target
521
+ if (ScriptNode.speaker != null)
522
+ {
523
+ Object3D sourcenode = GetFileRoot();
524
+ Object3D speakernode = ScriptNode.speaker.GetFileRoot();
525
+
526
+ //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker);
527
+
528
+ Object3D speaker = ScriptNode.speaker;
529
+
530
+ if (speakernode == sourcenode)
531
+ {
532
+ if (ScriptNode.lastspeaker != null)
533
+ {
534
+ speakernode = ScriptNode.lastspeaker.GetFileRoot();
535
+ speaker = ScriptNode.lastspeaker;
536
+ }
537
+ else
538
+ return;
539
+ }
540
+
541
+ cVector dst = new cVector();
542
+
543
+ boolean success = speakernode.getCentroid(dst); // , true);
544
+
545
+ if (!success)
546
+ new Exception().printStackTrace();
547
+
548
+ //speakernode.parent.TransformToWorld(dst);
549
+ //sourcenode.parent.TransformToLocal(dst);
550
+ this.parent.TransformToLocal(dst);
551
+
552
+ goalposx = dst.x;
553
+ goalposz = dst.z;
554
+ }
555
+ else
556
+ return;
557
+ }
558
+
559
+ cVector temp = new cVector();
560
+
561
+ temp.x = 1;
562
+ temp.y = 0;
563
+ temp.z = 0;
564
+
565
+ LA.xformDir(temp, matrix, temp);
566
+
567
+ double angleYhip = Math.atan2(-temp.z, temp.x);
568
+
569
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
570
+
571
+ LA.matIdentity(matrix);
572
+ LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
573
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
574
+ LA.matYRotate(matrix, angle);
575
+ LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
576
+
577
+ LA.matConcat(matrix, toParent, toParent);
578
+
579
+ LA.matInvert(toParent, fromParent);
580
+
581
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
582
+
583
+ centroid.x = matrix[3][0];
584
+ centroid.y = matrix[3][1];
585
+ centroid.z = matrix[3][2];
586
+
587
+ double dist = LA.distance(centroid, mocaporigin);
588
+
589
+ CheckForAction(centroid);
590
+ }
473591
474592 void WriteTo(java.io.Writer writer) throws Exception
475593 {
....@@ -543,11 +661,11 @@
543661 double pinx;
544662 double pinz;
545663
546
- double targetx;
547
- double targetz;
664
+ double targetdirx;
665
+ double targetdirz;
548666
549
- double goalx;
550
- double goalz;
667
+ double goalposx = -20;
668
+ double goalposz = -10;
551669
552670 boolean followpath;
553671
....@@ -618,7 +736,7 @@
618736 scriptactions.clear();
619737 }
620738
621
- static double EPSACTION = 0.1; // 0.075; // 0.1;
739
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
622740
623741 void AddFromTo(cVector from, cVector to)
624742 {
....@@ -904,6 +1022,8 @@
9041022 testvect.set(from);
9051023 testvect.sub(fromto.from);
9061024
1025
+ testvect.y = 0; // PATCH
1026
+
9071027 int factor = 1;
9081028
9091029 //if (CameraPane.FAST)
....@@ -945,6 +1065,8 @@
9451065
9461066 testvect.set(from);
9471067 testvect.sub(fromto.from);
1068
+
1069
+ testvect.y = 0; // PATCH
9481070
9491071 int factor = 1;
9501072
....@@ -1180,6 +1302,7 @@
11801302
11811303 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
11821304 {
1305
+ assert(false);
11831306 //assert(CameraPane.drawMode == CameraPane.SHADOW);
11841307
11851308 Object3D transformnode = new Object3D();
....@@ -1383,9 +1506,9 @@
13831506 groundid = floorid;
13841507
13851508 // green
1386
- CameraPane.debugpoint.toParent[3][0] = groundx;
1387
- CameraPane.debugpoint.toParent[3][1] = floor.y;
1388
- CameraPane.debugpoint.toParent[3][2] = groundz;
1509
+ CameraPane.debugpointG.toParent[3][0] = groundx;
1510
+ CameraPane.debugpointG.toParent[3][1] = floor.y;
1511
+ CameraPane.debugpointG.toParent[3][2] = groundz;
13891512
13901513 if (true) // slow && stepout && onein)
13911514 {
....@@ -1462,9 +1585,9 @@
14621585
14631586 // System.out.println("Allo " + sourcenode);
14641587 // purple
1465
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1466
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1467
- CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz;
1588
+ CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx;
1589
+ CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1590
+ CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz;
14681591
14691592
14701593 if (false) // dist2 > 0.1)
....@@ -1530,9 +1653,9 @@
15301653 this.get(0).TransformToWorld(v0);
15311654
15321655 // cyan
1533
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1534
- CameraPane.debugpoint3.toParent[3][1] = ground;
1535
- CameraPane.debugpoint3.toParent[3][2] = v0.z;
1656
+ CameraPane.debugpointC.toParent[3][0] = v0.x;
1657
+ CameraPane.debugpointC.toParent[3][1] = ground;
1658
+ CameraPane.debugpointC.toParent[3][2] = v0.z;
15361659
15371660 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
15381661 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1542,9 +1665,9 @@
15421665 this.get(0).TransformToWorld(v0);
15431666
15441667 // red
1545
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1546
- CameraPane.debugpoint4.toParent[3][1] = ground;
1547
- CameraPane.debugpoint4.toParent[3][2] = v0.z;
1668
+ CameraPane.debugpointR.toParent[3][0] = v0.x;
1669
+ CameraPane.debugpointR.toParent[3][1] = ground;
1670
+ CameraPane.debugpointR.toParent[3][2] = v0.z;
15481671 }
15491672 }
15501673
....@@ -1584,11 +1707,11 @@
15841707
15851708 if (goal != null)
15861709 {
1587
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1710
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
15881711 //sourcenode.parent.parent.Dump();
1589
- goalx = goal.x;
1590
- goalz = goal.z;
1591
- targetx = targetz = 0;
1712
+ goalposx = goal.x;
1713
+ goalposz = goal.z;
1714
+ targetdirx = targetdirz = 0;
15921715
15931716 followpath = true;
15941717 }
....@@ -1639,16 +1762,16 @@
16391762 // }
16401763 if (false) // !uselast)
16411764 {
1642
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1643
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1644
- CameraPane.debugpoint.toParent[3][2] = dst.z;
1765
+ CameraPane.debugpointG.toParent[3][0] = dst.x;
1766
+ CameraPane.debugpointG.toParent[3][1] = dst.y;
1767
+ CameraPane.debugpointG.toParent[3][2] = dst.z;
16451768 }
16461769 }
16471770
1648
- if (goalx != 0 || goalz != 0) // TODO
1771
+ if (goalposx != 0 || goalposz != 0) // TODO
16491772 {
16501773 // overwrite speaker orientation
1651
- dst.set(goalx,0,goalz);
1774
+ dst.set(goalposx,0,goalposz);
16521775 if (sourcenode.parent != null) // july 2014
16531776 sourcenode.parent.
16541777 TransformToLocal(dst);
....@@ -1700,26 +1823,26 @@
17001823 // mars 2014
17011824 if (false) // goalx != 0 || goalz != 0)
17021825 {
1703
- targetx = dst.x - src.x;
1704
- targetz = dst.z - src.z;
1826
+ targetdirx = dst.x - src.x;
1827
+ targetdirz = dst.z - src.z;
17051828
1706
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1829
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
17071830 {
17081831 // far enough from goal. keep the goal position.
1709
- targetx = 0;
1710
- targetz = 0;
1832
+ targetdirx = 0;
1833
+ targetdirz = 0;
17111834 }
17121835 else
17131836 {
17141837 // too close to goal. switch to target direction instead.
1715
- goalx = 0;
1716
- goalz = 0;
1838
+ goalposx = 0;
1839
+ goalposz = 0;
17171840 }
17181841 }
17191842
17201843 //sourcenode.getCentroid(src, true);
17211844
1722
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1845
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
17231846 {
17241847 if (ScriptNode.lastspeaker != null)
17251848 new Exception().printStackTrace();
....@@ -1728,13 +1851,13 @@
17281851
17291852 // LA.xformPos(src, fromParent, src);
17301853
1731
- if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0)
1854
+ if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0)
17321855 dst.sub(src);
17331856 else
17341857 // vector mode
17351858 {
1736
- dst.x = targetx;
1737
- dst.z = targetz;
1859
+ dst.x = targetdirx;
1860
+ dst.z = targetdirz;
17381861
17391862 // TEST TARGET
17401863 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -2182,9 +2305,16 @@
21822305 toVector.x = LA.cos(to);
21832306 toVector.y = LA.sin(to);
21842307
2308
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2309
+ double toA = Math.atan2(toVector.y, toVector.x);
2310
+
21852311 Vector2d currentVector = Slerp(fromVector, toVector, step);
21862312
2187
- return Math.atan2(currentVector.y, currentVector.x);
2313
+ double angle = Math.atan2(currentVector.y, currentVector.x);
2314
+
2315
+ double angle2 = (1-step) * fromA + step * toA;
2316
+
2317
+ return angle;
21882318 }
21892319
21902320 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -2236,6 +2366,8 @@
22362366 {
22372367 e.printStackTrace();
22382368 }
2369
+
2370
+ SetHipOrientation();
22392371
22402372 if (true)
22412373 return;
....@@ -2664,8 +2796,8 @@
26642796 // set rotation
26652797 //if (bone._rotationEnabled)
26662798 if (//frame > 0 &&
2667
- !bone.skipmocap //&&
2668
- //!bone.name.contains("head") &&
2799
+ !bone.skipmocap &&
2800
+ !bone.name.contains("head") // &&
26692801 // !bone.name.contains("rFoot") &&
26702802 // !bone.name.contains("lFoot") &&
26712803 // !bone.name.contains("Pinky") &&
....@@ -3020,7 +3152,8 @@
30203152 }
30213153 }
30223154
3023
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3155
+ // skip initial "T"
3156
+ static int offset = 1; // 5; // 10; // 5; // 100;
30243157
30253158 void ReadBVH()
30263159 {
....@@ -3049,8 +3182,8 @@
30493182
30503183 void Reset()
30513184 {
3052
- if (fullname != null)
3053
- ReadBVH();
3185
+// if (fullname != null)
3186
+// ReadBVH();
30543187
30553188 Object3D hip = get(0);
30563189
....@@ -3089,8 +3222,8 @@
30893222 // LA.matIdentity(rot.fromParent);
30903223
30913224 // july 2014
3092
- goalx = goalz = 0;
3093
- targetx = targetz = 0;
3225
+// goalx = goalz = 0;
3226
+ targetdirx = targetdirz = 0;
30943227
30953228 //SetPositionDelta(true, true, true, false);
30963229 // LoadData();
....@@ -3132,7 +3265,7 @@
31323265 baseframe += step;
31333266
31343267 //frame = baseframe;
3135
- frame += step;
3268
+ //frame += step;
31363269
31373270 // if (frame != baseframe)
31383271 // {
....@@ -3184,13 +3317,17 @@
31843317 }
31853318 }
31863319 }
3320
+
3321
+ frame = GetFirstFrame();
31873322 }
3323
+ else
3324
+ frame += step;
31883325
31893326 //SetPositionDelta(false);
31903327
3191
- if (frame >= bvh.animation.getNumFrames())
3192
- //baseframe =
3193
- frame = GetFirstFrame(); // 0; // offset; // initial point
3328
+// if (frame >= bvh.animation.getNumFrames())
3329
+// //baseframe =
3330
+// frame = GetFirstFrame(); // 0; // offset; // initial point
31943331
31953332 //System.err.println("frame = " + frame);
31963333 if (lastframe != 0)