.. | .. |
---|
26 | 26 | public class Mocap extends Object3D |
---|
27 | 27 | { |
---|
28 | 28 | 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 | + } |
---|
29 | 591 | |
---|
30 | 592 | void WriteTo(java.io.Writer writer) throws Exception |
---|
31 | 593 | { |
---|
.. | .. |
---|
99 | 661 | double pinx; |
---|
100 | 662 | double pinz; |
---|
101 | 663 | |
---|
102 | | - double targetx; |
---|
103 | | - double targetz; |
---|
| 664 | + double targetdirx; |
---|
| 665 | + double targetdirz; |
---|
104 | 666 | |
---|
105 | | - double goalx; |
---|
106 | | - double goalz; |
---|
| 667 | + double goalposx = -20; |
---|
| 668 | + double goalposz = -10; |
---|
107 | 669 | |
---|
108 | 670 | boolean followpath; |
---|
109 | 671 | |
---|
.. | .. |
---|
174 | 736 | scriptactions.clear(); |
---|
175 | 737 | } |
---|
176 | 738 | |
---|
177 | | - static double EPSACTION = 0.1; // 0.075; // 0.1; |
---|
| 739 | + static double EPSACTION = 0.1; // 0.075; // 0.1;Came |
---|
178 | 740 | |
---|
179 | 741 | void AddFromTo(cVector from, cVector to) |
---|
180 | 742 | { |
---|
.. | .. |
---|
460 | 1022 | testvect.set(from); |
---|
461 | 1023 | testvect.sub(fromto.from); |
---|
462 | 1024 | |
---|
| 1025 | + testvect.y = 0; // PATCH |
---|
| 1026 | + |
---|
463 | 1027 | int factor = 1; |
---|
464 | 1028 | |
---|
465 | 1029 | //if (CameraPane.FAST) |
---|
.. | .. |
---|
501 | 1065 | |
---|
502 | 1066 | testvect.set(from); |
---|
503 | 1067 | testvect.sub(fromto.from); |
---|
| 1068 | + |
---|
| 1069 | + testvect.y = 0; // PATCH |
---|
504 | 1070 | |
---|
505 | 1071 | int factor = 1; |
---|
506 | 1072 | |
---|
.. | .. |
---|
705 | 1271 | // skip first node: translation |
---|
706 | 1272 | // Object3D b = input.get(0); |
---|
707 | 1273 | |
---|
708 | | - setPose(input, f, data.getBoneData(input._index), false); //, null); |
---|
| 1274 | + setPose(input, f, data.getBoneData(input._index)); //, false); //, null); |
---|
709 | 1275 | } |
---|
710 | 1276 | |
---|
711 | 1277 | //mocap.figure.Bone[] children = b.getChildren(); |
---|
.. | .. |
---|
736 | 1302 | |
---|
737 | 1303 | void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid) |
---|
738 | 1304 | { |
---|
| 1305 | + assert(false); |
---|
739 | 1306 | //assert(CameraPane.drawMode == CameraPane.SHADOW); |
---|
740 | 1307 | |
---|
741 | 1308 | Object3D transformnode = new Object3D(); |
---|
.. | .. |
---|
921 | 1488 | //groundz += sourcenode.parent.toParent[3][2] - posz; |
---|
922 | 1489 | } |
---|
923 | 1490 | |
---|
924 | | - boolean footcontact = CameraPane.FOOTCONTACT; // false; |
---|
| 1491 | + boolean footcontact = false; // CameraPane.FOOTCONTACT; // false; |
---|
925 | 1492 | |
---|
926 | 1493 | if (footcontact && ground != -123456) |
---|
927 | 1494 | { |
---|
.. | .. |
---|
939 | 1506 | groundid = floorid; |
---|
940 | 1507 | |
---|
941 | 1508 | // 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; |
---|
945 | 1512 | |
---|
946 | 1513 | if (true) // slow && stepout && onein) |
---|
947 | 1514 | { |
---|
.. | .. |
---|
1018 | 1585 | |
---|
1019 | 1586 | // System.out.println("Allo " + sourcenode); |
---|
1020 | 1587 | // 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; |
---|
1024 | 1591 | |
---|
1025 | 1592 | |
---|
1026 | 1593 | if (false) // dist2 > 0.1) |
---|
.. | .. |
---|
1086 | 1653 | this.get(0).TransformToWorld(v0); |
---|
1087 | 1654 | |
---|
1088 | 1655 | // 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; |
---|
1092 | 1659 | |
---|
1093 | 1660 | LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent); |
---|
1094 | 1661 | LA.matInvert(sourcenode.toParent, sourcenode.fromParent); |
---|
.. | .. |
---|
1098 | 1665 | this.get(0).TransformToWorld(v0); |
---|
1099 | 1666 | |
---|
1100 | 1667 | // 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; |
---|
1104 | 1671 | } |
---|
1105 | 1672 | } |
---|
1106 | 1673 | |
---|
.. | .. |
---|
1140 | 1707 | |
---|
1141 | 1708 | if (goal != null) |
---|
1142 | 1709 | { |
---|
1143 | | - System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")"); |
---|
| 1710 | + System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")"); |
---|
1144 | 1711 | //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; |
---|
1148 | 1715 | |
---|
1149 | 1716 | followpath = true; |
---|
1150 | 1717 | } |
---|
.. | .. |
---|
1195 | 1762 | // } |
---|
1196 | 1763 | if (false) // !uselast) |
---|
1197 | 1764 | { |
---|
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; |
---|
1201 | 1768 | } |
---|
1202 | 1769 | } |
---|
1203 | 1770 | |
---|
1204 | | - if (goalx != 0 || goalz != 0) // TODO |
---|
| 1771 | + if (goalposx != 0 || goalposz != 0) // TODO |
---|
1205 | 1772 | { |
---|
1206 | 1773 | // overwrite speaker orientation |
---|
1207 | | - dst.set(goalx,0,goalz); |
---|
| 1774 | + dst.set(goalposx,0,goalposz); |
---|
1208 | 1775 | if (sourcenode.parent != null) // july 2014 |
---|
1209 | 1776 | sourcenode.parent. |
---|
1210 | 1777 | TransformToLocal(dst); |
---|
.. | .. |
---|
1220 | 1787 | src.x = 0; |
---|
1221 | 1788 | src.y = 0; |
---|
1222 | 1789 | src.z = 0; |
---|
| 1790 | + LA.xformPos(src, get(0).get(0).toParent, src); |
---|
1223 | 1791 | LA.xformPos(src, get(0).toParent, src); |
---|
1224 | 1792 | LA.xformPos(src, toParent, src); |
---|
1225 | 1793 | // LA.xformPos(src, rotsourcenode.toParent, src); |
---|
.. | .. |
---|
1255 | 1823 | // mars 2014 |
---|
1256 | 1824 | if (false) // goalx != 0 || goalz != 0) |
---|
1257 | 1825 | { |
---|
1258 | | - targetx = dst.x - src.x; |
---|
1259 | | - targetz = dst.z - src.z; |
---|
| 1826 | + targetdirx = dst.x - src.x; |
---|
| 1827 | + targetdirz = dst.z - src.z; |
---|
1260 | 1828 | |
---|
1261 | | - if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1) |
---|
| 1829 | + if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1) |
---|
1262 | 1830 | { |
---|
1263 | 1831 | // far enough from goal. keep the goal position. |
---|
1264 | | - targetx = 0; |
---|
1265 | | - targetz = 0; |
---|
| 1832 | + targetdirx = 0; |
---|
| 1833 | + targetdirz = 0; |
---|
1266 | 1834 | } |
---|
1267 | 1835 | else |
---|
1268 | 1836 | { |
---|
1269 | 1837 | // too close to goal. switch to target direction instead. |
---|
1270 | | - goalx = 0; |
---|
1271 | | - goalz = 0; |
---|
| 1838 | + goalposx = 0; |
---|
| 1839 | + goalposz = 0; |
---|
1272 | 1840 | } |
---|
1273 | 1841 | } |
---|
1274 | 1842 | |
---|
1275 | 1843 | //sourcenode.getCentroid(src, true); |
---|
1276 | 1844 | |
---|
1277 | | - if (speakernode == sourcenode && goalx == 0 && goalz == 0) |
---|
| 1845 | + if (speakernode == sourcenode && goalposx == 0 && goalposz == 0) |
---|
1278 | 1846 | { |
---|
1279 | 1847 | if (ScriptNode.lastspeaker != null) |
---|
1280 | 1848 | new Exception().printStackTrace(); |
---|
.. | .. |
---|
1283 | 1851 | |
---|
1284 | 1852 | // LA.xformPos(src, fromParent, src); |
---|
1285 | 1853 | |
---|
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) |
---|
1287 | 1855 | dst.sub(src); |
---|
1288 | 1856 | else |
---|
1289 | 1857 | // vector mode |
---|
1290 | 1858 | { |
---|
1291 | | - dst.x = targetx; |
---|
1292 | | - dst.z = targetz; |
---|
| 1859 | + dst.x = targetdirx; |
---|
| 1860 | + dst.z = targetdirz; |
---|
1293 | 1861 | |
---|
1294 | 1862 | // TEST TARGET |
---|
1295 | 1863 | // dst.x = CameraPane.selectedpoint.toParent[3][0]; |
---|
.. | .. |
---|
1563 | 2131 | toParent = LA.newMatrix(); |
---|
1564 | 2132 | fromParent = LA.newMatrix(); |
---|
1565 | 2133 | } |
---|
| 2134 | + |
---|
1566 | 2135 | LA.matConcat(toParent, rotsourcenode.toParent, toParent); |
---|
1567 | 2136 | LA.matInvert(toParent, fromParent); |
---|
1568 | 2137 | |
---|
.. | .. |
---|
1698 | 2267 | } |
---|
1699 | 2268 | |
---|
1700 | 2269 | if (!smoothed) |
---|
1701 | | - for (int i=4; --i>=0;) |
---|
| 2270 | + for (int i=0; --i>=0;) |
---|
1702 | 2271 | SmoothAnimData(); // much reduces shakiness |
---|
1703 | 2272 | |
---|
1704 | 2273 | smoothed = true; |
---|
.. | .. |
---|
1736 | 2305 | toVector.x = LA.cos(to); |
---|
1737 | 2306 | toVector.y = LA.sin(to); |
---|
1738 | 2307 | |
---|
| 2308 | + double fromA = Math.atan2(fromVector.y, fromVector.x); |
---|
| 2309 | + double toA = Math.atan2(toVector.y, toVector.x); |
---|
| 2310 | + |
---|
1739 | 2311 | Vector2d currentVector = Slerp(fromVector, toVector, step); |
---|
1740 | 2312 | |
---|
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; |
---|
1742 | 2318 | } |
---|
1743 | 2319 | |
---|
1744 | 2320 | public static Vector2d Slerp(Vector2d from, Vector2d to, double step) |
---|
.. | .. |
---|
1780 | 2356 | if (!live) // aout 2013 |
---|
1781 | 2357 | return; |
---|
1782 | 2358 | |
---|
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 | + } |
---|
1787 | 2369 | |
---|
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); |
---|
1789 | 2381 | // if (!success) |
---|
1790 | 2382 | // { |
---|
1791 | 2383 | // //assert(success); |
---|
.. | .. |
---|
1793 | 2385 | // System.out.println("No centroid for " + sourcenode); |
---|
1794 | 2386 | // } |
---|
1795 | 2387 | |
---|
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 | | - |
---|
1806 | 2388 | if (sourcenode.parent == null && sourcenode.fileparent == null) |
---|
1807 | 2389 | { |
---|
1808 | 2390 | // No GFD |
---|
.. | .. |
---|
2050 | 2632 | * @param frame |
---|
2051 | 2633 | * Frame number |
---|
2052 | 2634 | */ |
---|
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) |
---|
2054 | 2636 | { |
---|
2055 | 2637 | if (!live) // aout 2013 |
---|
2056 | 2638 | return; |
---|
.. | .. |
---|
2058 | 2640 | cVector temp = new cVector(); |
---|
2059 | 2641 | cVector temp0 = new cVector(); |
---|
2060 | 2642 | 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 | + } |
---|
2061 | 2670 | |
---|
2062 | 2671 | // Object3D obj = get(0); |
---|
2063 | 2672 | // Object3D gp = this.parent; |
---|
.. | .. |
---|
2188 | 2797 | //if (bone._rotationEnabled) |
---|
2189 | 2798 | if (//frame > 0 && |
---|
2190 | 2799 | !bone.skipmocap && |
---|
2191 | | - !bone.name.contains("head") && |
---|
| 2800 | + !bone.name.contains("head") // && |
---|
2192 | 2801 | // !bone.name.contains("rFoot") && |
---|
2193 | 2802 | // !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") |
---|
2199 | 2808 | ) |
---|
2200 | 2809 | { |
---|
2201 | 2810 | //_rotTG.setTransform(_t1); |
---|
.. | .. |
---|
2228 | 2837 | // CROWD |
---|
2229 | 2838 | //cJ3D.GetTranslation(bone, _trans0); |
---|
2230 | 2839 | //_trans.add(_trans0); |
---|
2231 | | - _transTF.setIdentity(); |
---|
| 2840 | + //_transTF.setIdentity(); |
---|
| 2841 | + _transTF.set(_t1); |
---|
2232 | 2842 | _transTF.setTranslation(_trans); |
---|
2233 | 2843 | // System.err.println("Translate: " + _transTF); |
---|
2234 | 2844 | //_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 |
---|
2236 | 2847 | } |
---|
2237 | 2848 | } |
---|
2238 | 2849 | |
---|
2239 | | - if (bone._isRoot && firsttimeafterload && frame > 0) |
---|
| 2850 | + if (false) // bone._isRoot && firsttimeafterload && frame > 0) |
---|
2240 | 2851 | { |
---|
2241 | 2852 | assert(bone == get(0)); |
---|
2242 | 2853 | |
---|
.. | .. |
---|
2252 | 2863 | // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1 |
---|
2253 | 2864 | // |
---|
2254 | 2865 | |
---|
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(); |
---|
2262 | 2873 | |
---|
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); |
---|
2266 | 2877 | |
---|
2267 | 2878 | // matrixToEulerXYZ(toParent, temp); |
---|
2268 | 2879 | // matrixToEulerXYZ(bone.get(0).toParent, temp); |
---|
.. | .. |
---|
2296 | 2907 | // |
---|
2297 | 2908 | // mat4d.get(quat); |
---|
2298 | 2909 | |
---|
2299 | | - if (true) // hip correction |
---|
| 2910 | + if (false) // hip correction |
---|
2300 | 2911 | { |
---|
2301 | 2912 | _t2.setIdentity(); |
---|
2302 | 2913 | |
---|
.. | .. |
---|
2337 | 2948 | //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C' |
---|
2338 | 2949 | // LA.matConcat(origin.fromParent, tempmatrix, fromParent); |
---|
2339 | 2950 | |
---|
2340 | | - LA.matInvert(toParent, fromParent); |
---|
| 2951 | +//?? LA.matInvert(toParent, fromParent); |
---|
2341 | 2952 | |
---|
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(); |
---|
2347 | 2958 | |
---|
2348 | 2959 | // LA.matInvert(fromParent, tempmatrix); |
---|
2349 | 2960 | // |
---|
.. | .. |
---|
2364 | 2975 | // temp.x = data[0]; |
---|
2365 | 2976 | // temp.y = data[1]; |
---|
2366 | 2977 | // temp.z = data[2]; |
---|
2367 | | - LA.xformPos(temp, origin0.toParent, temp0); |
---|
| 2978 | + LA.xformPos(temp, origin0.toParent, temp0); // NU |
---|
2368 | 2979 | |
---|
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 | +// |
---|
2375 | 2986 | // 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); |
---|
2380 | 2991 | |
---|
2381 | | - LA.xformPos(temp0, fromParent, temp); |
---|
| 2992 | + LA.xformPos(temp0, fromParent, temp); // NU |
---|
2382 | 2993 | //LA.xformPos(temp, bone.fromParent, temp); |
---|
2383 | 2994 | // float[] data; |
---|
2384 | 2995 | |
---|
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); |
---|
2388 | 3005 | |
---|
2389 | 3006 | // CameraPane.selectedpoint.toParent[3][0] = temp0.x; |
---|
2390 | 3007 | // CameraPane.selectedpoint.toParent[3][1] = temp0.y; |
---|
2391 | 3008 | // CameraPane.selectedpoint.toParent[3][2] = temp0.z; |
---|
2392 | 3009 | |
---|
2393 | | - int numframes = bvh.animation.getNumFrames(); |
---|
| 3010 | + int numframes = bvh.animation.getNumFrames(); |
---|
2394 | 3011 | |
---|
2395 | 3012 | int b = 0; |
---|
2396 | 3013 | { |
---|
.. | .. |
---|
2398 | 3015 | |
---|
2399 | 3016 | int dof = 6; /// data.length/numframes; |
---|
2400 | 3017 | |
---|
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 | + } |
---|
2407 | 3024 | |
---|
2408 | 3025 | |
---|
2409 | 3026 | int theframe = 0; // baseframe; |
---|
.. | .. |
---|
2455 | 3072 | // } |
---|
2456 | 3073 | // } |
---|
2457 | 3074 | |
---|
2458 | | - data[f3 + i] += pos[i] - data[frame3 + i]; |
---|
| 3075 | + data[f3 + i] += /*pos[i]*/ - data[frame3 + i]; |
---|
2459 | 3076 | |
---|
2460 | 3077 | // if (f < 3) |
---|
2461 | 3078 | // { |
---|
2462 | 3079 | // System.out.print(data[f3 + i] + " "); |
---|
2463 | 3080 | // } |
---|
2464 | 3081 | } |
---|
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]; |
---|
2469 | 3095 | } |
---|
2470 | 3096 | } |
---|
2471 | 3097 | |
---|
.. | .. |
---|
2479 | 3105 | // temp.y = data[1]; |
---|
2480 | 3106 | // temp.z = data[2]; |
---|
2481 | 3107 | |
---|
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 | +// } |
---|
2655 | 3112 | } |
---|
2656 | | - |
---|
| 3113 | + |
---|
2657 | 3114 | if (false) // doesn't change anything bone._isRoot) |
---|
2658 | 3115 | { |
---|
2659 | 3116 | // Reset orientation |
---|
2660 | 3117 | _t2.setIdentity(); |
---|
2661 | | - |
---|
| 3118 | + |
---|
2662 | 3119 | double tx = bone.toParent[3][0]; |
---|
2663 | 3120 | double ty = bone.toParent[3][1]; |
---|
2664 | 3121 | double tz = bone.toParent[3][2]; |
---|
.. | .. |
---|
2667 | 3124 | temp.y = 0; |
---|
2668 | 3125 | temp.z = 0; |
---|
2669 | 3126 | LA.xformDir(temp, bone.toParent, temp); |
---|
2670 | | - |
---|
| 3127 | + |
---|
2671 | 3128 | double angle = Math.atan2(-temp.z, temp.x); |
---|
2672 | | - |
---|
| 3129 | + |
---|
2673 | 3130 | _t2.rotY(angle); |
---|
2674 | 3131 | // _t1.setIdentity(); |
---|
2675 | 3132 | // _t1.rotX(temp.x); |
---|
.. | .. |
---|
2682 | 3139 | // _t1.setIdentity(); |
---|
2683 | 3140 | // _t1.rotZ(temp.z); |
---|
2684 | 3141 | // _t2.mul(_t1); |
---|
2685 | | - |
---|
| 3142 | + |
---|
2686 | 3143 | cJ3D.ResetTransform(bone, _t2, false); |
---|
2687 | | - |
---|
| 3144 | + |
---|
2688 | 3145 | bone.toParent[3][0] = tx; |
---|
2689 | 3146 | bone.toParent[3][1] = ty; |
---|
2690 | 3147 | bone.toParent[3][2] = tz; |
---|
2691 | 3148 | } |
---|
2692 | 3149 | } |
---|
2693 | 3150 | |
---|
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); |
---|
2731 | 3152 | } |
---|
2732 | 3153 | } |
---|
2733 | 3154 | |
---|
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; |
---|
2735 | 3157 | |
---|
2736 | 3158 | void ReadBVH() |
---|
2737 | 3159 | { |
---|
.. | .. |
---|
2760 | 3182 | |
---|
2761 | 3183 | void Reset() |
---|
2762 | 3184 | { |
---|
2763 | | - if (fullname != null) |
---|
2764 | | - ReadBVH(); |
---|
| 3185 | +// if (fullname != null) |
---|
| 3186 | +// ReadBVH(); |
---|
2765 | 3187 | |
---|
2766 | 3188 | Object3D hip = get(0); |
---|
2767 | 3189 | |
---|
2768 | 3190 | // assert(obj.name.equals("hip")); |
---|
2769 | 3191 | |
---|
2770 | | - Object3D rot = hip.get(0); |
---|
| 3192 | + //Object3D rot = hip.get(0); |
---|
2771 | 3193 | |
---|
2772 | 3194 | // assert(obj.name == null); // .equals("hip#")); |
---|
2773 | 3195 | |
---|
.. | .. |
---|
2777 | 3199 | hip.fromParent = LA.newMatrix(); |
---|
2778 | 3200 | } |
---|
2779 | 3201 | |
---|
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; |
---|
2782 | 3204 | |
---|
2783 | 3205 | if (toParent == null) |
---|
2784 | 3206 | { |
---|
.. | .. |
---|
2790 | 3212 | LA.matIdentity(fromParent); |
---|
2791 | 3213 | // LA.matIdentity(hip.toParent); |
---|
2792 | 3214 | // 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); |
---|
2801 | 3223 | |
---|
2802 | 3224 | // july 2014 |
---|
2803 | | - goalx = goalz = 0; |
---|
2804 | | - targetx = targetz = 0; |
---|
| 3225 | +// goalx = goalz = 0; |
---|
| 3226 | + targetdirx = targetdirz = 0; |
---|
2805 | 3227 | |
---|
2806 | | - SetPositionDelta(true, true, true, false); |
---|
| 3228 | + //SetPositionDelta(true, true, true, false); |
---|
| 3229 | +// LoadData(); |
---|
| 3230 | +// Rewind(); |
---|
2807 | 3231 | |
---|
2808 | 3232 | baseframe = frame = 0; // T pose. No offset. |
---|
2809 | 3233 | |
---|
2810 | 3234 | // aout 2013 endframe = 0; // june 2013 |
---|
2811 | 3235 | |
---|
| 3236 | + //ResetZero(); |
---|
2812 | 3237 | setPose(frame); |
---|
2813 | 3238 | } |
---|
2814 | 3239 | |
---|
.. | .. |
---|
2840 | 3265 | baseframe += step; |
---|
2841 | 3266 | |
---|
2842 | 3267 | //frame = baseframe; |
---|
2843 | | - frame += step; |
---|
| 3268 | + //frame += step; |
---|
2844 | 3269 | |
---|
2845 | 3270 | // if (frame != baseframe) |
---|
2846 | 3271 | // { |
---|
.. | .. |
---|
2880 | 3305 | { |
---|
2881 | 3306 | bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh; |
---|
2882 | 3307 | |
---|
2883 | | - SetPositionDelta(false, true, true, true); |
---|
| 3308 | + // SetPositionDelta(false, true, true, true); |
---|
| 3309 | + LoadData(); |
---|
| 3310 | + Rewind(); |
---|
| 3311 | + Fade(); |
---|
2884 | 3312 | } |
---|
2885 | 3313 | catch (Exception e) |
---|
2886 | 3314 | { |
---|
.. | .. |
---|
2889 | 3317 | } |
---|
2890 | 3318 | } |
---|
2891 | 3319 | } |
---|
| 3320 | + |
---|
| 3321 | + frame = GetFirstFrame(); |
---|
2892 | 3322 | } |
---|
| 3323 | + else |
---|
| 3324 | + frame += step; |
---|
2893 | 3325 | |
---|
2894 | 3326 | //SetPositionDelta(false); |
---|
2895 | 3327 | |
---|
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 |
---|
2899 | 3331 | |
---|
2900 | 3332 | //System.err.println("frame = " + frame); |
---|
2901 | 3333 | if (lastframe != 0) |
---|
.. | .. |
---|
3193 | 3625 | //static |
---|
3194 | 3626 | transient |
---|
3195 | 3627 | double[] currentbones; |
---|
| 3628 | + double[] currenthip; |
---|
| 3629 | + |
---|
3196 | 3630 | transient boolean inbetween; |
---|
3197 | 3631 | |
---|
3198 | 3632 | void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade) |
---|
.. | .. |
---|
3203 | 3637 | //assert(dim == numframes*6); |
---|
3204 | 3638 | |
---|
3205 | 3639 | 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 | + } |
---|
3238 | 3643 | |
---|
3239 | 3644 | // assert(thedata[0] == 0); |
---|
3240 | 3645 | // assert(thedata[1] == 0); |
---|
.. | .. |
---|
3244 | 3649 | // assert(thedata[7] == 0); |
---|
3245 | 3650 | // assert(thedata[8] == 0); |
---|
3246 | 3651 | |
---|
3247 | | - Object3D obj = get(0); |
---|
| 3652 | + Object3D hip = get(0); |
---|
3248 | 3653 | |
---|
3249 | 3654 | // assert(obj.name.equals("hip")); |
---|
3250 | 3655 | |
---|
3251 | | - Object3D rot = obj.get(0); |
---|
| 3656 | + Object3D rot = hip.get(0); |
---|
3252 | 3657 | |
---|
3253 | 3658 | // if (toParent == null) |
---|
3254 | 3659 | // { |
---|
.. | .. |
---|
3260 | 3665 | // // assert(obj.name == null); // .equals("hip#")); |
---|
3261 | 3666 | |
---|
3262 | 3667 | Invariants(); |
---|
3263 | | - obj.Invariants(); |
---|
| 3668 | + hip.Invariants(); |
---|
3264 | 3669 | rot.Invariants(); |
---|
3265 | 3670 | |
---|
3266 | 3671 | if (origin == null) |
---|
.. | .. |
---|
3281 | 3686 | fromParent = LA.newMatrix(); |
---|
3282 | 3687 | } |
---|
3283 | 3688 | |
---|
3284 | | - if (obj.toParent == null) // june 2014 |
---|
| 3689 | + if (hip.toParent == null) // june 2014 |
---|
3285 | 3690 | { |
---|
3286 | | - obj.toParent = LA.newMatrix(); |
---|
3287 | | - obj.fromParent = LA.newMatrix(); |
---|
| 3691 | + hip.toParent = LA.newMatrix(); |
---|
| 3692 | + hip.fromParent = LA.newMatrix(); |
---|
3288 | 3693 | } |
---|
3289 | 3694 | |
---|
3290 | | - LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB |
---|
| 3695 | + LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB |
---|
3291 | 3696 | Object3D gp = this.parent; |
---|
3292 | 3697 | this.parent = null; |
---|
3293 | | - obj.GlobalTransformInv(); |
---|
| 3698 | + hip.GlobalTransformInv(); |
---|
3294 | 3699 | this.parent = gp; |
---|
3295 | 3700 | |
---|
3296 | 3701 | if (rot.toParent == null) |
---|
.. | .. |
---|
3313 | 3718 | LA.matInvert(origin.toParent, origin.fromParent); |
---|
3314 | 3719 | |
---|
3315 | 3720 | Invariants(); |
---|
3316 | | - obj.Invariants(); |
---|
| 3721 | + hip.Invariants(); |
---|
3317 | 3722 | rot.Invariants(); |
---|
3318 | 3723 | origin.Invariants(); |
---|
3319 | 3724 | origin0.Invariants(); |
---|
3320 | 3725 | |
---|
3321 | | - firsttimeafterload = true; |
---|
| 3726 | + firsttimeafterload = false; // true; |
---|
3322 | 3727 | |
---|
3323 | 3728 | if (rewind) |
---|
3324 | 3729 | Rewind(); |
---|
3325 | 3730 | |
---|
3326 | | - setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade); |
---|
| 3731 | + setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade); |
---|
3327 | 3732 | |
---|
3328 | | - if (true) |
---|
3329 | | - return; |
---|
| 3733 | + if (true) |
---|
| 3734 | + return; |
---|
3330 | 3735 | |
---|
3331 | 3736 | double pos[] = new double[6]; |
---|
3332 | 3737 | |
---|
3333 | 3738 | if (!reset) |
---|
3334 | 3739 | { |
---|
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]); |
---|
3338 | 3743 | |
---|
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; |
---|
3345 | 3750 | } |
---|
3346 | 3751 | |
---|
3347 | 3752 | 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]; |
---|
3351 | 3756 | // LA.xformPos(temp, origin0.toParent, temp); |
---|
3352 | 3757 | // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";"); |
---|
3353 | 3758 | |
---|
.. | .. |
---|
3431 | 3836 | } |
---|
3432 | 3837 | |
---|
3433 | 3838 | // Rewind(); |
---|
3434 | | - setPose(obj, frame, bvh.animation.getBoneData(obj._index), true); |
---|
| 3839 | + setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true); |
---|
3435 | 3840 | } |
---|
3436 | 3841 | |
---|
3437 | 3842 | void Rewind() |
---|