Normand Briere
2018-07-03 02e145cb923d601395acc7f15ae9e13f85ef2fbb
Mocap.java
....@@ -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];
....@@ -476,6 +476,94 @@
476476 currenthip[i] = data[frame3 + i];
477477 }
478478 }
479
+
480
+ void SetHipOrientation()
481
+ {
482
+ Object3D hip = get(0);
483
+
484
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
485
+
486
+ cVector centroid = new cVector();
487
+ centroid.x = matrix[3][0];
488
+ centroid.y = matrix[3][1];
489
+ centroid.z = matrix[3][2];
490
+ this.getCentroid(centroid, true);
491
+
492
+ cVector goal = GetGoal(centroid);
493
+ if (goal != null)
494
+ {
495
+ System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalx + ", " + goalz + ")");
496
+
497
+ goalx = goal.x;
498
+ goalz = goal.z;
499
+ targetx = targetz = 0;
500
+ }
501
+
502
+ if (goalx == 0 && goalz == 0)
503
+ {
504
+ // No target
505
+ if (ScriptNode.speaker != null)
506
+ {
507
+ Object3D sourcenode = GetFileRoot();
508
+ Object3D speakernode = ScriptNode.speaker.GetFileRoot();
509
+
510
+ //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker);
511
+
512
+ Object3D speaker = ScriptNode.speaker;
513
+
514
+ if (speakernode == sourcenode)
515
+ {
516
+ if (ScriptNode.lastspeaker != null)
517
+ {
518
+ speakernode = ScriptNode.lastspeaker.GetFileRoot();
519
+ speaker = ScriptNode.lastspeaker;
520
+ }
521
+ else
522
+ return;
523
+ }
524
+
525
+ cVector dst = new cVector();
526
+
527
+ boolean success = speakernode.getCentroid(dst); // , true);
528
+
529
+ if (!success)
530
+ new Exception().printStackTrace();
531
+
532
+ //speakernode.parent.TransformToWorld(dst);
533
+ //sourcenode.parent.TransformToLocal(dst);
534
+ this.parent.TransformToLocal(dst);
535
+
536
+ goalx = dst.x;
537
+ goalz = dst.z;
538
+ }
539
+ else
540
+ return;
541
+ }
542
+
543
+ cVector temp = new cVector();
544
+
545
+ temp.x = 1;
546
+ temp.y = 0;
547
+ temp.z = 0;
548
+
549
+ LA.xformDir(temp, matrix, temp);
550
+
551
+ double angleYhip = Math.atan2(-temp.z, temp.x);
552
+
553
+ double angleYtarget = Math.atan2(goalx - centroid.x, goalz - centroid.z);
554
+
555
+ LA.matIdentity(matrix);
556
+ LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z);
557
+ double angle = CurveAngle(0, angleYtarget - angleYhip, 1); // 0.1f);
558
+ LA.matYRotate(matrix, angle);
559
+ LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z);
560
+
561
+ LA.matConcat(matrix, toParent, toParent);
562
+
563
+ LA.matInvert(toParent, fromParent);
564
+
565
+ CheckForAction(centroid);
566
+ }
479567
480568 void WriteTo(java.io.Writer writer) throws Exception
481569 {
....@@ -552,8 +640,8 @@
552640 double targetx;
553641 double targetz;
554642
555
- double goalx;
556
- double goalz;
643
+ double goalx = -20;
644
+ double goalz = -10;
557645
558646 boolean followpath;
559647
....@@ -910,6 +998,8 @@
910998 testvect.set(from);
911999 testvect.sub(fromto.from);
9121000
1001
+ testvect.y = 0; // PATCH
1002
+
9131003 int factor = 1;
9141004
9151005 //if (CameraPane.FAST)
....@@ -951,6 +1041,8 @@
9511041
9521042 testvect.set(from);
9531043 testvect.sub(fromto.from);
1044
+
1045
+ testvect.y = 0; // PATCH
9541046
9551047 int factor = 1;
9561048
....@@ -2243,6 +2335,8 @@
22432335 e.printStackTrace();
22442336 }
22452337
2338
+ SetHipOrientation();
2339
+
22462340 if (true)
22472341 return;
22482342
....@@ -2670,8 +2764,8 @@
26702764 // set rotation
26712765 //if (bone._rotationEnabled)
26722766 if (//frame > 0 &&
2673
- !bone.skipmocap //&&
2674
- //!bone.name.contains("head") &&
2767
+ !bone.skipmocap &&
2768
+ !bone.name.contains("head") // &&
26752769 // !bone.name.contains("rFoot") &&
26762770 // !bone.name.contains("lFoot") &&
26772771 // !bone.name.contains("Pinky") &&
....@@ -3096,7 +3190,7 @@
30963190 // LA.matIdentity(rot.fromParent);
30973191
30983192 // july 2014
3099
- goalx = goalz = 0;
3193
+// goalx = goalz = 0;
31003194 targetx = targetz = 0;
31013195
31023196 //SetPositionDelta(true, true, true, false);