Normand Briere
2019-06-09 79d0f9a45d36656051a77a7b0837aa0318f81ee5
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
....@@ -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 }
....@@ -477,29 +477,51 @@
477477 }
478478 }
479479
480
+ static cVector centroid = new cVector();
481
+ static cVector mocaporigin = new cVector();
482
+
480483 void SetHipOrientation()
481484 {
482485 Object3D hip = get(0);
483486
487
+ if (toParent == null)
488
+ {
489
+ toParent = LA.newMatrix();
490
+ fromParent = LA.newMatrix();
491
+ }
492
+
484493 LA.matConcat(toParent, hip.get(0).toParent, matrix);
485494
486
- cVector centroid = new cVector();
495
+ mocaporigin.x = matrix[3][0];
496
+ mocaporigin.y = matrix[3][1];
497
+ mocaporigin.z = matrix[3][2];
498
+
487499 centroid.x = matrix[3][0];
488500 centroid.y = matrix[3][1];
489501 centroid.z = matrix[3][2];
490
- this.getCentroid(centroid, true);
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;
491513
492514 cVector goal = GetGoal(centroid);
493515 if (goal != null)
494516 {
495
- System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalx + ", " + goalz + ")");
517
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
496518
497
- goalx = goal.x;
498
- goalz = goal.z;
499
- targetx = targetz = 0;
519
+ goalposx = goal.x;
520
+ goalposz = goal.z;
521
+ targetdirx = targetdirz = 0;
500522 }
501523
502
- if (goalx == 0 && goalz == 0)
524
+ if (goalposx == 0 && goalposz == 0)
503525 {
504526 // No target
505527 if (ScriptNode.speaker != null)
....@@ -533,8 +555,8 @@
533555 //sourcenode.parent.TransformToLocal(dst);
534556 this.parent.TransformToLocal(dst);
535557
536
- goalx = dst.x;
537
- goalz = dst.z;
558
+ goalposx = dst.x;
559
+ goalposz = dst.z;
538560 }
539561 else
540562 return;
....@@ -550,17 +572,25 @@
550572
551573 double angleYhip = Math.atan2(-temp.z, temp.x);
552574
553
- double angleYtarget = Math.atan2(goalx - centroid.x, goalz - centroid.z);
575
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
554576
555577 LA.matIdentity(matrix);
556578 LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
557
- double angle = CurveAngle(0, angleYtarget - angleYhip, 1); // 0.1f);
579
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
558580 LA.matYRotate(matrix, angle);
559581 LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
560582
561583 LA.matConcat(matrix, toParent, toParent);
562584
563585 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);
564594
565595 CheckForAction(centroid);
566596 }
....@@ -637,11 +667,11 @@
637667 double pinx;
638668 double pinz;
639669
640
- double targetx;
641
- double targetz;
670
+ double targetdirx;
671
+ double targetdirz;
642672
643
- double goalx = -20;
644
- double goalz = -10;
673
+ double goalposx = 0; // -20;
674
+ double goalposz = 0; // -10;
645675
646676 boolean followpath;
647677
....@@ -712,7 +742,7 @@
712742 scriptactions.clear();
713743 }
714744
715
- static double EPSACTION = 0.1; // 0.075; // 0.1;
745
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
716746
717747 void AddFromTo(cVector from, cVector to)
718748 {
....@@ -897,7 +927,7 @@
897927 // //GetFileRoot();
898928
899929 // sept 2014: //
900
- GrafreeD.RENDERME = 3; // patch for Merge objects
930
+ Grafreed.RENDERME = 3; // patch for Merge objects
901931 float[] thedata = bvh.animation.getBoneData(0);
902932
903933 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -1278,6 +1308,7 @@
12781308
12791309 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
12801310 {
1311
+ assert(false);
12811312 //assert(CameraPane.drawMode == CameraPane.SHADOW);
12821313
12831314 Object3D transformnode = new Object3D();
....@@ -1481,9 +1512,9 @@
14811512 groundid = floorid;
14821513
14831514 // green
1484
- CameraPane.debugpoint.toParent[3][0] = groundx;
1485
- CameraPane.debugpoint.toParent[3][1] = floor.y;
1486
- 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;
14871518
14881519 if (true) // slow && stepout && onein)
14891520 {
....@@ -1494,7 +1525,7 @@
14941525 // mywave = currentwave++;
14951526 // }
14961527 // sound
1497
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1528
+ cVector eye = Globals.theRenderer.EyeCamera().location;
14981529
14991530 // if (sourcenode.parent.parent != null)
15001531 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -1539,9 +1570,9 @@
15391570 //GraphreeD.
15401571 wav.play(volume * usedvolume); //, mywave);
15411572
1542
- lastsoundtime = CameraPane.framecount;
1573
+ lastsoundtime = Globals.framecount;
15431574
1544
- GrafreeD.hassound = true;
1575
+ Grafreed.hassound = true;
15451576 }
15461577 // else
15471578 // System.out.println("skipped");
....@@ -1560,9 +1591,9 @@
15601591
15611592 // System.out.println("Allo " + sourcenode);
15621593 // purple
1563
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1564
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1565
- 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;
15661597
15671598
15681599 if (false) // dist2 > 0.1)
....@@ -1628,9 +1659,9 @@
16281659 this.get(0).TransformToWorld(v0);
16291660
16301661 // cyan
1631
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1632
- CameraPane.debugpoint3.toParent[3][1] = ground;
1633
- 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;
16341665
16351666 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
16361667 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1640,9 +1671,9 @@
16401671 this.get(0).TransformToWorld(v0);
16411672
16421673 // red
1643
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1644
- CameraPane.debugpoint4.toParent[3][1] = ground;
1645
- 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;
16461677 }
16471678 }
16481679
....@@ -1682,11 +1713,11 @@
16821713
16831714 if (goal != null)
16841715 {
1685
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1716
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
16861717 //sourcenode.parent.parent.Dump();
1687
- goalx = goal.x;
1688
- goalz = goal.z;
1689
- targetx = targetz = 0;
1718
+ goalposx = goal.x;
1719
+ goalposz = goal.z;
1720
+ targetdirx = targetdirz = 0;
16901721
16911722 followpath = true;
16921723 }
....@@ -1737,16 +1768,16 @@
17371768 // }
17381769 if (false) // !uselast)
17391770 {
1740
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1741
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1742
- 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;
17431774 }
17441775 }
17451776
1746
- if (goalx != 0 || goalz != 0) // TODO
1777
+ if (goalposx != 0 || goalposz != 0) // TODO
17471778 {
17481779 // overwrite speaker orientation
1749
- dst.set(goalx,0,goalz);
1780
+ dst.set(goalposx,0,goalposz);
17501781 if (sourcenode.parent != null) // july 2014
17511782 sourcenode.parent.
17521783 TransformToLocal(dst);
....@@ -1798,26 +1829,26 @@
17981829 // mars 2014
17991830 if (false) // goalx != 0 || goalz != 0)
18001831 {
1801
- targetx = dst.x - src.x;
1802
- targetz = dst.z - src.z;
1832
+ targetdirx = dst.x - src.x;
1833
+ targetdirz = dst.z - src.z;
18031834
1804
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1835
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
18051836 {
18061837 // far enough from goal. keep the goal position.
1807
- targetx = 0;
1808
- targetz = 0;
1838
+ targetdirx = 0;
1839
+ targetdirz = 0;
18091840 }
18101841 else
18111842 {
18121843 // too close to goal. switch to target direction instead.
1813
- goalx = 0;
1814
- goalz = 0;
1844
+ goalposx = 0;
1845
+ goalposz = 0;
18151846 }
18161847 }
18171848
18181849 //sourcenode.getCentroid(src, true);
18191850
1820
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1851
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
18211852 {
18221853 if (ScriptNode.lastspeaker != null)
18231854 new Exception().printStackTrace();
....@@ -1826,13 +1857,13 @@
18261857
18271858 // LA.xformPos(src, fromParent, src);
18281859
1829
- 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)
18301861 dst.sub(src);
18311862 else
18321863 // vector mode
18331864 {
1834
- dst.x = targetx;
1835
- dst.z = targetz;
1865
+ dst.x = targetdirx;
1866
+ dst.z = targetdirz;
18361867
18371868 // TEST TARGET
18381869 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -2242,7 +2273,7 @@
22422273 }
22432274
22442275 if (!smoothed)
2245
- for (int i=0; --i>=0;)
2276
+ for (int i=10; --i>=0;)
22462277 SmoothAnimData(); // much reduces shakiness
22472278
22482279 smoothed = true;
....@@ -2280,9 +2311,16 @@
22802311 toVector.x = LA.cos(to);
22812312 toVector.y = LA.sin(to);
22822313
2314
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2315
+ double toA = Math.atan2(toVector.y, toVector.x);
2316
+
22832317 Vector2d currentVector = Slerp(fromVector, toVector, step);
22842318
2285
- 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;
22862324 }
22872325
22882326 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -2765,7 +2803,8 @@
27652803 //if (bone._rotationEnabled)
27662804 if (//frame > 0 &&
27672805 !bone.skipmocap &&
2768
- !bone.name.contains("head") // &&
2806
+ !bone.name.contains("head") &&
2807
+ !bone.name.contains("Head") // &&
27692808 // !bone.name.contains("rFoot") &&
27702809 // !bone.name.contains("lFoot") &&
27712810 // !bone.name.contains("Pinky") &&
....@@ -3191,7 +3230,7 @@
31913230
31923231 // july 2014
31933232 // goalx = goalz = 0;
3194
- targetx = targetz = 0;
3233
+ targetdirx = targetdirz = 0;
31953234
31963235 //SetPositionDelta(true, true, true, false);
31973236 // LoadData();
....@@ -3201,8 +3240,8 @@
32013240
32023241 // aout 2013 endframe = 0; // june 2013
32033242
3204
- //ResetZero();
3205
- setPose(frame);
3243
+ ResetZero();
3244
+ //setPose(frame);
32063245 }
32073246
32083247 static int mocapsupport = 0;
....@@ -3220,12 +3259,13 @@
32203259
32213260 int step = 1;
32223261
3262
+ // patch for running hare
32233263 if (speedup) // fev 2014
32243264 step *= 2; // 4;
32253265 if (rewind) // mars 2014
32263266 step *= 4;
32273267
3228
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3268
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
32293269 step *= CameraPane.STEP;
32303270
32313271 //System.err.println("Step Mocap frame # " + frame);
....@@ -3257,7 +3297,7 @@
32573297 "; fullname = " + fullname);
32583298
32593299 //int delta = frame - baseframe;
3260
- if (CameraPane.CROWD)
3300
+ if (Globals.CROWD)
32613301 {
32623302 baseframe = GetFirstFrame(); // 0 initial point
32633303 }
....@@ -3266,23 +3306,40 @@
32663306 // SetPositionDelta(false, true, false); // ?? false);
32673307 {
32683308 if (support == null)
3269
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3309
+ {
3310
+ if (bvh == null && new File(fullname).exists())
3311
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3312
+ else
3313
+ {
3314
+ SetGlobalTransform();
3315
+ Rewind();
3316
+ Fade();
3317
+ }
3318
+ }
32703319 else
32713320 {
3272
- try
3273
- {
3321
+// try
3322
+// {
32743323 bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
32753324
32763325 // SetPositionDelta(false, true, true, true);
32773326 LoadData();
32783327 Rewind();
32793328 Fade();
3280
- }
3281
- catch (Exception e)
3282
- {
3283
- e.printStackTrace();
3284
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3285
- }
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
+// }
32863343 }
32873344 }
32883345
....@@ -3464,6 +3521,7 @@
34643521 // filters out bad input data
34653522 void FilterAnimData()
34663523 {
3524
+ new Exception().printStackTrace();
34673525 System.exit(0);
34683526
34693527 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3821,7 +3879,7 @@
38213879
38223880 transient boolean restarted; // CROWD issue?
38233881
3824
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3882
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
38253883 {
38263884 //System.err.println("drawSelf Mocap frame # " + frame);
38273885 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3838,17 +3896,22 @@
38383896 // if (firstframe)
38393897 // return;
38403898
3841
- if (!restarted && /*display.restartframe &&*/
3842
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3899
+ if (//!restarted && /*display.restartframe &&*/
3900
+ Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW))
38433901 {
38443902 //display.restartframe = false;
38453903 restarted = true;
3904
+ //System.err.println("restarted = true");
38463905 Step();
38473906 }
38483907 else
38493908 {
3850
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3909
+ //System.err.println("restarted");
3910
+ if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW)
3911
+ {
38513912 restarted = false;
3913
+ //System.err.println("restarted = false");
3914
+ }
38523915 }
38533916
38543917 super.drawSelf(display, root, selected, blocked);