Normand Briere
2019-05-05 f69d25e4682ca33edfc8cfad26187050f4eb558a
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,45 @@
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
484487 LA.matConcat(toParent, hip.get(0).toParent, matrix);
485488
486
- cVector centroid = new cVector();
489
+ mocaporigin.x = matrix[3][0];
490
+ mocaporigin.y = matrix[3][1];
491
+ mocaporigin.z = matrix[3][2];
492
+
487493 centroid.x = matrix[3][0];
488494 centroid.y = matrix[3][1];
489495 centroid.z = matrix[3][2];
490
- this.getCentroid(centroid, true);
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;
491507
492508 cVector goal = GetGoal(centroid);
493509 if (goal != null)
494510 {
495
- System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalx + ", " + goalz + ")");
511
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
496512
497
- goalx = goal.x;
498
- goalz = goal.z;
499
- targetx = targetz = 0;
513
+ goalposx = goal.x;
514
+ goalposz = goal.z;
515
+ targetdirx = targetdirz = 0;
500516 }
501517
502
- if (goalx == 0 && goalz == 0)
518
+ if (goalposx == 0 && goalposz == 0)
503519 {
504520 // No target
505521 if (ScriptNode.speaker != null)
....@@ -533,8 +549,8 @@
533549 //sourcenode.parent.TransformToLocal(dst);
534550 this.parent.TransformToLocal(dst);
535551
536
- goalx = dst.x;
537
- goalz = dst.z;
552
+ goalposx = dst.x;
553
+ goalposz = dst.z;
538554 }
539555 else
540556 return;
....@@ -550,17 +566,25 @@
550566
551567 double angleYhip = Math.atan2(-temp.z, temp.x);
552568
553
- double angleYtarget = Math.atan2(goalx - centroid.x, goalz - centroid.z);
569
+ double angleYtarget = Math.atan2(goalposx - centroid.x, goalposz - centroid.z);
554570
555571 LA.matIdentity(matrix);
556572 LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
557
- double angle = CurveAngle(0, angleYtarget - angleYhip, 1); // 0.1f);
573
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f);
558574 LA.matYRotate(matrix, angle);
559575 LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
560576
561577 LA.matConcat(matrix, toParent, toParent);
562578
563579 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);
564588
565589 CheckForAction(centroid);
566590 }
....@@ -637,11 +661,11 @@
637661 double pinx;
638662 double pinz;
639663
640
- double targetx;
641
- double targetz;
664
+ double targetdirx;
665
+ double targetdirz;
642666
643
- double goalx = -20;
644
- double goalz = -10;
667
+ double goalposx = -20;
668
+ double goalposz = -10;
645669
646670 boolean followpath;
647671
....@@ -712,7 +736,7 @@
712736 scriptactions.clear();
713737 }
714738
715
- static double EPSACTION = 0.1; // 0.075; // 0.1;
739
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
716740
717741 void AddFromTo(cVector from, cVector to)
718742 {
....@@ -897,7 +921,7 @@
897921 // //GetFileRoot();
898922
899923 // sept 2014: //
900
- GrafreeD.RENDERME = 3; // patch for Merge objects
924
+ Grafreed.RENDERME = 3; // patch for Merge objects
901925 float[] thedata = bvh.animation.getBoneData(0);
902926
903927 os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]);
....@@ -1278,6 +1302,7 @@
12781302
12791303 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
12801304 {
1305
+ assert(false);
12811306 //assert(CameraPane.drawMode == CameraPane.SHADOW);
12821307
12831308 Object3D transformnode = new Object3D();
....@@ -1481,9 +1506,9 @@
14811506 groundid = floorid;
14821507
14831508 // green
1484
- CameraPane.debugpoint.toParent[3][0] = groundx;
1485
- CameraPane.debugpoint.toParent[3][1] = floor.y;
1486
- 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;
14871512
14881513 if (true) // slow && stepout && onein)
14891514 {
....@@ -1494,7 +1519,7 @@
14941519 // mywave = currentwave++;
14951520 // }
14961521 // sound
1497
- cVector eye = CameraPane.theRenderer.eyeCamera.location;
1522
+ cVector eye = Globals.theRenderer.EyeCamera().location;
14981523
14991524 // if (sourcenode.parent.parent != null)
15001525 // sourcenode.parent.parent.TransformToWorld(floor, tmp);
....@@ -1539,9 +1564,9 @@
15391564 //GraphreeD.
15401565 wav.play(volume * usedvolume); //, mywave);
15411566
1542
- lastsoundtime = CameraPane.framecount;
1567
+ lastsoundtime = Globals.framecount;
15431568
1544
- GrafreeD.hassound = true;
1569
+ Grafreed.hassound = true;
15451570 }
15461571 // else
15471572 // System.out.println("skipped");
....@@ -1560,9 +1585,9 @@
15601585
15611586 // System.out.println("Allo " + sourcenode);
15621587 // 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;
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;
15661591
15671592
15681593 if (false) // dist2 > 0.1)
....@@ -1628,9 +1653,9 @@
16281653 this.get(0).TransformToWorld(v0);
16291654
16301655 // cyan
1631
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1632
- CameraPane.debugpoint3.toParent[3][1] = ground;
1633
- 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;
16341659
16351660 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
16361661 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1640,9 +1665,9 @@
16401665 this.get(0).TransformToWorld(v0);
16411666
16421667 // red
1643
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1644
- CameraPane.debugpoint4.toParent[3][1] = ground;
1645
- 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;
16461671 }
16471672 }
16481673
....@@ -1682,11 +1707,11 @@
16821707
16831708 if (goal != null)
16841709 {
1685
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1710
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
16861711 //sourcenode.parent.parent.Dump();
1687
- goalx = goal.x;
1688
- goalz = goal.z;
1689
- targetx = targetz = 0;
1712
+ goalposx = goal.x;
1713
+ goalposz = goal.z;
1714
+ targetdirx = targetdirz = 0;
16901715
16911716 followpath = true;
16921717 }
....@@ -1737,16 +1762,16 @@
17371762 // }
17381763 if (false) // !uselast)
17391764 {
1740
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1741
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1742
- 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;
17431768 }
17441769 }
17451770
1746
- if (goalx != 0 || goalz != 0) // TODO
1771
+ if (goalposx != 0 || goalposz != 0) // TODO
17471772 {
17481773 // overwrite speaker orientation
1749
- dst.set(goalx,0,goalz);
1774
+ dst.set(goalposx,0,goalposz);
17501775 if (sourcenode.parent != null) // july 2014
17511776 sourcenode.parent.
17521777 TransformToLocal(dst);
....@@ -1798,26 +1823,26 @@
17981823 // mars 2014
17991824 if (false) // goalx != 0 || goalz != 0)
18001825 {
1801
- targetx = dst.x - src.x;
1802
- targetz = dst.z - src.z;
1826
+ targetdirx = dst.x - src.x;
1827
+ targetdirz = dst.z - src.z;
18031828
1804
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1829
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
18051830 {
18061831 // far enough from goal. keep the goal position.
1807
- targetx = 0;
1808
- targetz = 0;
1832
+ targetdirx = 0;
1833
+ targetdirz = 0;
18091834 }
18101835 else
18111836 {
18121837 // too close to goal. switch to target direction instead.
1813
- goalx = 0;
1814
- goalz = 0;
1838
+ goalposx = 0;
1839
+ goalposz = 0;
18151840 }
18161841 }
18171842
18181843 //sourcenode.getCentroid(src, true);
18191844
1820
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1845
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
18211846 {
18221847 if (ScriptNode.lastspeaker != null)
18231848 new Exception().printStackTrace();
....@@ -1826,13 +1851,13 @@
18261851
18271852 // LA.xformPos(src, fromParent, src);
18281853
1829
- 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)
18301855 dst.sub(src);
18311856 else
18321857 // vector mode
18331858 {
1834
- dst.x = targetx;
1835
- dst.z = targetz;
1859
+ dst.x = targetdirx;
1860
+ dst.z = targetdirz;
18361861
18371862 // TEST TARGET
18381863 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -2242,7 +2267,7 @@
22422267 }
22432268
22442269 if (!smoothed)
2245
- for (int i=0; --i>=0;)
2270
+ for (int i=10; --i>=0;)
22462271 SmoothAnimData(); // much reduces shakiness
22472272
22482273 smoothed = true;
....@@ -2280,9 +2305,16 @@
22802305 toVector.x = LA.cos(to);
22812306 toVector.y = LA.sin(to);
22822307
2308
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2309
+ double toA = Math.atan2(toVector.y, toVector.x);
2310
+
22832311 Vector2d currentVector = Slerp(fromVector, toVector, step);
22842312
2285
- 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;
22862318 }
22872319
22882320 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -3191,7 +3223,7 @@
31913223
31923224 // july 2014
31933225 // goalx = goalz = 0;
3194
- targetx = targetz = 0;
3226
+ targetdirx = targetdirz = 0;
31953227
31963228 //SetPositionDelta(true, true, true, false);
31973229 // LoadData();
....@@ -3220,12 +3252,13 @@
32203252
32213253 int step = 1;
32223254
3255
+ // patch for running hare
32233256 if (speedup) // fev 2014
32243257 step *= 2; // 4;
32253258 if (rewind) // mars 2014
32263259 step *= 4;
32273260
3228
- if (CameraPane.FAST) // && !CameraPane.HOLD)
3261
+ //if (CameraPane.FAST) // && !CameraPane.HOLD)
32293262 step *= CameraPane.STEP;
32303263
32313264 //System.err.println("Step Mocap frame # " + frame);
....@@ -3257,7 +3290,7 @@
32573290 "; fullname = " + fullname);
32583291
32593292 //int delta = frame - baseframe;
3260
- if (CameraPane.CROWD)
3293
+ if (Globals.CROWD)
32613294 {
32623295 baseframe = GetFirstFrame(); // 0 initial point
32633296 }
....@@ -3266,23 +3299,40 @@
32663299 // SetPositionDelta(false, true, false); // ?? false);
32673300 {
32683301 if (support == null)
3269
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3302
+ {
3303
+ if (new File(fullname).exists())
3304
+ ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3305
+ else
3306
+ {
3307
+ SetGlobalTransform();
3308
+ Rewind();
3309
+ Fade();
3310
+ }
3311
+ }
32703312 else
32713313 {
3272
- try
3273
- {
3314
+// try
3315
+// {
32743316 bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
32753317
32763318 // SetPositionDelta(false, true, true, true);
32773319 LoadData();
32783320 Rewind();
32793321 Fade();
3280
- }
3281
- catch (Exception e)
3282
- {
3283
- e.printStackTrace();
3284
- ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3285
- }
3322
+// }
3323
+// catch (Exception e)
3324
+// {
3325
+// System.err.println("An error occured while loading data. Use fallback by loading the file.");
3326
+// //e.printStackTrace();
3327
+// try
3328
+// {
3329
+// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest);
3330
+// }
3331
+// catch (Exception e2)
3332
+// {
3333
+// System.err.println("Motion file not found: " + fullname);
3334
+// }
3335
+// }
32863336 }
32873337 }
32883338
....@@ -3464,6 +3514,7 @@
34643514 // filters out bad input data
34653515 void FilterAnimData()
34663516 {
3517
+ new Exception().printStackTrace();
34673518 System.exit(0);
34683519
34693520 float[] data; // = bvh.animation.getBoneData(0);
....@@ -3821,7 +3872,7 @@
38213872
38223873 transient boolean restarted; // CROWD issue?
38233874
3824
- void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
3875
+ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
38253876 {
38263877 //System.err.println("drawSelf Mocap frame # " + frame);
38273878 //System.err.println("drawSelf Mocap baseframe # " + baseframe);
....@@ -3839,7 +3890,7 @@
38393890 // return;
38403891
38413892 if (!restarted && /*display.restartframe &&*/
3842
- display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK
3893
+ Globals.isLIVE() && live && display.DrawMode() == display.SHADOW) // FUCK
38433894 {
38443895 //display.restartframe = false;
38453896 restarted = true;
....@@ -3847,7 +3898,7 @@
38473898 }
38483899 else
38493900 {
3850
- if (display.isLIVE() && live && display.drawMode != display.SHADOW)
3901
+ if (Globals.isLIVE() && live && display.DrawMode() != display.SHADOW)
38513902 restarted = false;
38523903 }
38533904