Normand Briere
2018-12-15 6ed65dcb597fb2153cef75bf1845978f1115658c
Mocap.java
....@@ -261,9 +261,9 @@
261261
262262 // LA.matConcat(toParent, hip.get(0).toParent, toParent);
263263
264
- CameraPane.debugpoint.toParent[3][0] = poship.x;
265
- CameraPane.debugpoint.toParent[3][1] = poship.y;
266
- 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;
267267
268268 LA.matInvert(toParent, fromParent);
269269
....@@ -283,28 +283,28 @@
283283 poship.x = hip.get(0).toParent[3][0];
284284 poship.y = hip.get(0).toParent[3][1];
285285 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);
286294
287
- // AT*AR = A'T*BT*A'R*BR
288
- //
289
- 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);
290301
291302 //LA.matIdentity(matrix);
292303 //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
293304
294305 LA.matConcat(toParent, matrix, toParent);
295306
296
-// poship.x = hip.get(0).toParent[3][0];
297
-// poship.y = hip.get(0).toParent[3][1];
298
-// poship.z = hip.get(0).toParent[3][2];
299
-//
300
-// temp.x = 1;
301
-// temp.y = 0;
302
-// temp.z = 0;
303
-//
304
-// LA.xformDir(temp, hip.get(0).toParent, temp);
305
-//
306
-// angleYhip = Math.atan2(-temp.z, temp.x);
307
-
307
+
308308 LA.matConcat(toParent, hip.get(0).toParent, matrix);
309309 pos.x = hip.get(0).toParent[3][0];
310310 pos.y = hip.get(0).toParent[3][1];
....@@ -324,21 +324,21 @@
324324 // LA.matYRotate(toParent, angleY - angleYhip);
325325 // LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
326326
327
- CameraPane.debugpoint2.toParent[3][0] = pos.x;
328
- CameraPane.debugpoint2.toParent[3][1] = pos.y;
329
- 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;
330330
331
- CameraPane.debugpoint3.toParent[3][0] = poship.x;
332
- CameraPane.debugpoint3.toParent[3][1] = poship.y;
333
- 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;
334334
335335 poship.x = toParent[3][0];
336336 poship.y = toParent[3][1];
337337 poship.z = toParent[3][2];
338338
339
- CameraPane.debugpoint4.toParent[3][0] = poship.x;
340
- CameraPane.debugpoint4.toParent[3][1] = poship.y;
341
- 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;
342342
343343 LA.matInvert(toParent, fromParent);
344344 }
....@@ -476,6 +476,118 @@
476476 currenthip[i] = data[frame3 + i];
477477 }
478478 }
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
+ }
479591
480592 void WriteTo(java.io.Writer writer) throws Exception
481593 {
....@@ -549,11 +661,11 @@
549661 double pinx;
550662 double pinz;
551663
552
- double targetx;
553
- double targetz;
664
+ double targetdirx;
665
+ double targetdirz;
554666
555
- double goalx;
556
- double goalz;
667
+ double goalposx = -20;
668
+ double goalposz = -10;
557669
558670 boolean followpath;
559671
....@@ -624,7 +736,7 @@
624736 scriptactions.clear();
625737 }
626738
627
- static double EPSACTION = 0.1; // 0.075; // 0.1;
739
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
628740
629741 void AddFromTo(cVector from, cVector to)
630742 {
....@@ -910,6 +1022,8 @@
9101022 testvect.set(from);
9111023 testvect.sub(fromto.from);
9121024
1025
+ testvect.y = 0; // PATCH
1026
+
9131027 int factor = 1;
9141028
9151029 //if (CameraPane.FAST)
....@@ -951,6 +1065,8 @@
9511065
9521066 testvect.set(from);
9531067 testvect.sub(fromto.from);
1068
+
1069
+ testvect.y = 0; // PATCH
9541070
9551071 int factor = 1;
9561072
....@@ -1186,6 +1302,7 @@
11861302
11871303 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
11881304 {
1305
+ assert(false);
11891306 //assert(CameraPane.drawMode == CameraPane.SHADOW);
11901307
11911308 Object3D transformnode = new Object3D();
....@@ -1389,9 +1506,9 @@
13891506 groundid = floorid;
13901507
13911508 // green
1392
- CameraPane.debugpoint.toParent[3][0] = groundx;
1393
- CameraPane.debugpoint.toParent[3][1] = floor.y;
1394
- 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;
13951512
13961513 if (true) // slow && stepout && onein)
13971514 {
....@@ -1468,9 +1585,9 @@
14681585
14691586 // System.out.println("Allo " + sourcenode);
14701587 // purple
1471
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1472
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1473
- 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;
14741591
14751592
14761593 if (false) // dist2 > 0.1)
....@@ -1536,9 +1653,9 @@
15361653 this.get(0).TransformToWorld(v0);
15371654
15381655 // cyan
1539
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1540
- CameraPane.debugpoint3.toParent[3][1] = ground;
1541
- 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;
15421659
15431660 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
15441661 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1548,9 +1665,9 @@
15481665 this.get(0).TransformToWorld(v0);
15491666
15501667 // red
1551
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1552
- CameraPane.debugpoint4.toParent[3][1] = ground;
1553
- 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;
15541671 }
15551672 }
15561673
....@@ -1590,11 +1707,11 @@
15901707
15911708 if (goal != null)
15921709 {
1593
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1710
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
15941711 //sourcenode.parent.parent.Dump();
1595
- goalx = goal.x;
1596
- goalz = goal.z;
1597
- targetx = targetz = 0;
1712
+ goalposx = goal.x;
1713
+ goalposz = goal.z;
1714
+ targetdirx = targetdirz = 0;
15981715
15991716 followpath = true;
16001717 }
....@@ -1645,16 +1762,16 @@
16451762 // }
16461763 if (false) // !uselast)
16471764 {
1648
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1649
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1650
- 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;
16511768 }
16521769 }
16531770
1654
- if (goalx != 0 || goalz != 0) // TODO
1771
+ if (goalposx != 0 || goalposz != 0) // TODO
16551772 {
16561773 // overwrite speaker orientation
1657
- dst.set(goalx,0,goalz);
1774
+ dst.set(goalposx,0,goalposz);
16581775 if (sourcenode.parent != null) // july 2014
16591776 sourcenode.parent.
16601777 TransformToLocal(dst);
....@@ -1706,26 +1823,26 @@
17061823 // mars 2014
17071824 if (false) // goalx != 0 || goalz != 0)
17081825 {
1709
- targetx = dst.x - src.x;
1710
- targetz = dst.z - src.z;
1826
+ targetdirx = dst.x - src.x;
1827
+ targetdirz = dst.z - src.z;
17111828
1712
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1829
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
17131830 {
17141831 // far enough from goal. keep the goal position.
1715
- targetx = 0;
1716
- targetz = 0;
1832
+ targetdirx = 0;
1833
+ targetdirz = 0;
17171834 }
17181835 else
17191836 {
17201837 // too close to goal. switch to target direction instead.
1721
- goalx = 0;
1722
- goalz = 0;
1838
+ goalposx = 0;
1839
+ goalposz = 0;
17231840 }
17241841 }
17251842
17261843 //sourcenode.getCentroid(src, true);
17271844
1728
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1845
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
17291846 {
17301847 if (ScriptNode.lastspeaker != null)
17311848 new Exception().printStackTrace();
....@@ -1734,13 +1851,13 @@
17341851
17351852 // LA.xformPos(src, fromParent, src);
17361853
1737
- 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)
17381855 dst.sub(src);
17391856 else
17401857 // vector mode
17411858 {
1742
- dst.x = targetx;
1743
- dst.z = targetz;
1859
+ dst.x = targetdirx;
1860
+ dst.z = targetdirz;
17441861
17451862 // TEST TARGET
17461863 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -2188,9 +2305,16 @@
21882305 toVector.x = LA.cos(to);
21892306 toVector.y = LA.sin(to);
21902307
2308
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2309
+ double toA = Math.atan2(toVector.y, toVector.x);
2310
+
21912311 Vector2d currentVector = Slerp(fromVector, toVector, step);
21922312
2193
- 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;
21942318 }
21952319
21962320 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -2242,6 +2366,8 @@
22422366 {
22432367 e.printStackTrace();
22442368 }
2369
+
2370
+ SetHipOrientation();
22452371
22462372 if (true)
22472373 return;
....@@ -2670,8 +2796,8 @@
26702796 // set rotation
26712797 //if (bone._rotationEnabled)
26722798 if (//frame > 0 &&
2673
- !bone.skipmocap //&&
2674
- //!bone.name.contains("head") &&
2799
+ !bone.skipmocap &&
2800
+ !bone.name.contains("head") // &&
26752801 // !bone.name.contains("rFoot") &&
26762802 // !bone.name.contains("lFoot") &&
26772803 // !bone.name.contains("Pinky") &&
....@@ -3056,8 +3182,8 @@
30563182
30573183 void Reset()
30583184 {
3059
- if (fullname != null)
3060
- ReadBVH();
3185
+// if (fullname != null)
3186
+// ReadBVH();
30613187
30623188 Object3D hip = get(0);
30633189
....@@ -3096,8 +3222,8 @@
30963222 // LA.matIdentity(rot.fromParent);
30973223
30983224 // july 2014
3099
- goalx = goalz = 0;
3100
- targetx = targetz = 0;
3225
+// goalx = goalz = 0;
3226
+ targetdirx = targetdirz = 0;
31013227
31023228 //SetPositionDelta(true, true, true, false);
31033229 // LoadData();