Normand Briere
2018-07-03 02e145cb923d601395acc7f15ae9e13f85ef2fbb
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];
....@@ -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];
....@@ -470,6 +476,94 @@
470476 currenthip[i] = data[frame3 + i];
471477 }
472478 }
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
+ }
473567
474568 void WriteTo(java.io.Writer writer) throws Exception
475569 {
....@@ -546,8 +640,8 @@
546640 double targetx;
547641 double targetz;
548642
549
- double goalx;
550
- double goalz;
643
+ double goalx = -20;
644
+ double goalz = -10;
551645
552646 boolean followpath;
553647
....@@ -904,6 +998,8 @@
904998 testvect.set(from);
905999 testvect.sub(fromto.from);
9061000
1001
+ testvect.y = 0; // PATCH
1002
+
9071003 int factor = 1;
9081004
9091005 //if (CameraPane.FAST)
....@@ -945,6 +1041,8 @@
9451041
9461042 testvect.set(from);
9471043 testvect.sub(fromto.from);
1044
+
1045
+ testvect.y = 0; // PATCH
9481046
9491047 int factor = 1;
9501048
....@@ -2237,6 +2335,8 @@
22372335 e.printStackTrace();
22382336 }
22392337
2338
+ SetHipOrientation();
2339
+
22402340 if (true)
22412341 return;
22422342
....@@ -2664,8 +2764,8 @@
26642764 // set rotation
26652765 //if (bone._rotationEnabled)
26662766 if (//frame > 0 &&
2667
- !bone.skipmocap //&&
2668
- //!bone.name.contains("head") &&
2767
+ !bone.skipmocap &&
2768
+ !bone.name.contains("head") // &&
26692769 // !bone.name.contains("rFoot") &&
26702770 // !bone.name.contains("lFoot") &&
26712771 // !bone.name.contains("Pinky") &&
....@@ -3020,7 +3120,8 @@
30203120 }
30213121 }
30223122
3023
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3123
+ // skip initial "T"
3124
+ static int offset = 1; // 5; // 10; // 5; // 100;
30243125
30253126 void ReadBVH()
30263127 {
....@@ -3049,8 +3150,8 @@
30493150
30503151 void Reset()
30513152 {
3052
- if (fullname != null)
3053
- ReadBVH();
3153
+// if (fullname != null)
3154
+// ReadBVH();
30543155
30553156 Object3D hip = get(0);
30563157
....@@ -3089,7 +3190,7 @@
30893190 // LA.matIdentity(rot.fromParent);
30903191
30913192 // july 2014
3092
- goalx = goalz = 0;
3193
+// goalx = goalz = 0;
30933194 targetx = targetz = 0;
30943195
30953196 //SetPositionDelta(true, true, true, false);
....@@ -3132,7 +3233,7 @@
31323233 baseframe += step;
31333234
31343235 //frame = baseframe;
3135
- frame += step;
3236
+ //frame += step;
31363237
31373238 // if (frame != baseframe)
31383239 // {
....@@ -3184,13 +3285,17 @@
31843285 }
31853286 }
31863287 }
3288
+
3289
+ frame = GetFirstFrame();
31873290 }
3291
+ else
3292
+ frame += step;
31883293
31893294 //SetPositionDelta(false);
31903295
3191
- if (frame >= bvh.animation.getNumFrames())
3192
- //baseframe =
3193
- frame = GetFirstFrame(); // 0; // offset; // initial point
3296
+// if (frame >= bvh.animation.getNumFrames())
3297
+// //baseframe =
3298
+// frame = GetFirstFrame(); // 0; // offset; // initial point
31943299
31953300 //System.err.println("frame = " + frame);
31963301 if (lastframe != 0)