Normand Briere
2018-12-15 6ed65dcb597fb2153cef75bf1845978f1115658c
Mocap.java
....@@ -26,6 +26,568 @@
2626 public class Mocap extends Object3D
2727 {
2828 static final long serialVersionUID = 7437391692559853707L;
29
+
30
+ void Fade()
31
+ {
32
+ if (currentbones == null || CameraPane.fullreset)
33
+ return;
34
+
35
+ cVector temp = new cVector();
36
+
37
+ int numframes = bvh.animation.getNumFrames();
38
+
39
+ int b;
40
+ float[] data;
41
+ Quat4d quatstart = new Quat4d();
42
+ Quat4d quatend = new Quat4d();
43
+ Quat4d quat = new Quat4d();
44
+ Matrix4d mat4d = new Matrix4d();
45
+ double[][] rot = new double[4][4];
46
+ for (b=numbones; --b>=0;) // HIP ROTATION: 0;)
47
+ {
48
+ // int hipindex = get(0)._index;
49
+
50
+// assert(get(0).get(0)._isHip);
51
+
52
+ // if (b == hipindex)
53
+ // continue;
54
+
55
+ data = bvh.animation.getBoneData(b);
56
+
57
+ int dof = 3; // data.length/numframes;
58
+
59
+ if (b == 0)
60
+ {
61
+ dof = 6;
62
+ }
63
+ // assert(dof == 3);
64
+
65
+ int boneframe3 = (b-1)*3; // dof;
66
+
67
+ // System.err.println("Bone #" + b + ": dof = " + dof);
68
+ int fadein = 45; // 120;
69
+
70
+ // if (b == hipindex)
71
+ // fadein *= 5;
72
+
73
+ if (fadein > numframes)
74
+ fadein = 0; // numframes;
75
+
76
+ for (int fi=fadein; --fi>=0;)
77
+ //for (int f=numframes; --f>=0;)
78
+ {
79
+ int f = fi + GetFirstFrame();
80
+
81
+ int f3 = f*dof;
82
+
83
+ float k = fi;
84
+
85
+ k /= fadein - 1;
86
+
87
+ if (Float.isNaN(k))
88
+ k = 1; // 0/0
89
+
90
+ k = (float) (-Math.cos(k*Math.PI));
91
+ k += 1;
92
+ k /= 2;
93
+
94
+ int start = 3;
95
+ int end = 0;
96
+
97
+ if (dof == 6)
98
+ {
99
+ start = 6;
100
+ end = 3;
101
+ }
102
+
103
+ if (b == 0)
104
+ {
105
+ for (int i=start; --i>=end;)
106
+ {
107
+ //data[f3 + i] += pos[i] - data[frame3 + i];
108
+// data[f3 + i] = k*data[f3+i] + (1-k)*
109
+// currentbones[boneframe3 + i-end];
110
+// data[f3 + i] = (float)CurveAngle(data[f3+i], currenthip[i], 1-k);
111
+ }
112
+
113
+ // TODO: translation
114
+
115
+// _t1.setIdentity();
116
+// _t2.setIdentity();
117
+// _t2.rotZ(currentbones[boneframe3 + start-1-end]);
118
+// _t1.mul(_t2);
119
+// _t2.setIdentity();
120
+// if (b == 0)
121
+// {
122
+// _t2.rotY(currentbones[boneframe3 + start-2-end]);
123
+// _t1.mul(_t2);
124
+// _t2.setIdentity();
125
+// _t2.rotX(currentbones[boneframe3 + start-3-end]);
126
+// }
127
+// else
128
+// {
129
+// _t2.rotX(currentbones[boneframe3 + start-2-end]);
130
+// _t1.mul(_t2);
131
+// _t2.setIdentity();
132
+// _t2.rotY(currentbones[boneframe3 + start-3-end]);
133
+// }
134
+// _t1.mul(_t2);
135
+// _t2.setIdentity();
136
+//
137
+// _t1.get(mat4d);
138
+//
139
+// mat4d.get(quatstart);
140
+//
141
+// _t1.setIdentity();
142
+// _t2.setIdentity();
143
+// _t2.rotZ(data[f3 + start-1]);
144
+// _t1.mul(_t2);
145
+// _t2.setIdentity();
146
+// if (b == 0)
147
+// {
148
+// _t2.rotY(data[f3 + start-2]);
149
+// _t1.mul(_t2);
150
+// _t2.setIdentity();
151
+// _t2.rotX(data[f3 + start-3]);
152
+// }
153
+// else
154
+// {
155
+// _t2.rotX(data[f3 + start-2]);
156
+// _t1.mul(_t2);
157
+// _t2.setIdentity();
158
+// _t2.rotY(data[f3 + start-3]);
159
+// }
160
+//
161
+// _t1.mul(_t2);
162
+// _t2.setIdentity();
163
+//
164
+// _t1.get(mat4d);
165
+//
166
+// mat4d.get(quatend);
167
+//
168
+// double dot = quatstart.x*quatend.x +
169
+// quatstart.y*quatend.y +
170
+// quatstart.z*quatend.z +
171
+// quatstart.w*quatend.w
172
+// ;
173
+//
174
+// if (dot < 0)
175
+// {
176
+// quatend.x *= -1;
177
+// quatend.y *= -1;
178
+// quatend.z *= -1;
179
+// quatend.w *= -1;
180
+// }
181
+//
182
+// // k = 1-k;
183
+//
184
+// quat.x = (1-k)*quatstart.x + k*quatend.x;
185
+// quat.y = (1-k)*quatstart.y + k*quatend.y;
186
+// quat.z = (1-k)*quatstart.z + k*quatend.z;
187
+// quat.w = (1-k)*quatstart.w + k*quatend.w;
188
+//
189
+// quat.normalize();
190
+//
191
+// mat4d.set(quat);
192
+//
193
+// cJ3D.SetTransform(rot, mat4d);
194
+//
195
+// matrixToEulerXYZ(rot, temp);
196
+//
197
+// data[f3 + start-1] = -(float)temp.z;
198
+//
199
+// if (b == 0)
200
+// {
201
+// data[f3 + start-2] = -(float)temp.y;
202
+// data[f3 + start-3] = -(float)temp.x;
203
+// }
204
+// else
205
+// {
206
+// data[f3 + start-2] = -(float)temp.x;
207
+// data[f3 + start-3] = -(float)temp.y;
208
+// }
209
+ }
210
+ else
211
+ {
212
+ for (int i=start; --i>=end;)
213
+ {
214
+ //data[f3 + i] += pos[i] - data[frame3 + i];
215
+// data[f3 + i] = k*data[f3+i] + (1-k)*
216
+// currentbones[boneframe3 + i-end];
217
+ data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i/*-end*/], 1-k);
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+
224
+ // Updates the toParent matrix to keep the same position and orientation
225
+ // before resetting the mocap data.
226
+ void SetGlobalTransform()
227
+ {
228
+ //SetCurrentBones(frame);
229
+
230
+ cVector temp = new cVector();
231
+ cVector pos = new cVector();
232
+ cVector poship = new cVector();
233
+
234
+ double angleY = 0;
235
+ double angleYhip = 0;
236
+
237
+ 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
+ }
244
+
245
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
246
+ poship.x = matrix[3][0];
247
+ poship.y = matrix[3][1];
248
+ poship.z = matrix[3][2];
249
+
250
+ temp.x = 1;
251
+ temp.y = 0;
252
+ temp.z = 0;
253
+
254
+ LA.xformDir(temp, matrix, temp);
255
+
256
+ angleYhip = Math.atan2(-temp.z, temp.x);
257
+
258
+ LA.matIdentity(toParent);
259
+ LA.matYRotate(toParent, angleYhip);
260
+ LA.matTranslate(toParent, poship.x, poship.y, poship.z);
261
+
262
+// LA.matConcat(toParent, hip.get(0).toParent, toParent);
263
+
264
+ CameraPane.debugpointG.toParent[3][0] = poship.x;
265
+ CameraPane.debugpointG.toParent[3][1] = poship.y;
266
+ CameraPane.debugpointG.toParent[3][2] = poship.z;
267
+
268
+ LA.matInvert(toParent, fromParent);
269
+
270
+ LA.matIdentity(hip.get(0).toParent);
271
+ LA.matIdentity(hip.get(0).fromParent);
272
+
273
+// if (true)
274
+// return;
275
+
276
+ // Updates hip.get(0).toParent
277
+ setPose(hip, GetFirstFrame(), bvh.animation.getBoneData(hip._index));
278
+
279
+ // A = toParent; B = hip.get(0).toParent
280
+ // A'*B = A
281
+ // A' = A * B-1
282
+
283
+ poship.x = hip.get(0).toParent[3][0];
284
+ poship.y = hip.get(0).toParent[3][1];
285
+ 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);
294
+
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);
301
+
302
+ //LA.matIdentity(matrix);
303
+ //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z);
304
+
305
+ LA.matConcat(toParent, matrix, toParent);
306
+
307
+
308
+ LA.matConcat(toParent, hip.get(0).toParent, matrix);
309
+ pos.x = hip.get(0).toParent[3][0];
310
+ pos.y = hip.get(0).toParent[3][1];
311
+ pos.z = hip.get(0).toParent[3][2];
312
+ LA.xformPos(new cVector(), hip.get(0).toParent, pos);
313
+ LA.xformPos(pos, toParent, pos);
314
+
315
+// temp.x = 1;
316
+// temp.y = 0;
317
+// temp.z = 0;
318
+//
319
+// LA.xformDir(temp, toParent, temp);
320
+//
321
+// angleY = Math.atan2(-temp.z, temp.x);
322
+//
323
+// LA.matIdentity(toParent);
324
+// LA.matYRotate(toParent, angleY - angleYhip);
325
+// LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z);
326
+
327
+ CameraPane.debugpointP.toParent[3][0] = pos.x;
328
+ CameraPane.debugpointP.toParent[3][1] = pos.y;
329
+ CameraPane.debugpointP.toParent[3][2] = pos.z;
330
+
331
+ CameraPane.debugpointC.toParent[3][0] = poship.x;
332
+ CameraPane.debugpointC.toParent[3][1] = poship.y;
333
+ CameraPane.debugpointC.toParent[3][2] = poship.z;
334
+
335
+ poship.x = toParent[3][0];
336
+ poship.y = toParent[3][1];
337
+ poship.z = toParent[3][2];
338
+
339
+ CameraPane.debugpointR.toParent[3][0] = poship.x;
340
+ CameraPane.debugpointR.toParent[3][1] = poship.y;
341
+ CameraPane.debugpointR.toParent[3][2] = poship.z;
342
+
343
+ LA.matInvert(toParent, fromParent);
344
+ }
345
+
346
+ void LoadData()
347
+ {
348
+ float[] thedata = bvh.animation.getBoneData(0);
349
+
350
+// thedata[0] = 0;
351
+// thedata[1] = 0;
352
+// thedata[2] = 0;
353
+// thedata[3] = 0;
354
+// thedata[4] = 0;
355
+// thedata[5] = 0;
356
+
357
+ if (true)
358
+ return;
359
+
360
+ for (int b=numbones; --b>=0;)
361
+ //int b = 0;
362
+ {
363
+ thedata = bvh.animation.getBoneData(b);
364
+
365
+ int numframes = bvh.animation.getNumFrames();
366
+
367
+ int dof = 6; // thedata.length/numframes;
368
+
369
+ if (b > 0)
370
+ dof = 3;
371
+
372
+ if (dof != thedata.length/numframes)
373
+ {
374
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
375
+ dof = thedata.length/numframes;
376
+ }
377
+
378
+ //for (int f=numframes; --f>=offset;)
379
+ int firstframe = GetFirstFrame();
380
+ for (int f=0; f<numframes-firstframe; f++)
381
+ {
382
+ int f3 = f*dof;
383
+
384
+ //for (int i=3/*dof*/; --i>=0;)
385
+ for (int i=dof; --i>=0;)
386
+ {
387
+ //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
388
+ thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
389
+ }
390
+ }
391
+ }
392
+ }
393
+
394
+ void ResetZero()
395
+ {
396
+ for (int b=numbones; --b>=0;)
397
+ {
398
+ float[] thedata = bvh.animation.getBoneData(b);
399
+
400
+ int numframes = bvh.animation.getNumFrames();
401
+
402
+ int dof = 6;
403
+
404
+ if (b > 0)
405
+ dof = 3;
406
+
407
+ for (int i=dof; --i>=0;)
408
+ {
409
+ thedata[i] = 0;
410
+ }
411
+ }
412
+ }
413
+
414
+ void SetCurrentBones(int frame)
415
+ {
416
+ if (frame == 0)
417
+ {
418
+ //frame = 1;
419
+ }
420
+
421
+ if (currentbones == null)
422
+ {
423
+ currentbones = new double[(numbones-1)*3];
424
+ currenthip = new double[6];
425
+ }
426
+
427
+ for (int b=numbones; --b>=1;) // HIP ROTATION: 0;)
428
+ //int b = 0;
429
+ {
430
+ float[] data = bvh.animation.getBoneData(b);
431
+
432
+ // int numframes = bvh.animation.getNumFrames();
433
+
434
+ int dof = 6; // data.length/numframes;
435
+
436
+ if (b > 0)
437
+ dof = 3;
438
+
439
+ //assert(dof == 3);
440
+
441
+ // System.err.println("Bone #" + b + ": dof = " + dof);
442
+ int theframe = // 1; // baseframe;
443
+ frame;
444
+
445
+ int frame3 = theframe*dof;
446
+ int bone3 = (b-1)*dof;
447
+
448
+ int start = 3;
449
+ int end = 0;
450
+
451
+ if (dof == 6)
452
+ {
453
+ start = 6;
454
+ //end = 3;
455
+ }
456
+
457
+ for (int i=start; --i>=end;)
458
+ {
459
+ currentbones[bone3 + i/*-end*/] = data[frame3 + i];
460
+ }
461
+ }
462
+
463
+ float[] data = bvh.animation.getBoneData(0);
464
+
465
+ int dof = 6;
466
+
467
+ int theframe = frame;
468
+
469
+ int frame3 = theframe*dof;
470
+
471
+ int start = 6;
472
+ int end = 0;
473
+
474
+ for (int i=start; --i>=end;)
475
+ {
476
+ currenthip[i] = data[frame3 + i];
477
+ }
478
+ }
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
+ }
29591
30592 void WriteTo(java.io.Writer writer) throws Exception
31593 {
....@@ -99,11 +661,11 @@
99661 double pinx;
100662 double pinz;
101663
102
- double targetx;
103
- double targetz;
664
+ double targetdirx;
665
+ double targetdirz;
104666
105
- double goalx;
106
- double goalz;
667
+ double goalposx = -20;
668
+ double goalposz = -10;
107669
108670 boolean followpath;
109671
....@@ -174,7 +736,7 @@
174736 scriptactions.clear();
175737 }
176738
177
- static double EPSACTION = 0.1; // 0.075; // 0.1;
739
+ static double EPSACTION = 0.1; // 0.075; // 0.1;Came
178740
179741 void AddFromTo(cVector from, cVector to)
180742 {
....@@ -460,6 +1022,8 @@
4601022 testvect.set(from);
4611023 testvect.sub(fromto.from);
4621024
1025
+ testvect.y = 0; // PATCH
1026
+
4631027 int factor = 1;
4641028
4651029 //if (CameraPane.FAST)
....@@ -501,6 +1065,8 @@
5011065
5021066 testvect.set(from);
5031067 testvect.sub(fromto.from);
1068
+
1069
+ testvect.y = 0; // PATCH
5041070
5051071 int factor = 1;
5061072
....@@ -705,7 +1271,7 @@
7051271 // skip first node: translation
7061272 // Object3D b = input.get(0);
7071273
708
- setPose(input, f, data.getBoneData(input._index), false); //, null);
1274
+ setPose(input, f, data.getBoneData(input._index)); //, false); //, null);
7091275 }
7101276
7111277 //mocap.figure.Bone[] children = b.getChildren();
....@@ -736,6 +1302,7 @@
7361302
7371303 void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid)
7381304 {
1305
+ assert(false);
7391306 //assert(CameraPane.drawMode == CameraPane.SHADOW);
7401307
7411308 Object3D transformnode = new Object3D();
....@@ -921,7 +1488,7 @@
9211488 //groundz += sourcenode.parent.toParent[3][2] - posz;
9221489 }
9231490
924
- boolean footcontact = CameraPane.FOOTCONTACT; // false;
1491
+ boolean footcontact = false; // CameraPane.FOOTCONTACT; // false;
9251492
9261493 if (footcontact && ground != -123456)
9271494 {
....@@ -939,9 +1506,9 @@
9391506 groundid = floorid;
9401507
9411508 // green
942
- CameraPane.debugpoint.toParent[3][0] = groundx;
943
- CameraPane.debugpoint.toParent[3][1] = floor.y;
944
- 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;
9451512
9461513 if (true) // slow && stepout && onein)
9471514 {
....@@ -1018,9 +1585,9 @@
10181585
10191586 // System.out.println("Allo " + sourcenode);
10201587 // purple
1021
- CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx;
1022
- CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1];
1023
- 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;
10241591
10251592
10261593 if (false) // dist2 > 0.1)
....@@ -1086,9 +1653,9 @@
10861653 this.get(0).TransformToWorld(v0);
10871654
10881655 // cyan
1089
- CameraPane.debugpoint3.toParent[3][0] = v0.x;
1090
- CameraPane.debugpoint3.toParent[3][1] = ground;
1091
- 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;
10921659
10931660 LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent);
10941661 LA.matInvert(sourcenode.toParent, sourcenode.fromParent);
....@@ -1098,9 +1665,9 @@
10981665 this.get(0).TransformToWorld(v0);
10991666
11001667 // red
1101
- CameraPane.debugpoint4.toParent[3][0] = v0.x;
1102
- CameraPane.debugpoint4.toParent[3][1] = ground;
1103
- 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;
11041671 }
11051672 }
11061673
....@@ -1140,11 +1707,11 @@
11401707
11411708 if (goal != null)
11421709 {
1143
- System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")");
1710
+ System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")");
11441711 //sourcenode.parent.parent.Dump();
1145
- goalx = goal.x;
1146
- goalz = goal.z;
1147
- targetx = targetz = 0;
1712
+ goalposx = goal.x;
1713
+ goalposz = goal.z;
1714
+ targetdirx = targetdirz = 0;
11481715
11491716 followpath = true;
11501717 }
....@@ -1195,16 +1762,16 @@
11951762 // }
11961763 if (false) // !uselast)
11971764 {
1198
- CameraPane.debugpoint.toParent[3][0] = dst.x;
1199
- CameraPane.debugpoint.toParent[3][1] = dst.y;
1200
- 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;
12011768 }
12021769 }
12031770
1204
- if (goalx != 0 || goalz != 0) // TODO
1771
+ if (goalposx != 0 || goalposz != 0) // TODO
12051772 {
12061773 // overwrite speaker orientation
1207
- dst.set(goalx,0,goalz);
1774
+ dst.set(goalposx,0,goalposz);
12081775 if (sourcenode.parent != null) // july 2014
12091776 sourcenode.parent.
12101777 TransformToLocal(dst);
....@@ -1220,6 +1787,7 @@
12201787 src.x = 0;
12211788 src.y = 0;
12221789 src.z = 0;
1790
+ LA.xformPos(src, get(0).get(0).toParent, src);
12231791 LA.xformPos(src, get(0).toParent, src);
12241792 LA.xformPos(src, toParent, src);
12251793 // LA.xformPos(src, rotsourcenode.toParent, src);
....@@ -1255,26 +1823,26 @@
12551823 // mars 2014
12561824 if (false) // goalx != 0 || goalz != 0)
12571825 {
1258
- targetx = dst.x - src.x;
1259
- targetz = dst.z - src.z;
1826
+ targetdirx = dst.x - src.x;
1827
+ targetdirz = dst.z - src.z;
12601828
1261
- if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1)
1829
+ if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1)
12621830 {
12631831 // far enough from goal. keep the goal position.
1264
- targetx = 0;
1265
- targetz = 0;
1832
+ targetdirx = 0;
1833
+ targetdirz = 0;
12661834 }
12671835 else
12681836 {
12691837 // too close to goal. switch to target direction instead.
1270
- goalx = 0;
1271
- goalz = 0;
1838
+ goalposx = 0;
1839
+ goalposz = 0;
12721840 }
12731841 }
12741842
12751843 //sourcenode.getCentroid(src, true);
12761844
1277
- if (speakernode == sourcenode && goalx == 0 && goalz == 0)
1845
+ if (speakernode == sourcenode && goalposx == 0 && goalposz == 0)
12781846 {
12791847 if (ScriptNode.lastspeaker != null)
12801848 new Exception().printStackTrace();
....@@ -1283,13 +1851,13 @@
12831851
12841852 // LA.xformPos(src, fromParent, src);
12851853
1286
- 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)
12871855 dst.sub(src);
12881856 else
12891857 // vector mode
12901858 {
1291
- dst.x = targetx;
1292
- dst.z = targetz;
1859
+ dst.x = targetdirx;
1860
+ dst.z = targetdirz;
12931861
12941862 // TEST TARGET
12951863 // dst.x = CameraPane.selectedpoint.toParent[3][0];
....@@ -1563,6 +2131,7 @@
15632131 toParent = LA.newMatrix();
15642132 fromParent = LA.newMatrix();
15652133 }
2134
+
15662135 LA.matConcat(toParent, rotsourcenode.toParent, toParent);
15672136 LA.matInvert(toParent, fromParent);
15682137
....@@ -1698,7 +2267,7 @@
16982267 }
16992268
17002269 if (!smoothed)
1701
- for (int i=4; --i>=0;)
2270
+ for (int i=0; --i>=0;)
17022271 SmoothAnimData(); // much reduces shakiness
17032272
17042273 smoothed = true;
....@@ -1736,9 +2305,16 @@
17362305 toVector.x = LA.cos(to);
17372306 toVector.y = LA.sin(to);
17382307
2308
+ double fromA = Math.atan2(fromVector.y, fromVector.x);
2309
+ double toA = Math.atan2(toVector.y, toVector.x);
2310
+
17392311 Vector2d currentVector = Slerp(fromVector, toVector, step);
17402312
1741
- 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;
17422318 }
17432319
17442320 public static Vector2d Slerp(Vector2d from, Vector2d to, double step)
....@@ -1780,12 +2356,28 @@
17802356 if (!live) // aout 2013
17812357 return;
17822358
1783
- cVector centroid = new cVector();
1784
- cVector floor = new cVector();
1785
-
1786
- Object3D sourcenode = GetFileRoot();
2359
+ //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
2360
+ try
2361
+ {
2362
+ SetPose(GetSkeleton(), bvh.animation, f);
2363
+ SetCurrentBones(frame);
2364
+ }
2365
+ catch (Exception e)
2366
+ {
2367
+ e.printStackTrace();
2368
+ }
17872369
1788
- boolean success; // = sourcenode.getCentroid(centroid);
2370
+ SetHipOrientation();
2371
+
2372
+ if (true)
2373
+ return;
2374
+
2375
+ cVector centroid = new cVector();
2376
+ cVector floor = new cVector();
2377
+
2378
+ Object3D sourcenode = GetFileRoot();
2379
+
2380
+ boolean success; // = sourcenode.getCentroid(centroid);
17892381 // if (!success)
17902382 // {
17912383 // //assert(success);
....@@ -1793,16 +2385,6 @@
17932385 // System.out.println("No centroid for " + sourcenode);
17942386 // }
17952387
1796
- //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null);
1797
- try
1798
- {
1799
- SetPose(GetSkeleton(), bvh.animation, f);
1800
- }
1801
- catch (Exception e)
1802
- {
1803
- e.printStackTrace();
1804
- }
1805
-
18062388 if (sourcenode.parent == null && sourcenode.fileparent == null)
18072389 {
18082390 // No GFD
....@@ -2050,7 +2632,7 @@
20502632 * @param frame
20512633 * Frame number
20522634 */
2053
- public void setPose(Object3D bone, int frame, float[] data, boolean fade) //, Point3d offsetTrans)
2635
+ public void setPose(Object3D bone, int frame, float[] data) //, boolean fade) //, Point3d offsetTrans)
20542636 {
20552637 if (!live) // aout 2013
20562638 return;
....@@ -2058,6 +2640,33 @@
20582640 cVector temp = new cVector();
20592641 cVector temp0 = new cVector();
20602642 double pos[] = new double[3];
2643
+ double angleY = 0;
2644
+ double sinY = 0;
2645
+ double cosY = 0;
2646
+
2647
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
2648
+ {
2649
+ bone.get(0).GlobalTransformInv();
2650
+
2651
+ temp.x = bone.get(0).globalTransform[3][0];
2652
+ temp.y = bone.get(0).globalTransform[3][1];
2653
+ temp.z = bone.get(0).globalTransform[3][2];
2654
+
2655
+ pos[0] = temp.x;
2656
+ pos[1] = temp.y;
2657
+ pos[2] = temp.z;
2658
+
2659
+ temp.x = 1;
2660
+ temp.y = 0;
2661
+ temp.z = 0;
2662
+
2663
+ LA.xformDir(temp, bone.get(0).globalTransform, temp);
2664
+
2665
+ sinY = temp.z;
2666
+ cosY = temp.x;
2667
+
2668
+ angleY = Math.atan2(-sinY, cosY);
2669
+ }
20612670
20622671 // Object3D obj = get(0);
20632672 // Object3D gp = this.parent;
....@@ -2188,14 +2797,14 @@
21882797 //if (bone._rotationEnabled)
21892798 if (//frame > 0 &&
21902799 !bone.skipmocap &&
2191
- !bone.name.contains("head") &&
2800
+ !bone.name.contains("head") // &&
21922801 // !bone.name.contains("rFoot") &&
21932802 // !bone.name.contains("lFoot") &&
2194
- !bone.name.contains("Pinky") &&
2195
- !bone.name.contains("Ring") &&
2196
- !bone.name.contains("Mid") &&
2197
- !bone.name.contains("Index") &&
2198
- !bone.name.contains("Thumb")
2803
+// !bone.name.contains("Pinky") &&
2804
+// !bone.name.contains("Ring") &&
2805
+// !bone.name.contains("Mid") &&
2806
+// !bone.name.contains("Index") &&
2807
+// !bone.name.contains("Thumb")
21992808 )
22002809 {
22012810 //_rotTG.setTransform(_t1);
....@@ -2228,15 +2837,17 @@
22282837 // CROWD
22292838 //cJ3D.GetTranslation(bone, _trans0);
22302839 //_trans.add(_trans0);
2231
- _transTF.setIdentity();
2840
+ //_transTF.setIdentity();
2841
+ _transTF.set(_t1);
22322842 _transTF.setTranslation(_trans);
22332843 // System.err.println("Translate: " + _transTF);
22342844 //_transTG.setTransform(_transTF);
2235
- cJ3D.ResetTransform(bone, _transTF, true); // translation node
2845
+ cJ3D.ResetTransform(bone.get(0), _transTF, true); // translation node
2846
+ //cJ3D.ResetTransform(bone, _transTF, true); // translation node
22362847 }
22372848 }
22382849
2239
- if (bone._isRoot && firsttimeafterload && frame > 0)
2850
+ if (false) // bone._isRoot && firsttimeafterload && frame > 0)
22402851 {
22412852 assert(bone == get(0));
22422853
....@@ -2252,17 +2863,17 @@
22522863 // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1
22532864 //
22542865
2255
- Invariants();
2256
- bone.Invariants();
2257
- bone.get(0).Invariants();
2258
- // if (origin == null)
2259
- // origin = null;
2260
- origin.Invariants();
2261
- origin0.Invariants();
2866
+ Invariants();
2867
+ bone.Invariants();
2868
+ bone.get(0).Invariants();
2869
+ // if (origin == null)
2870
+ // origin = null;
2871
+ origin.Invariants();
2872
+ origin0.Invariants();
22622873
2263
-
2264
- LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2265
- LA.matConcat(origin.toParent, tempmatrix, toParent);
2874
+
2875
+//?? LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C'
2876
+//?? LA.matConcat(origin.toParent, tempmatrix, toParent);
22662877
22672878 // matrixToEulerXYZ(toParent, temp);
22682879 // matrixToEulerXYZ(bone.get(0).toParent, temp);
....@@ -2296,7 +2907,7 @@
22962907 //
22972908 // mat4d.get(quat);
22982909
2299
- if (true) // hip correction
2910
+ if (false) // hip correction
23002911 {
23012912 _t2.setIdentity();
23022913
....@@ -2337,13 +2948,13 @@
23372948 //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C'
23382949 // LA.matConcat(origin.fromParent, tempmatrix, fromParent);
23392950
2340
- LA.matInvert(toParent, fromParent);
2951
+//?? LA.matInvert(toParent, fromParent);
23412952
2342
- Invariants();
2343
- bone.Invariants();
2344
- bone.get(0).Invariants();
2345
- origin.Invariants();
2346
- origin0.Invariants();
2953
+ Invariants();
2954
+ bone.Invariants();
2955
+ bone.get(0).Invariants();
2956
+ origin.Invariants();
2957
+ origin0.Invariants();
23472958
23482959 // LA.matInvert(fromParent, tempmatrix);
23492960 //
....@@ -2364,33 +2975,39 @@
23642975 // temp.x = data[0];
23652976 // temp.y = data[1];
23662977 // temp.z = data[2];
2367
- LA.xformPos(temp, origin0.toParent, temp0);
2978
+ LA.xformPos(temp, origin0.toParent, temp0); // NU
23682979
2369
-// bone.GlobalTransformInv();
2370
-
2371
- temp0.x = bone.globalTransform[3][0];
2372
- temp0.y = bone.globalTransform[3][1];
2373
- temp0.z = bone.globalTransform[3][2];
2374
-
2980
+// bone.get(0).GlobalTransformInv();
2981
+//
2982
+// temp0.x = bone.get(0).globalTransform[3][0];
2983
+// temp0.y = bone.get(0).globalTransform[3][1];
2984
+// temp0.z = bone.get(0).globalTransform[3][2];
2985
+//
23752986 // MEGA TEST // june 2014: necessary for precision? otherwise comment works
2376
-fromParent[3][0] = 0;
2377
-fromParent[3][1] = 0;
2378
-fromParent[3][2] = 0;
2379
-LA.matInvert(fromParent, toParent);
2987
+//fromParent[3][0] = 0;
2988
+//fromParent[3][1] = 0;
2989
+//fromParent[3][2] = 0;
2990
+//LA.matInvert(fromParent, toParent);
23802991
2381
- LA.xformPos(temp0, fromParent, temp);
2992
+ LA.xformPos(temp0, fromParent, temp); // NU
23822993 //LA.xformPos(temp, bone.fromParent, temp);
23832994 // float[] data;
23842995
2385
- pos[0] = temp.x;
2386
- pos[1] = temp.y;
2387
- pos[2] = temp.z;
2996
+// pos[0] = temp.x;
2997
+// pos[1] = temp.y;
2998
+// pos[2] = temp.z;
2999
+//
3000
+// temp.x = 1;
3001
+// temp.y = 0;
3002
+// temp.z = 0;
3003
+//
3004
+// LA.xformDir(temp, bone.get(0).globalTransform, temp);
23883005
23893006 // CameraPane.selectedpoint.toParent[3][0] = temp0.x;
23903007 // CameraPane.selectedpoint.toParent[3][1] = temp0.y;
23913008 // CameraPane.selectedpoint.toParent[3][2] = temp0.z;
23923009
2393
- int numframes = bvh.animation.getNumFrames();
3010
+ int numframes = bvh.animation.getNumFrames();
23943011
23953012 int b = 0;
23963013 {
....@@ -2398,12 +3015,12 @@
23983015
23993016 int dof = 6; /// data.length/numframes;
24003017
2401
- // july 2014
2402
- if (dof != data.length/numframes)
2403
- {
2404
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
2405
- dof = data.length/numframes;
2406
- }
3018
+ // july 2014
3019
+ if (dof != data.length/numframes)
3020
+ {
3021
+ System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes));
3022
+ dof = data.length/numframes;
3023
+ }
24073024
24083025
24093026 int theframe = 0; // baseframe;
....@@ -2455,17 +3072,26 @@
24553072 // }
24563073 // }
24573074
2458
- data[f3 + i] += pos[i] - data[frame3 + i];
3075
+ data[f3 + i] += /*pos[i]*/ - data[frame3 + i];
24593076
24603077 // if (f < 3)
24613078 // {
24623079 // System.out.print(data[f3 + i] + " ");
24633080 // }
24643081 }
2465
-// if (f < 3)
2466
-// {
2467
-// System.out.println();
2468
-// }
3082
+
3083
+ double t1 = data[f3 + 0];
3084
+ double t2 = data[f3 + 2];
3085
+
3086
+ data[f3 + 0] = (float)(cosY*t1 - sinY*t2);
3087
+ data[f3 + 2] = (float)(sinY*t1 + cosY*t2);
3088
+
3089
+ for (int i=3/*dof*/; --i>=0;)
3090
+ {
3091
+ data[f3 + i] += pos[i];
3092
+ }
3093
+
3094
+ data[f3 + 4] += angleY - data[frame3 + 4];
24693095 }
24703096 }
24713097
....@@ -2479,186 +3105,17 @@
24793105 // temp.y = data[1];
24803106 // temp.z = data[2];
24813107
2482
- if (fade && currentbones != null && !CameraPane.fullreset)
2483
- {
2484
- Quat4d quatstart = new Quat4d();
2485
- Quat4d quatend = new Quat4d();
2486
- Quat4d quat = new Quat4d();
2487
- Matrix4d mat4d = new Matrix4d();
2488
- double[][] rot = new double[4][4];
2489
-
2490
- for (b=numbones; --b>=1;) // HIP ROTATION: 0;)
2491
- {
2492
- int hipindex = get(0)._index;
2493
-
2494
-// assert(get(0).get(0)._isHip);
2495
-
2496
- // if (b == hipindex)
2497
- // continue;
2498
-
2499
- data = bvh.animation.getBoneData(b);
2500
-
2501
- int dof = 3; // data.length/numframes;
2502
-
2503
- // assert(dof == 3);
2504
-
2505
- int boneframe3 = b*3; // dof;
2506
-
2507
- // System.err.println("Bone #" + b + ": dof = " + dof);
2508
- int fadein = 45; // 120;
2509
-
2510
- // if (b == hipindex)
2511
- // fadein *= 5;
2512
-
2513
- if (fadein > numframes)
2514
- fadein = 0; // numframes;
2515
-
2516
- for (int fi=fadein; --fi>=0;)
2517
- //for (int f=numframes; --f>=0;)
2518
- {
2519
- int f = fi + GetFirstFrame();
2520
-
2521
- int f3 = f*dof;
2522
-
2523
- float k = fi;
2524
-
2525
- k /= fadein - 1;
2526
-
2527
- if (Float.isNaN(k))
2528
- k = 1; // 0/0
2529
-
2530
- k = (float) (-Math.cos(k*Math.PI));
2531
- k += 1;
2532
- k /= 2;
2533
-
2534
- int start = 3;
2535
- int end = 0;
2536
-
2537
- if (dof == 6)
2538
- {
2539
- start = 6;
2540
- end = 3;
2541
- }
2542
-
2543
- if (b == 0)
2544
- {
2545
- _t1.setIdentity();
2546
- _t2.setIdentity();
2547
- _t2.rotZ(currentbones[boneframe3 + start-1-end]);
2548
- _t1.mul(_t2);
2549
- _t2.setIdentity();
2550
- if (b == 0)
2551
- {
2552
- _t2.rotY(currentbones[boneframe3 + start-2-end]);
2553
- _t1.mul(_t2);
2554
- _t2.setIdentity();
2555
- _t2.rotX(currentbones[boneframe3 + start-3-end]);
2556
- }
2557
- else
2558
- {
2559
- _t2.rotX(currentbones[boneframe3 + start-2-end]);
2560
- _t1.mul(_t2);
2561
- _t2.setIdentity();
2562
- _t2.rotY(currentbones[boneframe3 + start-3-end]);
2563
- }
2564
- _t1.mul(_t2);
2565
- _t2.setIdentity();
2566
-
2567
- _t1.get(mat4d);
2568
-
2569
- mat4d.get(quatstart);
2570
-
2571
- _t1.setIdentity();
2572
- _t2.setIdentity();
2573
- _t2.rotZ(data[f3 + start-1]);
2574
- _t1.mul(_t2);
2575
- _t2.setIdentity();
2576
- if (b == 0)
2577
- {
2578
- _t2.rotY(data[f3 + start-2]);
2579
- _t1.mul(_t2);
2580
- _t2.setIdentity();
2581
- _t2.rotX(data[f3 + start-3]);
2582
- }
2583
- else
2584
- {
2585
- _t2.rotX(data[f3 + start-2]);
2586
- _t1.mul(_t2);
2587
- _t2.setIdentity();
2588
- _t2.rotY(data[f3 + start-3]);
2589
- }
2590
-
2591
- _t1.mul(_t2);
2592
- _t2.setIdentity();
2593
-
2594
- _t1.get(mat4d);
2595
-
2596
- mat4d.get(quatend);
2597
-
2598
- double dot = quatstart.x*quatend.x +
2599
- quatstart.y*quatend.y +
2600
- quatstart.z*quatend.z +
2601
- quatstart.w*quatend.w
2602
- ;
2603
-
2604
- if (dot < 0)
2605
- {
2606
- quatend.x *= -1;
2607
- quatend.y *= -1;
2608
- quatend.z *= -1;
2609
- quatend.w *= -1;
2610
- }
2611
-
2612
- // k = 1-k;
2613
-
2614
- quat.x = (1-k)*quatstart.x + k*quatend.x;
2615
- quat.y = (1-k)*quatstart.y + k*quatend.y;
2616
- quat.z = (1-k)*quatstart.z + k*quatend.z;
2617
- quat.w = (1-k)*quatstart.w + k*quatend.w;
2618
-
2619
- quat.normalize();
2620
-
2621
- mat4d.set(quat);
2622
-
2623
- cJ3D.SetTransform(rot, mat4d);
2624
-
2625
- matrixToEulerXYZ(rot, temp);
2626
-
2627
- data[f3 + start-1] = -(float)temp.z;
2628
-
2629
- if (b == 0)
2630
- {
2631
- data[f3 + start-2] = -(float)temp.y;
2632
- data[f3 + start-3] = -(float)temp.x;
2633
- }
2634
- else
2635
- {
2636
- data[f3 + start-2] = -(float)temp.x;
2637
- data[f3 + start-3] = -(float)temp.y;
2638
- }
2639
- }
2640
- else
2641
- {
2642
- for (int i=start; --i>=end;)
2643
- {
2644
- //data[f3 + i] += pos[i] - data[frame3 + i];
2645
- // data[f3 + i] = k*data[f3+i] + (1-k)*
2646
- // currentbones[boneframe3 + i-end];
2647
- data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k);
2648
- }
2649
- }
2650
-
2651
- }
2652
- }
2653
-
2654
- }
3108
+// if (fade && currentbones != null && !CameraPane.fullreset)
3109
+// {
3110
+// Fade();
3111
+// }
26553112 }
2656
-
3113
+
26573114 if (false) // doesn't change anything bone._isRoot)
26583115 {
26593116 // Reset orientation
26603117 _t2.setIdentity();
2661
-
3118
+
26623119 double tx = bone.toParent[3][0];
26633120 double ty = bone.toParent[3][1];
26643121 double tz = bone.toParent[3][2];
....@@ -2667,9 +3124,9 @@
26673124 temp.y = 0;
26683125 temp.z = 0;
26693126 LA.xformDir(temp, bone.toParent, temp);
2670
-
3127
+
26713128 double angle = Math.atan2(-temp.z, temp.x);
2672
-
3129
+
26733130 _t2.rotY(angle);
26743131 // _t1.setIdentity();
26753132 // _t1.rotX(temp.x);
....@@ -2682,56 +3139,21 @@
26823139 // _t1.setIdentity();
26833140 // _t1.rotZ(temp.z);
26843141 // _t2.mul(_t1);
2685
-
3142
+
26863143 cJ3D.ResetTransform(bone, _t2, false);
2687
-
3144
+
26883145 bone.toParent[3][0] = tx;
26893146 bone.toParent[3][1] = ty;
26903147 bone.toParent[3][2] = tz;
26913148 }
26923149 }
26933150
2694
- if (currentbones == null)
2695
- currentbones = new double[numbones*3];
2696
-
2697
- for (int b=numbones; --b>=1;) // 0;)
2698
- //int b = 0;
2699
- {
2700
- data = bvh.animation.getBoneData(b);
2701
-
2702
- int numframes = bvh.animation.getNumFrames();
2703
-
2704
- int dof = 6; // data.length/numframes;
2705
-
2706
- if (b > 0)
2707
- dof = 3;
2708
-
2709
- //assert(dof == 3);
2710
-
2711
- // System.err.println("Bone #" + b + ": dof = " + dof);
2712
- int theframe = // 1; // baseframe;
2713
- frame;
2714
-
2715
- int frame3 = theframe*dof;
2716
- int bone3 = b*3; // dof;
2717
-
2718
- int start = 3;
2719
- int end = 0;
2720
-
2721
- if (dof == 6)
2722
- {
2723
- start = 6;
2724
- end = 3;
2725
- }
2726
- for (int i=start; --i>=end;)
2727
- {
2728
- currentbones[bone3 + i-end] = data[frame3 + i];
2729
- }
2730
- }
3151
+ // SetCurrentBones(frame);
27313152 }
27323153 }
27333154
2734
- static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T"
3155
+ // skip initial "T"
3156
+ static int offset = 1; // 5; // 10; // 5; // 100;
27353157
27363158 void ReadBVH()
27373159 {
....@@ -2760,14 +3182,14 @@
27603182
27613183 void Reset()
27623184 {
2763
- if (fullname != null)
2764
- ReadBVH();
3185
+// if (fullname != null)
3186
+// ReadBVH();
27653187
27663188 Object3D hip = get(0);
27673189
27683190 // assert(obj.name.equals("hip"));
27693191
2770
- Object3D rot = hip.get(0);
3192
+ //Object3D rot = hip.get(0);
27713193
27723194 // assert(obj.name == null); // .equals("hip#"));
27733195
....@@ -2777,8 +3199,8 @@
27773199 hip.fromParent = LA.newMatrix();
27783200 }
27793201
2780
- hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
2781
- hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
3202
+ //hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0;
3203
+ //hip.fromParent[3][0] = hip.fromParent[3][1] = hip.fromParent[3][2] = 0;
27823204
27833205 if (toParent == null)
27843206 {
....@@ -2790,25 +3212,28 @@
27903212 LA.matIdentity(fromParent);
27913213 // LA.matIdentity(hip.toParent);
27923214 // LA.matIdentity(hip.fromParent);
2793
- if (rot.toParent == null)
2794
- {
2795
- // june 2014
2796
- rot.toParent = LA.newMatrix();
2797
- rot.fromParent = LA.newMatrix();
2798
- }
2799
- LA.matIdentity(rot.toParent);
2800
- LA.matIdentity(rot.fromParent);
3215
+// if (rot.toParent == null)
3216
+// {
3217
+// // june 2014
3218
+// rot.toParent = LA.newMatrix();
3219
+// rot.fromParent = LA.newMatrix();
3220
+// }
3221
+// LA.matIdentity(rot.toParent);
3222
+// LA.matIdentity(rot.fromParent);
28013223
28023224 // july 2014
2803
- goalx = goalz = 0;
2804
- targetx = targetz = 0;
3225
+// goalx = goalz = 0;
3226
+ targetdirx = targetdirz = 0;
28053227
2806
- SetPositionDelta(true, true, true, false);
3228
+ //SetPositionDelta(true, true, true, false);
3229
+// LoadData();
3230
+// Rewind();
28073231
28083232 baseframe = frame = 0; // T pose. No offset.
28093233
28103234 // aout 2013 endframe = 0; // june 2013
28113235
3236
+ //ResetZero();
28123237 setPose(frame);
28133238 }
28143239
....@@ -2840,7 +3265,7 @@
28403265 baseframe += step;
28413266
28423267 //frame = baseframe;
2843
- frame += step;
3268
+ //frame += step;
28443269
28453270 // if (frame != baseframe)
28463271 // {
....@@ -2880,7 +3305,10 @@
28803305 {
28813306 bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh;
28823307
2883
- SetPositionDelta(false, true, true, true);
3308
+ // SetPositionDelta(false, true, true, true);
3309
+ LoadData();
3310
+ Rewind();
3311
+ Fade();
28843312 }
28853313 catch (Exception e)
28863314 {
....@@ -2889,13 +3317,17 @@
28893317 }
28903318 }
28913319 }
3320
+
3321
+ frame = GetFirstFrame();
28923322 }
3323
+ else
3324
+ frame += step;
28933325
28943326 //SetPositionDelta(false);
28953327
2896
- if (frame >= bvh.animation.getNumFrames())
2897
- //baseframe =
2898
- frame = GetFirstFrame(); // 0; // offset; // initial point
3328
+// if (frame >= bvh.animation.getNumFrames())
3329
+// //baseframe =
3330
+// frame = GetFirstFrame(); // 0; // offset; // initial point
28993331
29003332 //System.err.println("frame = " + frame);
29013333 if (lastframe != 0)
....@@ -3193,6 +3625,8 @@
31933625 //static
31943626 transient
31953627 double[] currentbones;
3628
+ double[] currenthip;
3629
+
31963630 transient boolean inbetween;
31973631
31983632 void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade)
....@@ -3203,38 +3637,9 @@
32033637 //assert(dim == numframes*6);
32043638
32053639 if (load)
3206
- for (int b=numbones; --b>=0;)
3207
- //int b = 0;
3208
- {
3209
- float[] thedata = bvh.animation.getBoneData(b);
3210
-
3211
- int numframes = bvh.animation.getNumFrames();
3212
-
3213
- int dof = 6; // thedata.length/numframes;
3214
-
3215
- if (b > 0)
3216
- dof = 3;
3217
-
3218
- if (dof != thedata.length/numframes)
3219
- {
3220
- System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes));
3221
- dof = thedata.length/numframes;
3222
- }
3223
-
3224
- //for (int f=numframes; --f>=offset;)
3225
- int firstframe = GetFirstFrame();
3226
- for (int f=0; f<numframes-firstframe; f++)
3227
- {
3228
- int f3 = f*dof;
3229
-
3230
- //for (int i=3/*dof*/; --i>=0;)
3231
- for (int i=dof; --i>=0;)
3232
- {
3233
- //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i];
3234
- thedata[f3 + i] = thedata[f3 + firstframe*dof + i];
3235
- }
3236
- }
3237
- }
3640
+ {
3641
+ LoadData();
3642
+ }
32383643
32393644 // assert(thedata[0] == 0);
32403645 // assert(thedata[1] == 0);
....@@ -3244,11 +3649,11 @@
32443649 // assert(thedata[7] == 0);
32453650 // assert(thedata[8] == 0);
32463651
3247
- Object3D obj = get(0);
3652
+ Object3D hip = get(0);
32483653
32493654 // assert(obj.name.equals("hip"));
32503655
3251
- Object3D rot = obj.get(0);
3656
+ Object3D rot = hip.get(0);
32523657
32533658 // if (toParent == null)
32543659 // {
....@@ -3260,7 +3665,7 @@
32603665 // // assert(obj.name == null); // .equals("hip#"));
32613666
32623667 Invariants();
3263
- obj.Invariants();
3668
+ hip.Invariants();
32643669 rot.Invariants();
32653670
32663671 if (origin == null)
....@@ -3281,16 +3686,16 @@
32813686 fromParent = LA.newMatrix();
32823687 }
32833688
3284
- if (obj.toParent == null) // june 2014
3689
+ if (hip.toParent == null) // june 2014
32853690 {
3286
- obj.toParent = LA.newMatrix();
3287
- obj.fromParent = LA.newMatrix();
3691
+ hip.toParent = LA.newMatrix();
3692
+ hip.fromParent = LA.newMatrix();
32883693 }
32893694
3290
- LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB
3695
+ LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB
32913696 Object3D gp = this.parent;
32923697 this.parent = null;
3293
- obj.GlobalTransformInv();
3698
+ hip.GlobalTransformInv();
32943699 this.parent = gp;
32953700
32963701 if (rot.toParent == null)
....@@ -3313,41 +3718,41 @@
33133718 LA.matInvert(origin.toParent, origin.fromParent);
33143719
33153720 Invariants();
3316
- obj.Invariants();
3721
+ hip.Invariants();
33173722 rot.Invariants();
33183723 origin.Invariants();
33193724 origin0.Invariants();
33203725
3321
- firsttimeafterload = true;
3726
+ firsttimeafterload = false; // true;
33223727
33233728 if (rewind)
33243729 Rewind();
33253730
3326
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade);
3731
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade);
33273732
3328
- if (true)
3329
- return;
3733
+ if (true)
3734
+ return;
33303735
33313736 double pos[] = new double[6];
33323737
33333738 if (!reset)
33343739 {
3335
- assert(obj.tx == obj.toParent[3][0]);
3336
- assert(obj.ty == obj.toParent[3][1]);
3337
- assert(obj.tz == obj.toParent[3][2]);
3740
+ assert(hip.tx == hip.toParent[3][0]);
3741
+ assert(hip.ty == hip.toParent[3][1]);
3742
+ assert(hip.tz == hip.toParent[3][2]);
33383743
3339
- pos[0] = obj.tx; // obj.toParent[3][0];
3340
- pos[1] = obj.ty; // obj.toParent[3][1];
3341
- pos[2] = obj.tz; // obj.toParent[3][2];
3342
- pos[3] = obj.rz;
3343
- pos[4] = obj.ry;
3344
- pos[5] = obj.rx;
3744
+ pos[0] = hip.tx; // obj.toParent[3][0];
3745
+ pos[1] = hip.ty; // obj.toParent[3][1];
3746
+ pos[2] = hip.tz; // obj.toParent[3][2];
3747
+ pos[3] = hip.rz;
3748
+ pos[4] = hip.ry;
3749
+ pos[5] = hip.rx;
33453750 }
33463751
33473752 cVector temp = new cVector();
3348
- temp.x = obj.globalTransform[3][0];
3349
- temp.y = obj.globalTransform[3][1];
3350
- temp.z = obj.globalTransform[3][2];
3753
+ temp.x = hip.globalTransform[3][0];
3754
+ temp.y = hip.globalTransform[3][1];
3755
+ temp.z = hip.globalTransform[3][2];
33513756 // LA.xformPos(temp, origin0.toParent, temp);
33523757 // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";");
33533758
....@@ -3431,7 +3836,7 @@
34313836 }
34323837
34333838 // Rewind();
3434
- setPose(obj, frame, bvh.animation.getBoneData(obj._index), true);
3839
+ setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true);
34353840 }
34363841
34373842 void Rewind()