.. | .. |
---|
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 | { |
---|
.. | .. |
---|
359 | 921 | // //GetFileRoot(); |
---|
360 | 922 | |
---|
361 | 923 | // sept 2014: // |
---|
362 | | - GraphreeD.RENDERME = 3; // patch for Merge objects |
---|
| 924 | + GrafreeD.RENDERME = 3; // patch for Merge objects |
---|
363 | 925 | float[] thedata = bvh.animation.getBoneData(0); |
---|
364 | 926 | |
---|
365 | 927 | os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]); |
---|
.. | .. |
---|
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 | { |
---|
.. | .. |
---|
938 | 1505 | |
---|
939 | 1506 | groundid = floorid; |
---|
940 | 1507 | |
---|
941 | | - CameraPane.debugpoint.toParent[3][0] = groundx; |
---|
942 | | - CameraPane.debugpoint.toParent[3][1] = floor.y; |
---|
943 | | - CameraPane.debugpoint.toParent[3][2] = groundz; |
---|
| 1508 | + // green |
---|
| 1509 | + CameraPane.debugpointG.toParent[3][0] = groundx; |
---|
| 1510 | + CameraPane.debugpointG.toParent[3][1] = floor.y; |
---|
| 1511 | + CameraPane.debugpointG.toParent[3][2] = groundz; |
---|
944 | 1512 | |
---|
945 | 1513 | if (true) // slow && stepout && onein) |
---|
946 | 1514 | { |
---|
.. | .. |
---|
998 | 1566 | |
---|
999 | 1567 | lastsoundtime = CameraPane.framecount; |
---|
1000 | 1568 | |
---|
1001 | | - GraphreeD.hassound = true; |
---|
| 1569 | + GrafreeD.hassound = true; |
---|
1002 | 1570 | } |
---|
1003 | 1571 | // else |
---|
1004 | 1572 | // System.out.println("skipped"); |
---|
.. | .. |
---|
1016 | 1584 | // floor.z += posz; |
---|
1017 | 1585 | |
---|
1018 | 1586 | // System.out.println("Allo " + sourcenode); |
---|
1019 | | - CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx; |
---|
1020 | | - CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1]; |
---|
1021 | | - CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz; |
---|
| 1587 | + // purple |
---|
| 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; |
---|
1022 | 1591 | |
---|
1023 | 1592 | |
---|
1024 | 1593 | if (false) // dist2 > 0.1) |
---|
.. | .. |
---|
1052 | 1621 | v0.z = groundz - floor.z; |
---|
1053 | 1622 | |
---|
1054 | 1623 | double distance = Math.sqrt(v0.dot(v0)); |
---|
1055 | | - double maxdist = 0.004; |
---|
| 1624 | + double maxdist = 0.04; |
---|
1056 | 1625 | |
---|
1057 | 1626 | if (distance > maxdist) |
---|
1058 | 1627 | { |
---|
.. | .. |
---|
1078 | 1647 | sourcenode.toParent = LA.newMatrix(); |
---|
1079 | 1648 | sourcenode.fromParent = LA.newMatrix(); |
---|
1080 | 1649 | } |
---|
| 1650 | + |
---|
| 1651 | + v0.x = v0.z = 0; |
---|
| 1652 | + |
---|
| 1653 | + this.get(0).TransformToWorld(v0); |
---|
| 1654 | + |
---|
| 1655 | + // cyan |
---|
| 1656 | + CameraPane.debugpointC.toParent[3][0] = v0.x; |
---|
| 1657 | + CameraPane.debugpointC.toParent[3][1] = ground; |
---|
| 1658 | + CameraPane.debugpointC.toParent[3][2] = v0.z; |
---|
| 1659 | + |
---|
1081 | 1660 | LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent); |
---|
1082 | 1661 | LA.matInvert(sourcenode.toParent, sourcenode.fromParent); |
---|
| 1662 | + |
---|
| 1663 | + v0.x = v0.z = 0; |
---|
| 1664 | + |
---|
| 1665 | + this.get(0).TransformToWorld(v0); |
---|
| 1666 | + |
---|
| 1667 | + // red |
---|
| 1668 | + CameraPane.debugpointR.toParent[3][0] = v0.x; |
---|
| 1669 | + CameraPane.debugpointR.toParent[3][1] = ground; |
---|
| 1670 | + CameraPane.debugpointR.toParent[3][2] = v0.z; |
---|
1083 | 1671 | } |
---|
1084 | 1672 | } |
---|
1085 | 1673 | |
---|
.. | .. |
---|
1119 | 1707 | |
---|
1120 | 1708 | if (goal != null) |
---|
1121 | 1709 | { |
---|
1122 | | - System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")"); |
---|
| 1710 | + System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")"); |
---|
1123 | 1711 | //sourcenode.parent.parent.Dump(); |
---|
1124 | | - goalx = goal.x; |
---|
1125 | | - goalz = goal.z; |
---|
1126 | | - targetx = targetz = 0; |
---|
| 1712 | + goalposx = goal.x; |
---|
| 1713 | + goalposz = goal.z; |
---|
| 1714 | + targetdirx = targetdirz = 0; |
---|
1127 | 1715 | |
---|
1128 | 1716 | followpath = true; |
---|
1129 | 1717 | } |
---|
.. | .. |
---|
1174 | 1762 | // } |
---|
1175 | 1763 | if (false) // !uselast) |
---|
1176 | 1764 | { |
---|
1177 | | - CameraPane.debugpoint.toParent[3][0] = dst.x; |
---|
1178 | | - CameraPane.debugpoint.toParent[3][1] = dst.y; |
---|
1179 | | - 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; |
---|
1180 | 1768 | } |
---|
1181 | 1769 | } |
---|
1182 | 1770 | |
---|
1183 | | - if (goalx != 0 || goalz != 0) // TODO |
---|
| 1771 | + if (goalposx != 0 || goalposz != 0) // TODO |
---|
1184 | 1772 | { |
---|
1185 | 1773 | // overwrite speaker orientation |
---|
1186 | | - dst.set(goalx,0,goalz); |
---|
| 1774 | + dst.set(goalposx,0,goalposz); |
---|
1187 | 1775 | if (sourcenode.parent != null) // july 2014 |
---|
1188 | 1776 | sourcenode.parent. |
---|
1189 | 1777 | TransformToLocal(dst); |
---|
.. | .. |
---|
1199 | 1787 | src.x = 0; |
---|
1200 | 1788 | src.y = 0; |
---|
1201 | 1789 | src.z = 0; |
---|
| 1790 | + LA.xformPos(src, get(0).get(0).toParent, src); |
---|
1202 | 1791 | LA.xformPos(src, get(0).toParent, src); |
---|
1203 | 1792 | LA.xformPos(src, toParent, src); |
---|
1204 | 1793 | // LA.xformPos(src, rotsourcenode.toParent, src); |
---|
.. | .. |
---|
1234 | 1823 | // mars 2014 |
---|
1235 | 1824 | if (false) // goalx != 0 || goalz != 0) |
---|
1236 | 1825 | { |
---|
1237 | | - targetx = dst.x - src.x; |
---|
1238 | | - targetz = dst.z - src.z; |
---|
| 1826 | + targetdirx = dst.x - src.x; |
---|
| 1827 | + targetdirz = dst.z - src.z; |
---|
1239 | 1828 | |
---|
1240 | | - if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1) |
---|
| 1829 | + if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1) |
---|
1241 | 1830 | { |
---|
1242 | 1831 | // far enough from goal. keep the goal position. |
---|
1243 | | - targetx = 0; |
---|
1244 | | - targetz = 0; |
---|
| 1832 | + targetdirx = 0; |
---|
| 1833 | + targetdirz = 0; |
---|
1245 | 1834 | } |
---|
1246 | 1835 | else |
---|
1247 | 1836 | { |
---|
1248 | 1837 | // too close to goal. switch to target direction instead. |
---|
1249 | | - goalx = 0; |
---|
1250 | | - goalz = 0; |
---|
| 1838 | + goalposx = 0; |
---|
| 1839 | + goalposz = 0; |
---|
1251 | 1840 | } |
---|
1252 | 1841 | } |
---|
1253 | 1842 | |
---|
1254 | 1843 | //sourcenode.getCentroid(src, true); |
---|
1255 | 1844 | |
---|
1256 | | - if (speakernode == sourcenode && goalx == 0 && goalz == 0) |
---|
| 1845 | + if (speakernode == sourcenode && goalposx == 0 && goalposz == 0) |
---|
1257 | 1846 | { |
---|
1258 | 1847 | if (ScriptNode.lastspeaker != null) |
---|
1259 | 1848 | new Exception().printStackTrace(); |
---|
.. | .. |
---|
1262 | 1851 | |
---|
1263 | 1852 | // LA.xformPos(src, fromParent, src); |
---|
1264 | 1853 | |
---|
1265 | | - 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) |
---|
1266 | 1855 | dst.sub(src); |
---|
1267 | 1856 | else |
---|
1268 | 1857 | // vector mode |
---|
1269 | 1858 | { |
---|
1270 | | - dst.x = targetx; |
---|
1271 | | - dst.z = targetz; |
---|
| 1859 | + dst.x = targetdirx; |
---|
| 1860 | + dst.z = targetdirz; |
---|
1272 | 1861 | |
---|
1273 | 1862 | // TEST TARGET |
---|
1274 | 1863 | // dst.x = CameraPane.selectedpoint.toParent[3][0]; |
---|
.. | .. |
---|
1542 | 2131 | toParent = LA.newMatrix(); |
---|
1543 | 2132 | fromParent = LA.newMatrix(); |
---|
1544 | 2133 | } |
---|
| 2134 | + |
---|
1545 | 2135 | LA.matConcat(toParent, rotsourcenode.toParent, toParent); |
---|
1546 | 2136 | LA.matInvert(toParent, fromParent); |
---|
1547 | 2137 | |
---|
.. | .. |
---|
1677 | 2267 | } |
---|
1678 | 2268 | |
---|
1679 | 2269 | if (!smoothed) |
---|
1680 | | - for (int i=4; --i>=0;) |
---|
| 2270 | + for (int i=0; --i>=0;) |
---|
1681 | 2271 | SmoothAnimData(); // much reduces shakiness |
---|
1682 | 2272 | |
---|
1683 | 2273 | smoothed = true; |
---|
.. | .. |
---|
1715 | 2305 | toVector.x = LA.cos(to); |
---|
1716 | 2306 | toVector.y = LA.sin(to); |
---|
1717 | 2307 | |
---|
| 2308 | + double fromA = Math.atan2(fromVector.y, fromVector.x); |
---|
| 2309 | + double toA = Math.atan2(toVector.y, toVector.x); |
---|
| 2310 | + |
---|
1718 | 2311 | Vector2d currentVector = Slerp(fromVector, toVector, step); |
---|
1719 | 2312 | |
---|
1720 | | - 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; |
---|
1721 | 2318 | } |
---|
1722 | 2319 | |
---|
1723 | 2320 | public static Vector2d Slerp(Vector2d from, Vector2d to, double step) |
---|
.. | .. |
---|
1759 | 2356 | if (!live) // aout 2013 |
---|
1760 | 2357 | return; |
---|
1761 | 2358 | |
---|
1762 | | - cVector centroid = new cVector(); |
---|
1763 | | - cVector floor = new cVector(); |
---|
1764 | | - |
---|
1765 | | - 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 | + } |
---|
1766 | 2369 | |
---|
1767 | | - 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); |
---|
1768 | 2381 | // if (!success) |
---|
1769 | 2382 | // { |
---|
1770 | 2383 | // //assert(success); |
---|
.. | .. |
---|
1772 | 2385 | // System.out.println("No centroid for " + sourcenode); |
---|
1773 | 2386 | // } |
---|
1774 | 2387 | |
---|
1775 | | - //bvh.skeleton.setPose(f, bvh.animation.getBoneData(bvh.skeleton.getIndex()), null); |
---|
1776 | | - try |
---|
1777 | | - { |
---|
1778 | | - SetPose(GetSkeleton(), bvh.animation, f); |
---|
1779 | | - } |
---|
1780 | | - catch (Exception e) |
---|
1781 | | - { |
---|
1782 | | - e.printStackTrace(); |
---|
1783 | | - } |
---|
1784 | | - |
---|
1785 | 2388 | if (sourcenode.parent == null && sourcenode.fileparent == null) |
---|
1786 | 2389 | { |
---|
1787 | 2390 | // No GFD |
---|
.. | .. |
---|
1835 | 2438 | { |
---|
1836 | 2439 | SetRotation(sourcenode, new cVector(floor), new cVector(centroid)); |
---|
1837 | 2440 | } |
---|
1838 | | - |
---|
| 2441 | + |
---|
1839 | 2442 | if (setposition) |
---|
1840 | 2443 | { |
---|
1841 | 2444 | if (floorobject != null) |
---|
.. | .. |
---|
2029 | 2632 | * @param frame |
---|
2030 | 2633 | * Frame number |
---|
2031 | 2634 | */ |
---|
2032 | | - 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) |
---|
2033 | 2636 | { |
---|
2034 | 2637 | if (!live) // aout 2013 |
---|
2035 | 2638 | return; |
---|
.. | .. |
---|
2037 | 2640 | cVector temp = new cVector(); |
---|
2038 | 2641 | cVector temp0 = new cVector(); |
---|
2039 | 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 | + } |
---|
2040 | 2670 | |
---|
2041 | 2671 | // Object3D obj = get(0); |
---|
2042 | 2672 | // Object3D gp = this.parent; |
---|
.. | .. |
---|
2167 | 2797 | //if (bone._rotationEnabled) |
---|
2168 | 2798 | if (//frame > 0 && |
---|
2169 | 2799 | !bone.skipmocap && |
---|
2170 | | - !bone.name.contains("head") && |
---|
| 2800 | + !bone.name.contains("head") // && |
---|
2171 | 2801 | // !bone.name.contains("rFoot") && |
---|
2172 | 2802 | // !bone.name.contains("lFoot") && |
---|
2173 | | - !bone.name.contains("Pinky") && |
---|
2174 | | - !bone.name.contains("Ring") && |
---|
2175 | | - !bone.name.contains("Mid") && |
---|
2176 | | - !bone.name.contains("Index") && |
---|
2177 | | - !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") |
---|
2178 | 2808 | ) |
---|
2179 | 2809 | { |
---|
2180 | 2810 | //_rotTG.setTransform(_t1); |
---|
.. | .. |
---|
2207 | 2837 | // CROWD |
---|
2208 | 2838 | //cJ3D.GetTranslation(bone, _trans0); |
---|
2209 | 2839 | //_trans.add(_trans0); |
---|
2210 | | - _transTF.setIdentity(); |
---|
| 2840 | + //_transTF.setIdentity(); |
---|
| 2841 | + _transTF.set(_t1); |
---|
2211 | 2842 | _transTF.setTranslation(_trans); |
---|
2212 | 2843 | // System.err.println("Translate: " + _transTF); |
---|
2213 | 2844 | //_transTG.setTransform(_transTF); |
---|
2214 | | - 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 |
---|
2215 | 2847 | } |
---|
2216 | 2848 | } |
---|
2217 | 2849 | |
---|
2218 | | - if (bone._isRoot && firsttimeafterload && frame > 0) |
---|
| 2850 | + if (false) // bone._isRoot && firsttimeafterload && frame > 0) |
---|
2219 | 2851 | { |
---|
2220 | 2852 | assert(bone == get(0)); |
---|
2221 | 2853 | |
---|
.. | .. |
---|
2231 | 2863 | // LA.matConcat(originmatrixinv, tempmatrixinv, fromParent); // ABC * (B'*C')^-1 |
---|
2232 | 2864 | // |
---|
2233 | 2865 | |
---|
2234 | | - Invariants(); |
---|
2235 | | - bone.Invariants(); |
---|
2236 | | - bone.get(0).Invariants(); |
---|
2237 | | - // if (origin == null) |
---|
2238 | | - // origin = null; |
---|
2239 | | - origin.Invariants(); |
---|
2240 | | - 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(); |
---|
2241 | 2873 | |
---|
2242 | | - |
---|
2243 | | - LA.matConcat(bone.get(0).fromParent, bone.fromParent, tempmatrix); // B' * C' |
---|
2244 | | - 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); |
---|
2245 | 2877 | |
---|
2246 | 2878 | // matrixToEulerXYZ(toParent, temp); |
---|
2247 | 2879 | // matrixToEulerXYZ(bone.get(0).toParent, temp); |
---|
.. | .. |
---|
2275 | 2907 | // |
---|
2276 | 2908 | // mat4d.get(quat); |
---|
2277 | 2909 | |
---|
2278 | | - if (true) // hip correction |
---|
| 2910 | + if (false) // hip correction |
---|
2279 | 2911 | { |
---|
2280 | 2912 | _t2.setIdentity(); |
---|
2281 | 2913 | |
---|
.. | .. |
---|
2316 | 2948 | //????? LA.matConcat(bone.get(0).toParent, bone.toParent, tempmatrix); // B' * C' |
---|
2317 | 2949 | // LA.matConcat(origin.fromParent, tempmatrix, fromParent); |
---|
2318 | 2950 | |
---|
2319 | | - LA.matInvert(toParent, fromParent); |
---|
| 2951 | +//?? LA.matInvert(toParent, fromParent); |
---|
2320 | 2952 | |
---|
2321 | | - Invariants(); |
---|
2322 | | - bone.Invariants(); |
---|
2323 | | - bone.get(0).Invariants(); |
---|
2324 | | - origin.Invariants(); |
---|
2325 | | - origin0.Invariants(); |
---|
| 2953 | + Invariants(); |
---|
| 2954 | + bone.Invariants(); |
---|
| 2955 | + bone.get(0).Invariants(); |
---|
| 2956 | + origin.Invariants(); |
---|
| 2957 | + origin0.Invariants(); |
---|
2326 | 2958 | |
---|
2327 | 2959 | // LA.matInvert(fromParent, tempmatrix); |
---|
2328 | 2960 | // |
---|
.. | .. |
---|
2343 | 2975 | // temp.x = data[0]; |
---|
2344 | 2976 | // temp.y = data[1]; |
---|
2345 | 2977 | // temp.z = data[2]; |
---|
2346 | | - LA.xformPos(temp, origin0.toParent, temp0); |
---|
| 2978 | + LA.xformPos(temp, origin0.toParent, temp0); // NU |
---|
2347 | 2979 | |
---|
2348 | | -// bone.GlobalTransformInv(); |
---|
2349 | | - |
---|
2350 | | - temp0.x = bone.globalTransform[3][0]; |
---|
2351 | | - temp0.y = bone.globalTransform[3][1]; |
---|
2352 | | - temp0.z = bone.globalTransform[3][2]; |
---|
2353 | | - |
---|
| 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 | +// |
---|
2354 | 2986 | // MEGA TEST // june 2014: necessary for precision? otherwise comment works |
---|
2355 | | -fromParent[3][0] = 0; |
---|
2356 | | -fromParent[3][1] = 0; |
---|
2357 | | -fromParent[3][2] = 0; |
---|
2358 | | -LA.matInvert(fromParent, toParent); |
---|
| 2987 | +//fromParent[3][0] = 0; |
---|
| 2988 | +//fromParent[3][1] = 0; |
---|
| 2989 | +//fromParent[3][2] = 0; |
---|
| 2990 | +//LA.matInvert(fromParent, toParent); |
---|
2359 | 2991 | |
---|
2360 | | - LA.xformPos(temp0, fromParent, temp); |
---|
| 2992 | + LA.xformPos(temp0, fromParent, temp); // NU |
---|
2361 | 2993 | //LA.xformPos(temp, bone.fromParent, temp); |
---|
2362 | 2994 | // float[] data; |
---|
2363 | 2995 | |
---|
2364 | | - pos[0] = temp.x; |
---|
2365 | | - pos[1] = temp.y; |
---|
2366 | | - 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); |
---|
2367 | 3005 | |
---|
2368 | 3006 | // CameraPane.selectedpoint.toParent[3][0] = temp0.x; |
---|
2369 | 3007 | // CameraPane.selectedpoint.toParent[3][1] = temp0.y; |
---|
2370 | 3008 | // CameraPane.selectedpoint.toParent[3][2] = temp0.z; |
---|
2371 | 3009 | |
---|
2372 | | - int numframes = bvh.animation.getNumFrames(); |
---|
| 3010 | + int numframes = bvh.animation.getNumFrames(); |
---|
2373 | 3011 | |
---|
2374 | 3012 | int b = 0; |
---|
2375 | 3013 | { |
---|
.. | .. |
---|
2377 | 3015 | |
---|
2378 | 3016 | int dof = 6; /// data.length/numframes; |
---|
2379 | 3017 | |
---|
2380 | | - // july 2014 |
---|
2381 | | - if (dof != data.length/numframes) |
---|
2382 | | - { |
---|
2383 | | - System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (data.length/numframes)); |
---|
2384 | | - dof = data.length/numframes; |
---|
2385 | | - } |
---|
| 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 | + } |
---|
2386 | 3024 | |
---|
2387 | 3025 | |
---|
2388 | 3026 | int theframe = 0; // baseframe; |
---|
.. | .. |
---|
2434 | 3072 | // } |
---|
2435 | 3073 | // } |
---|
2436 | 3074 | |
---|
2437 | | - data[f3 + i] += pos[i] - data[frame3 + i]; |
---|
| 3075 | + data[f3 + i] += /*pos[i]*/ - data[frame3 + i]; |
---|
2438 | 3076 | |
---|
2439 | 3077 | // if (f < 3) |
---|
2440 | 3078 | // { |
---|
2441 | 3079 | // System.out.print(data[f3 + i] + " "); |
---|
2442 | 3080 | // } |
---|
2443 | 3081 | } |
---|
2444 | | -// if (f < 3) |
---|
2445 | | -// { |
---|
2446 | | -// System.out.println(); |
---|
2447 | | -// } |
---|
| 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]; |
---|
2448 | 3095 | } |
---|
2449 | 3096 | } |
---|
2450 | 3097 | |
---|
.. | .. |
---|
2458 | 3105 | // temp.y = data[1]; |
---|
2459 | 3106 | // temp.z = data[2]; |
---|
2460 | 3107 | |
---|
2461 | | - if (fade && currentbones != null && !CameraPane.fullreset) |
---|
2462 | | - { |
---|
2463 | | - Quat4d quatstart = new Quat4d(); |
---|
2464 | | - Quat4d quatend = new Quat4d(); |
---|
2465 | | - Quat4d quat = new Quat4d(); |
---|
2466 | | - Matrix4d mat4d = new Matrix4d(); |
---|
2467 | | - double[][] rot = new double[4][4]; |
---|
2468 | | - |
---|
2469 | | - for (b=numbones; --b>=1;) // HIP ROTATION: 0;) |
---|
2470 | | - { |
---|
2471 | | - int hipindex = get(0)._index; |
---|
2472 | | - |
---|
2473 | | -// assert(get(0).get(0)._isHip); |
---|
2474 | | - |
---|
2475 | | - // if (b == hipindex) |
---|
2476 | | - // continue; |
---|
2477 | | - |
---|
2478 | | - data = bvh.animation.getBoneData(b); |
---|
2479 | | - |
---|
2480 | | - int dof = 3; // data.length/numframes; |
---|
2481 | | - |
---|
2482 | | - // assert(dof == 3); |
---|
2483 | | - |
---|
2484 | | - int boneframe3 = b*3; // dof; |
---|
2485 | | - |
---|
2486 | | - // System.err.println("Bone #" + b + ": dof = " + dof); |
---|
2487 | | - int fadein = 45; // 120; |
---|
2488 | | - |
---|
2489 | | - // if (b == hipindex) |
---|
2490 | | - // fadein *= 5; |
---|
2491 | | - |
---|
2492 | | - if (fadein > numframes) |
---|
2493 | | - fadein = 0; // numframes; |
---|
2494 | | - |
---|
2495 | | - for (int fi=fadein; --fi>=0;) |
---|
2496 | | - //for (int f=numframes; --f>=0;) |
---|
2497 | | - { |
---|
2498 | | - int f = fi + GetFirstFrame(); |
---|
2499 | | - |
---|
2500 | | - int f3 = f*dof; |
---|
2501 | | - |
---|
2502 | | - float k = fi; |
---|
2503 | | - |
---|
2504 | | - k /= fadein - 1; |
---|
2505 | | - |
---|
2506 | | - if (Float.isNaN(k)) |
---|
2507 | | - k = 1; // 0/0 |
---|
2508 | | - |
---|
2509 | | - k = (float) (-Math.cos(k*Math.PI)); |
---|
2510 | | - k += 1; |
---|
2511 | | - k /= 2; |
---|
2512 | | - |
---|
2513 | | - int start = 3; |
---|
2514 | | - int end = 0; |
---|
2515 | | - |
---|
2516 | | - if (dof == 6) |
---|
2517 | | - { |
---|
2518 | | - start = 6; |
---|
2519 | | - end = 3; |
---|
2520 | | - } |
---|
2521 | | - |
---|
2522 | | - if (b == 0) |
---|
2523 | | - { |
---|
2524 | | - _t1.setIdentity(); |
---|
2525 | | - _t2.setIdentity(); |
---|
2526 | | - _t2.rotZ(currentbones[boneframe3 + start-1-end]); |
---|
2527 | | - _t1.mul(_t2); |
---|
2528 | | - _t2.setIdentity(); |
---|
2529 | | - if (b == 0) |
---|
2530 | | - { |
---|
2531 | | - _t2.rotY(currentbones[boneframe3 + start-2-end]); |
---|
2532 | | - _t1.mul(_t2); |
---|
2533 | | - _t2.setIdentity(); |
---|
2534 | | - _t2.rotX(currentbones[boneframe3 + start-3-end]); |
---|
2535 | | - } |
---|
2536 | | - else |
---|
2537 | | - { |
---|
2538 | | - _t2.rotX(currentbones[boneframe3 + start-2-end]); |
---|
2539 | | - _t1.mul(_t2); |
---|
2540 | | - _t2.setIdentity(); |
---|
2541 | | - _t2.rotY(currentbones[boneframe3 + start-3-end]); |
---|
2542 | | - } |
---|
2543 | | - _t1.mul(_t2); |
---|
2544 | | - _t2.setIdentity(); |
---|
2545 | | - |
---|
2546 | | - _t1.get(mat4d); |
---|
2547 | | - |
---|
2548 | | - mat4d.get(quatstart); |
---|
2549 | | - |
---|
2550 | | - _t1.setIdentity(); |
---|
2551 | | - _t2.setIdentity(); |
---|
2552 | | - _t2.rotZ(data[f3 + start-1]); |
---|
2553 | | - _t1.mul(_t2); |
---|
2554 | | - _t2.setIdentity(); |
---|
2555 | | - if (b == 0) |
---|
2556 | | - { |
---|
2557 | | - _t2.rotY(data[f3 + start-2]); |
---|
2558 | | - _t1.mul(_t2); |
---|
2559 | | - _t2.setIdentity(); |
---|
2560 | | - _t2.rotX(data[f3 + start-3]); |
---|
2561 | | - } |
---|
2562 | | - else |
---|
2563 | | - { |
---|
2564 | | - _t2.rotX(data[f3 + start-2]); |
---|
2565 | | - _t1.mul(_t2); |
---|
2566 | | - _t2.setIdentity(); |
---|
2567 | | - _t2.rotY(data[f3 + start-3]); |
---|
2568 | | - } |
---|
2569 | | - |
---|
2570 | | - _t1.mul(_t2); |
---|
2571 | | - _t2.setIdentity(); |
---|
2572 | | - |
---|
2573 | | - _t1.get(mat4d); |
---|
2574 | | - |
---|
2575 | | - mat4d.get(quatend); |
---|
2576 | | - |
---|
2577 | | - double dot = quatstart.x*quatend.x + |
---|
2578 | | - quatstart.y*quatend.y + |
---|
2579 | | - quatstart.z*quatend.z + |
---|
2580 | | - quatstart.w*quatend.w |
---|
2581 | | - ; |
---|
2582 | | - |
---|
2583 | | - if (dot < 0) |
---|
2584 | | - { |
---|
2585 | | - quatend.x *= -1; |
---|
2586 | | - quatend.y *= -1; |
---|
2587 | | - quatend.z *= -1; |
---|
2588 | | - quatend.w *= -1; |
---|
2589 | | - } |
---|
2590 | | - |
---|
2591 | | - // k = 1-k; |
---|
2592 | | - |
---|
2593 | | - quat.x = (1-k)*quatstart.x + k*quatend.x; |
---|
2594 | | - quat.y = (1-k)*quatstart.y + k*quatend.y; |
---|
2595 | | - quat.z = (1-k)*quatstart.z + k*quatend.z; |
---|
2596 | | - quat.w = (1-k)*quatstart.w + k*quatend.w; |
---|
2597 | | - |
---|
2598 | | - quat.normalize(); |
---|
2599 | | - |
---|
2600 | | - mat4d.set(quat); |
---|
2601 | | - |
---|
2602 | | - cJ3D.SetTransform(rot, mat4d); |
---|
2603 | | - |
---|
2604 | | - matrixToEulerXYZ(rot, temp); |
---|
2605 | | - |
---|
2606 | | - data[f3 + start-1] = -(float)temp.z; |
---|
2607 | | - |
---|
2608 | | - if (b == 0) |
---|
2609 | | - { |
---|
2610 | | - data[f3 + start-2] = -(float)temp.y; |
---|
2611 | | - data[f3 + start-3] = -(float)temp.x; |
---|
2612 | | - } |
---|
2613 | | - else |
---|
2614 | | - { |
---|
2615 | | - data[f3 + start-2] = -(float)temp.x; |
---|
2616 | | - data[f3 + start-3] = -(float)temp.y; |
---|
2617 | | - } |
---|
2618 | | - } |
---|
2619 | | - else |
---|
2620 | | - { |
---|
2621 | | - for (int i=start; --i>=end;) |
---|
2622 | | - { |
---|
2623 | | - //data[f3 + i] += pos[i] - data[frame3 + i]; |
---|
2624 | | - // data[f3 + i] = k*data[f3+i] + (1-k)* |
---|
2625 | | - // currentbones[boneframe3 + i-end]; |
---|
2626 | | - data[f3 + i] = (float)CurveAngle(data[f3+i], currentbones[boneframe3 + i-end], 1-k); |
---|
2627 | | - } |
---|
2628 | | - } |
---|
2629 | | - |
---|
2630 | | - } |
---|
2631 | | - } |
---|
2632 | | - |
---|
2633 | | - } |
---|
| 3108 | +// if (fade && currentbones != null && !CameraPane.fullreset) |
---|
| 3109 | +// { |
---|
| 3110 | +// Fade(); |
---|
| 3111 | +// } |
---|
2634 | 3112 | } |
---|
2635 | | - |
---|
| 3113 | + |
---|
2636 | 3114 | if (false) // doesn't change anything bone._isRoot) |
---|
2637 | 3115 | { |
---|
2638 | 3116 | // Reset orientation |
---|
2639 | 3117 | _t2.setIdentity(); |
---|
2640 | | - |
---|
| 3118 | + |
---|
2641 | 3119 | double tx = bone.toParent[3][0]; |
---|
2642 | 3120 | double ty = bone.toParent[3][1]; |
---|
2643 | 3121 | double tz = bone.toParent[3][2]; |
---|
.. | .. |
---|
2646 | 3124 | temp.y = 0; |
---|
2647 | 3125 | temp.z = 0; |
---|
2648 | 3126 | LA.xformDir(temp, bone.toParent, temp); |
---|
2649 | | - |
---|
| 3127 | + |
---|
2650 | 3128 | double angle = Math.atan2(-temp.z, temp.x); |
---|
2651 | | - |
---|
| 3129 | + |
---|
2652 | 3130 | _t2.rotY(angle); |
---|
2653 | 3131 | // _t1.setIdentity(); |
---|
2654 | 3132 | // _t1.rotX(temp.x); |
---|
.. | .. |
---|
2661 | 3139 | // _t1.setIdentity(); |
---|
2662 | 3140 | // _t1.rotZ(temp.z); |
---|
2663 | 3141 | // _t2.mul(_t1); |
---|
2664 | | - |
---|
| 3142 | + |
---|
2665 | 3143 | cJ3D.ResetTransform(bone, _t2, false); |
---|
2666 | | - |
---|
| 3144 | + |
---|
2667 | 3145 | bone.toParent[3][0] = tx; |
---|
2668 | 3146 | bone.toParent[3][1] = ty; |
---|
2669 | 3147 | bone.toParent[3][2] = tz; |
---|
2670 | 3148 | } |
---|
2671 | 3149 | } |
---|
2672 | 3150 | |
---|
2673 | | - if (currentbones == null) |
---|
2674 | | - currentbones = new double[numbones*3]; |
---|
2675 | | - |
---|
2676 | | - for (int b=numbones; --b>=1;) // 0;) |
---|
2677 | | - //int b = 0; |
---|
2678 | | - { |
---|
2679 | | - data = bvh.animation.getBoneData(b); |
---|
2680 | | - |
---|
2681 | | - int numframes = bvh.animation.getNumFrames(); |
---|
2682 | | - |
---|
2683 | | - int dof = 6; // data.length/numframes; |
---|
2684 | | - |
---|
2685 | | - if (b > 0) |
---|
2686 | | - dof = 3; |
---|
2687 | | - |
---|
2688 | | - //assert(dof == 3); |
---|
2689 | | - |
---|
2690 | | - // System.err.println("Bone #" + b + ": dof = " + dof); |
---|
2691 | | - int theframe = // 1; // baseframe; |
---|
2692 | | - frame; |
---|
2693 | | - |
---|
2694 | | - int frame3 = theframe*dof; |
---|
2695 | | - int bone3 = b*3; // dof; |
---|
2696 | | - |
---|
2697 | | - int start = 3; |
---|
2698 | | - int end = 0; |
---|
2699 | | - |
---|
2700 | | - if (dof == 6) |
---|
2701 | | - { |
---|
2702 | | - start = 6; |
---|
2703 | | - end = 3; |
---|
2704 | | - } |
---|
2705 | | - for (int i=start; --i>=end;) |
---|
2706 | | - { |
---|
2707 | | - currentbones[bone3 + i-end] = data[frame3 + i]; |
---|
2708 | | - } |
---|
2709 | | - } |
---|
| 3151 | + // SetCurrentBones(frame); |
---|
2710 | 3152 | } |
---|
2711 | 3153 | } |
---|
2712 | 3154 | |
---|
2713 | | - static int offset = 1; // 5; // 10; // 5; // 100; // skip initial "T" |
---|
| 3155 | + // skip initial "T" |
---|
| 3156 | + static int offset = 1; // 5; // 10; // 5; // 100; |
---|
2714 | 3157 | |
---|
2715 | 3158 | void ReadBVH() |
---|
2716 | 3159 | { |
---|
.. | .. |
---|
2739 | 3182 | |
---|
2740 | 3183 | void Reset() |
---|
2741 | 3184 | { |
---|
2742 | | - if (fullname != null) |
---|
2743 | | - ReadBVH(); |
---|
| 3185 | +// if (fullname != null) |
---|
| 3186 | +// ReadBVH(); |
---|
2744 | 3187 | |
---|
2745 | 3188 | Object3D hip = get(0); |
---|
2746 | 3189 | |
---|
2747 | 3190 | // assert(obj.name.equals("hip")); |
---|
2748 | 3191 | |
---|
2749 | | - Object3D rot = hip.get(0); |
---|
| 3192 | + //Object3D rot = hip.get(0); |
---|
2750 | 3193 | |
---|
2751 | 3194 | // assert(obj.name == null); // .equals("hip#")); |
---|
2752 | 3195 | |
---|
.. | .. |
---|
2756 | 3199 | hip.fromParent = LA.newMatrix(); |
---|
2757 | 3200 | } |
---|
2758 | 3201 | |
---|
2759 | | - hip.toParent[3][0] = hip.toParent[3][1] = hip.toParent[3][2] = 0; |
---|
2760 | | - 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; |
---|
2761 | 3204 | |
---|
2762 | 3205 | if (toParent == null) |
---|
2763 | 3206 | { |
---|
.. | .. |
---|
2769 | 3212 | LA.matIdentity(fromParent); |
---|
2770 | 3213 | // LA.matIdentity(hip.toParent); |
---|
2771 | 3214 | // LA.matIdentity(hip.fromParent); |
---|
2772 | | - if (rot.toParent == null) |
---|
2773 | | - { |
---|
2774 | | - // june 2014 |
---|
2775 | | - rot.toParent = LA.newMatrix(); |
---|
2776 | | - rot.fromParent = LA.newMatrix(); |
---|
2777 | | - } |
---|
2778 | | - LA.matIdentity(rot.toParent); |
---|
2779 | | - 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); |
---|
2780 | 3223 | |
---|
2781 | 3224 | // july 2014 |
---|
2782 | | - goalx = goalz = 0; |
---|
2783 | | - targetx = targetz = 0; |
---|
| 3225 | +// goalx = goalz = 0; |
---|
| 3226 | + targetdirx = targetdirz = 0; |
---|
2784 | 3227 | |
---|
2785 | | - SetPositionDelta(true, true, true, false); |
---|
| 3228 | + //SetPositionDelta(true, true, true, false); |
---|
| 3229 | +// LoadData(); |
---|
| 3230 | +// Rewind(); |
---|
2786 | 3231 | |
---|
2787 | 3232 | baseframe = frame = 0; // T pose. No offset. |
---|
2788 | 3233 | |
---|
2789 | 3234 | // aout 2013 endframe = 0; // june 2013 |
---|
2790 | 3235 | |
---|
| 3236 | + //ResetZero(); |
---|
2791 | 3237 | setPose(frame); |
---|
2792 | 3238 | } |
---|
2793 | 3239 | |
---|
.. | .. |
---|
2819 | 3265 | baseframe += step; |
---|
2820 | 3266 | |
---|
2821 | 3267 | //frame = baseframe; |
---|
2822 | | - frame += step; |
---|
| 3268 | + //frame += step; |
---|
2823 | 3269 | |
---|
2824 | 3270 | // if (frame != baseframe) |
---|
2825 | 3271 | // { |
---|
.. | .. |
---|
2833 | 3279 | if (lastframetest == 0) |
---|
2834 | 3280 | lastframetest = bvh.animation.getNumFrames(); |
---|
2835 | 3281 | |
---|
| 3282 | + // WARNING: RESET DESTROYS EVERYTHING |
---|
2836 | 3283 | if (baseframe >= lastframetest) // july 2013 // - GetFirstFrame()) |
---|
2837 | 3284 | { |
---|
2838 | 3285 | System.out.println("MOCAP reset: " + this.GetFileRoot() + |
---|
.. | .. |
---|
2858 | 3305 | { |
---|
2859 | 3306 | bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh; |
---|
2860 | 3307 | |
---|
2861 | | - SetPositionDelta(false, true, true, true); |
---|
| 3308 | + // SetPositionDelta(false, true, true, true); |
---|
| 3309 | + LoadData(); |
---|
| 3310 | + Rewind(); |
---|
| 3311 | + Fade(); |
---|
2862 | 3312 | } |
---|
2863 | 3313 | catch (Exception e) |
---|
2864 | 3314 | { |
---|
.. | .. |
---|
2867 | 3317 | } |
---|
2868 | 3318 | } |
---|
2869 | 3319 | } |
---|
| 3320 | + |
---|
| 3321 | + frame = GetFirstFrame(); |
---|
2870 | 3322 | } |
---|
| 3323 | + else |
---|
| 3324 | + frame += step; |
---|
2871 | 3325 | |
---|
2872 | 3326 | //SetPositionDelta(false); |
---|
2873 | 3327 | |
---|
2874 | | - if (frame >= bvh.animation.getNumFrames()) |
---|
2875 | | - //baseframe = |
---|
2876 | | - frame = GetFirstFrame(); // 0; // offset; // initial point |
---|
| 3328 | +// if (frame >= bvh.animation.getNumFrames()) |
---|
| 3329 | +// //baseframe = |
---|
| 3330 | +// frame = GetFirstFrame(); // 0; // offset; // initial point |
---|
2877 | 3331 | |
---|
2878 | 3332 | //System.err.println("frame = " + frame); |
---|
2879 | 3333 | if (lastframe != 0) |
---|
.. | .. |
---|
3171 | 3625 | //static |
---|
3172 | 3626 | transient |
---|
3173 | 3627 | double[] currentbones; |
---|
| 3628 | + double[] currenthip; |
---|
| 3629 | + |
---|
3174 | 3630 | transient boolean inbetween; |
---|
3175 | 3631 | |
---|
3176 | 3632 | void SetPositionDelta(boolean reset, boolean rewind, boolean load, boolean fade) |
---|
.. | .. |
---|
3181 | 3637 | //assert(dim == numframes*6); |
---|
3182 | 3638 | |
---|
3183 | 3639 | if (load) |
---|
3184 | | - for (int b=numbones; --b>=0;) |
---|
3185 | | - //int b = 0; |
---|
3186 | | - { |
---|
3187 | | - float[] thedata = bvh.animation.getBoneData(b); |
---|
3188 | | - |
---|
3189 | | - int numframes = bvh.animation.getNumFrames(); |
---|
3190 | | - |
---|
3191 | | - int dof = 6; // thedata.length/numframes; |
---|
3192 | | - |
---|
3193 | | - if (b > 0) |
---|
3194 | | - dof = 3; |
---|
3195 | | - |
---|
3196 | | - if (dof != thedata.length/numframes) |
---|
3197 | | - { |
---|
3198 | | - System.err.println("Bone #" + b + ": dof = " + dof + " ---> " + (thedata.length/numframes)); |
---|
3199 | | - dof = thedata.length/numframes; |
---|
3200 | | - } |
---|
3201 | | - |
---|
3202 | | - //for (int f=numframes; --f>=offset;) |
---|
3203 | | - int firstframe = GetFirstFrame(); |
---|
3204 | | - for (int f=0; f<numframes-firstframe; f++) |
---|
3205 | | - { |
---|
3206 | | - int f3 = f*dof; |
---|
3207 | | - |
---|
3208 | | - //for (int i=3/*dof*/; --i>=0;) |
---|
3209 | | - for (int i=dof; --i>=0;) |
---|
3210 | | - { |
---|
3211 | | - //thedata[f3 + i] += thedata[i] - thedata[offset*dof + i]; |
---|
3212 | | - thedata[f3 + i] = thedata[f3 + firstframe*dof + i]; |
---|
3213 | | - } |
---|
3214 | | - } |
---|
3215 | | - } |
---|
| 3640 | + { |
---|
| 3641 | + LoadData(); |
---|
| 3642 | + } |
---|
3216 | 3643 | |
---|
3217 | 3644 | // assert(thedata[0] == 0); |
---|
3218 | 3645 | // assert(thedata[1] == 0); |
---|
.. | .. |
---|
3222 | 3649 | // assert(thedata[7] == 0); |
---|
3223 | 3650 | // assert(thedata[8] == 0); |
---|
3224 | 3651 | |
---|
3225 | | - Object3D obj = get(0); |
---|
| 3652 | + Object3D hip = get(0); |
---|
3226 | 3653 | |
---|
3227 | 3654 | // assert(obj.name.equals("hip")); |
---|
3228 | 3655 | |
---|
3229 | | - Object3D rot = obj.get(0); |
---|
| 3656 | + Object3D rot = hip.get(0); |
---|
3230 | 3657 | |
---|
3231 | 3658 | // if (toParent == null) |
---|
3232 | 3659 | // { |
---|
.. | .. |
---|
3238 | 3665 | // // assert(obj.name == null); // .equals("hip#")); |
---|
3239 | 3666 | |
---|
3240 | 3667 | Invariants(); |
---|
3241 | | - obj.Invariants(); |
---|
| 3668 | + hip.Invariants(); |
---|
3242 | 3669 | rot.Invariants(); |
---|
3243 | 3670 | |
---|
3244 | 3671 | if (origin == null) |
---|
.. | .. |
---|
3259 | 3686 | fromParent = LA.newMatrix(); |
---|
3260 | 3687 | } |
---|
3261 | 3688 | |
---|
3262 | | - if (obj.toParent == null) // june 2014 |
---|
| 3689 | + if (hip.toParent == null) // june 2014 |
---|
3263 | 3690 | { |
---|
3264 | | - obj.toParent = LA.newMatrix(); |
---|
3265 | | - obj.fromParent = LA.newMatrix(); |
---|
| 3691 | + hip.toParent = LA.newMatrix(); |
---|
| 3692 | + hip.fromParent = LA.newMatrix(); |
---|
3266 | 3693 | } |
---|
3267 | 3694 | |
---|
3268 | | - LA.matConcat(toParent, obj.toParent, origin0.toParent); // AB |
---|
| 3695 | + LA.matConcat(toParent, hip.toParent, origin0.toParent); // AB |
---|
3269 | 3696 | Object3D gp = this.parent; |
---|
3270 | 3697 | this.parent = null; |
---|
3271 | | - obj.GlobalTransformInv(); |
---|
| 3698 | + hip.GlobalTransformInv(); |
---|
3272 | 3699 | this.parent = gp; |
---|
3273 | 3700 | |
---|
3274 | 3701 | if (rot.toParent == null) |
---|
.. | .. |
---|
3291 | 3718 | LA.matInvert(origin.toParent, origin.fromParent); |
---|
3292 | 3719 | |
---|
3293 | 3720 | Invariants(); |
---|
3294 | | - obj.Invariants(); |
---|
| 3721 | + hip.Invariants(); |
---|
3295 | 3722 | rot.Invariants(); |
---|
3296 | 3723 | origin.Invariants(); |
---|
3297 | 3724 | origin0.Invariants(); |
---|
3298 | 3725 | |
---|
3299 | | - firsttimeafterload = true; |
---|
| 3726 | + firsttimeafterload = false; // true; |
---|
3300 | 3727 | |
---|
3301 | 3728 | if (rewind) |
---|
3302 | 3729 | Rewind(); |
---|
3303 | 3730 | |
---|
3304 | | - setPose(obj, frame, bvh.animation.getBoneData(obj._index), fade); |
---|
| 3731 | + setPose(hip, frame, bvh.animation.getBoneData(hip._index)); //, fade); |
---|
3305 | 3732 | |
---|
3306 | | - if (true) |
---|
3307 | | - return; |
---|
| 3733 | + if (true) |
---|
| 3734 | + return; |
---|
3308 | 3735 | |
---|
3309 | 3736 | double pos[] = new double[6]; |
---|
3310 | 3737 | |
---|
3311 | 3738 | if (!reset) |
---|
3312 | 3739 | { |
---|
3313 | | - assert(obj.tx == obj.toParent[3][0]); |
---|
3314 | | - assert(obj.ty == obj.toParent[3][1]); |
---|
3315 | | - 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]); |
---|
3316 | 3743 | |
---|
3317 | | - pos[0] = obj.tx; // obj.toParent[3][0]; |
---|
3318 | | - pos[1] = obj.ty; // obj.toParent[3][1]; |
---|
3319 | | - pos[2] = obj.tz; // obj.toParent[3][2]; |
---|
3320 | | - pos[3] = obj.rz; |
---|
3321 | | - pos[4] = obj.ry; |
---|
3322 | | - 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; |
---|
3323 | 3750 | } |
---|
3324 | 3751 | |
---|
3325 | 3752 | cVector temp = new cVector(); |
---|
3326 | | - temp.x = obj.globalTransform[3][0]; |
---|
3327 | | - temp.y = obj.globalTransform[3][1]; |
---|
3328 | | - 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]; |
---|
3329 | 3756 | // LA.xformPos(temp, origin0.toParent, temp); |
---|
3330 | 3757 | // System.err.println("POS0 = " + temp.x + ", " + temp.y + ", " + temp.z + ";"); |
---|
3331 | 3758 | |
---|
.. | .. |
---|
3409 | 3836 | } |
---|
3410 | 3837 | |
---|
3411 | 3838 | // Rewind(); |
---|
3412 | | - setPose(obj, frame, bvh.animation.getBoneData(obj._index), true); |
---|
| 3839 | + setPose(hip, frame, bvh.animation.getBoneData(hip._index)); // , true); |
---|
3413 | 3840 | } |
---|
3414 | 3841 | |
---|
3415 | 3842 | void Rewind() |
---|