Revision 9dacabea
Added by Leszek Koltunski almost 6 years ago
| src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
|---|---|---|
| 333 | 333 | return mNumEffects; | 
| 334 | 334 | } | 
| 335 | 335 |  | 
| 336 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 337 |  | |
| 338 | public Effect getEffect(int position) | |
| 339 |     {
 | |
| 340 | if( position>=0 && position< mNumEffects ) | |
| 341 |       {
 | |
| 342 | return mEffects[position]; | |
| 343 | } | |
| 344 | else | |
| 345 |       {
 | |
| 346 |       android.util.Log.e("queue", "getEffect: out of range "+position);
 | |
| 347 | return null; | |
| 348 | } | |
| 349 | } | |
| 350 |  | |
| 336 | 351 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 337 | 352 |  | 
| 338 | 353 | public void doWork() | 
| src/main/java/org/distorted/library/type/Dynamic.java | ||
|---|---|---|
| 301 | 301 |     if( error ) printBase("");
 | 
| 302 | 302 | } | 
| 303 | 303 |  | 
| 304 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 305 |  | |
| 306 | int getNext(int curr, float time) | |
| 307 |     {
 | |
| 308 | switch(mMode) | |
| 309 |       {
 | |
| 310 | case MODE_LOOP: return curr==numPoints-1 ? 0:curr+1; | |
| 311 | case MODE_PATH: return time<0.5f ? (curr+1) : (curr==0 ? 1 : curr-1); | |
| 312 | case MODE_JUMP: return curr==numPoints-1 ? 1:curr+1; | |
| 313 | default : return 0; | |
| 314 | } | |
| 315 | } | |
| 316 |  | |
| 304 | 317 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 305 | 318 |  | 
| 306 | 319 | private void checkAngle(int index) | 
| src/main/java/org/distorted/library/type/Dynamic1D.java | ||
|---|---|---|
| 440 | 440 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | 
| 441 | 441 | else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed | 
| 442 | 442 |                   {
 | 
| 443 | int vecNext; | |
| 444 |  | |
| 445 | switch(mMode) | |
| 446 |                     {
 | |
| 447 | case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; | |
| 448 | break; | |
| 449 | case MODE_PATH: if( t<=0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; | |
| 450 | else vecNext = vecCurr==0 ? 1 : vecCurr-1; | |
| 451 | break; | |
| 452 | case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; | |
| 453 | break; | |
| 454 | default : vecNext = 0; | |
| 455 | } | |
| 456 |  | |
| 443 | int vecNext = getNext(vecCurr,t); | |
| 457 | 444 | next = vv.elementAt(vecNext); | 
| 458 | 445 | tmp2 = vc.elementAt(vecNext); | 
| 459 | 446 |  | 
| src/main/java/org/distorted/library/type/Dynamic2D.java | ||
|---|---|---|
| 473 | 473 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | 
| 474 | 474 | else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed | 
| 475 | 475 |                   {
 | 
| 476 | int vecNext; | |
| 477 |  | |
| 478 | switch(mMode) | |
| 479 |                     {
 | |
| 480 | case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; | |
| 481 | break; | |
| 482 | case MODE_PATH: if( t<=0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; | |
| 483 | else vecNext = vecCurr==0 ? 1 : vecCurr-1; | |
| 484 | break; | |
| 485 | case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; | |
| 486 | break; | |
| 487 | default : vecNext = 0; | |
| 488 | } | |
| 489 |  | |
| 476 | int vecNext = getNext(vecCurr,t); | |
| 490 | 477 | next = vv.elementAt(vecNext); | 
| 491 | 478 | tmp2 = vc.elementAt(vecNext); | 
| 492 | 479 |  | 
| src/main/java/org/distorted/library/type/Dynamic3D.java | ||
|---|---|---|
| 497 | 497 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | 
| 498 | 498 | else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed | 
| 499 | 499 |                   {
 | 
| 500 | int vecNext; | |
| 501 |  | |
| 502 | switch(mMode) | |
| 503 |                     {
 | |
| 504 | case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; | |
| 505 | break; | |
| 506 | case MODE_PATH: if( t<=0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; | |
| 507 | else vecNext = vecCurr==0 ? 1 : vecCurr-1; | |
| 508 | break; | |
| 509 | case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; | |
| 510 | break; | |
| 511 | default : vecNext = 0; | |
| 512 | } | |
| 513 |  | |
| 500 | int vecNext = getNext(vecCurr,t); | |
| 514 | 501 | next = vv.elementAt(vecNext); | 
| 515 | 502 | tmp2 = vc.elementAt(vecNext); | 
| 516 | 503 |  | 
| src/main/java/org/distorted/library/type/Dynamic4D.java | ||
|---|---|---|
| 520 | 520 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | 
| 521 | 521 | else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed | 
| 522 | 522 |                   {
 | 
| 523 | int vecNext; | |
| 524 |  | |
| 525 | switch(mMode) | |
| 526 |                     {
 | |
| 527 | case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; | |
| 528 | break; | |
| 529 | case MODE_PATH: if( t<=0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; | |
| 530 | else vecNext = vecCurr==0 ? 1 : vecCurr-1; | |
| 531 | break; | |
| 532 | case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; | |
| 533 | break; | |
| 534 | default : vecNext = 0; | |
| 535 | } | |
| 536 |  | |
| 523 | int vecNext = getNext(vecCurr,t); | |
| 537 | 524 | next = vv.elementAt(vecNext); | 
| 538 | 525 | tmp2 = vc.elementAt(vecNext); | 
| 539 | 526 |  | 
| ... | ... | |
| 566 | 553 | buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2]; | 
| 567 | 554 | buffer[offset+3]= ((tmp1.a[3]*time+tmp1.b[3])*time+tmp1.c[3])*time+tmp1.d[3]; | 
| 568 | 555 | } | 
| 569 |  | |
| 556 |  | |
| 570 | 557 | break; | 
| 571 | 558 | } | 
| 572 | 559 | } | 
| src/main/java/org/distorted/library/type/Dynamic5D.java | ||
|---|---|---|
| 543 | 543 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | 
| 544 | 544 | else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed | 
| 545 | 545 |                   {
 | 
| 546 | int vecNext; | |
| 547 |  | |
| 548 | switch(mMode) | |
| 549 |                     {
 | |
| 550 | case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; | |
| 551 | break; | |
| 552 | case MODE_PATH: if( t<=0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; | |
| 553 | else vecNext = vecCurr==0 ? 1 : vecCurr-1; | |
| 554 | break; | |
| 555 | case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; | |
| 556 | break; | |
| 557 | default : vecNext = 0; | |
| 558 | } | |
| 559 |  | |
| 546 | int vecNext= getNext(vecCurr,t); | |
| 560 | 547 | next = vv.elementAt(vecNext); | 
| 561 | 548 | tmp2 = vc.elementAt(vecNext); | 
| 562 | 549 |  | 
| src/main/java/org/distorted/library/type/DynamicQuat.java | ||
|---|---|---|
| 63 | 63 | } | 
| 64 | 64 |  | 
| 65 | 65 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 66 |  | |
| 66 |  | |
| 67 | 67 | private void recomputeCache() | 
| 68 | 68 |     {  
 | 
| 69 | 69 | if( numPoints>=2 ) | 
| 70 | 70 |       {
 | 
| 71 | 71 | int i, n; | 
| 72 |  | |
| 72 | Static4D cu,ne; | |
| 73 | VectorCacheQuat vq; | |
| 74 |  | |
| 73 | 75 | for(i=0; i<numPoints; i++) | 
| 74 | 76 |         {
 | 
| 75 | 77 | n = i<numPoints-1 ? i+1:0; | 
| 76 | 78 |  | 
| 77 | tmp1= vc.elementAt(i); | |
| 78 | tmp2= vc.elementAt(n); | |
| 79 | curr= vv.elementAt(i); | |
| 80 | next= vv.elementAt(n); | |
| 79 | vq= vc.elementAt(i); | |
| 80 | cu= vv.elementAt(i); | |
| 81 | ne= vv.elementAt(n); | |
| 81 | 82 |  | 
| 82 |         tmp1.vx = curr.x;
 | |
| 83 |         tmp1.vy = curr.y;
 | |
| 84 |         tmp1.vz = curr.z;
 | |
| 85 |         tmp1.vw = curr.w;
 | |
| 83 |         vq.vx = cu.x;
 | |
| 84 |         vq.vy = cu.y;
 | |
| 85 |         vq.vz = cu.z;
 | |
| 86 |         vq.vw = cu.w;
 | |
| 86 | 87 |  | 
| 87 |         tmp1.cosOmega = curr.x*next.x + curr.y*next.y + curr.z*next.z + curr.w*next.w;
 | |
| 88 |         vq.cosOmega = cu.x*ne.x + cu.y*ne.y + cu.z*ne.z + cu.w*ne.w;
 | |
| 88 | 89 |  | 
| 89 |         if( tmp1.cosOmega<0 && n!=0 )  // do not invert the last quaternion even if we'd have to go the long way around!
 | |
| 90 |         if( vq.cosOmega<0 && n!=0 )  // do not invert the last quaternion even if we'd have to go the long way around!
 | |
| 90 | 91 |           {
 | 
| 91 |           tmp1.cosOmega = -tmp1.cosOmega;
 | |
| 92 |           next.x = -next.x;
 | |
| 93 |           next.y = -next.y;
 | |
| 94 |           next.z = -next.z;
 | |
| 95 |           next.w = -next.w;
 | |
| 92 |           vq.cosOmega = -vq.cosOmega;
 | |
| 93 |           ne.x = -ne.x;
 | |
| 94 |           ne.y = -ne.y;
 | |
| 95 |           ne.z = -ne.z;
 | |
| 96 |           ne.w = -ne.w;
 | |
| 96 | 97 | } | 
| 97 | 98 |  | 
| 98 |         tmp1.sinOmega = (float)Math.sqrt(1-tmp1.cosOmega*tmp1.cosOmega);
 | |
| 99 |         tmp1.omega = arcCos(tmp1.cosOmega);
 | |
| 99 |         vq.sinOmega = (float)Math.sqrt(1-vq.cosOmega*vq.cosOmega);
 | |
| 100 |         vq.omega = arcCos(vq.cosOmega);
 | |
| 100 | 101 | } | 
| 101 | 102 | } | 
| 102 | 103 |  | 
| ... | ... | |
| 341 | 342 | buffer[offset+3] = curr.w; | 
| 342 | 343 | break; | 
| 343 | 344 | default:float t = time; | 
| 345 | int vecCurr, segment; | |
| 344 | 346 | float scale0, scale1; | 
| 345 |  | |
| 346 | if( mMode==MODE_JUMP ) time = time*(numPoints-1); | |
| 347 | else if( mMode==MODE_PATH || numPoints==2 ) time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1); | |
| 348 | else time = time*numPoints; | |
| 349 |  | |
| 350 | int vecNext, vecCurr = (int)time; | |
| 351 | time = time-vecCurr; | |
| 352 |  | |
| 347 |  | |
| 348 | switch(mMode) | |
| 349 |                 {
 | |
| 350 | case MODE_LOOP: time = time*numPoints; | |
| 351 | segment = (int)time; | |
| 352 | vecCurr = segment; | |
| 353 | break; | |
| 354 | case MODE_PATH: if( t>0.5f ) t = 1.0f-t; | |
| 355 | time = 2*t*(numPoints-1); | |
| 356 | segment = (int)(2*t*(numPoints-1)); | |
| 357 | vecCurr = segment; | |
| 358 | break; | |
| 359 | case MODE_JUMP: time = time*(numPoints-1); | |
| 360 | segment = (int)time; | |
| 361 | vecCurr = segment; | |
| 362 | break; | |
| 363 | default : vecCurr = 0; | |
| 364 | segment = 0; | |
| 365 | } | |
| 366 |  | |
| 353 | 367 | if( vecCurr>=0 && vecCurr<numPoints ) | 
| 354 | 368 |                 {
 | 
| 355 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | |
| 356 |  | |
| 357 | switch(mMode) | |
| 358 |                   {
 | |
| 359 | case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; | |
| 360 | break; | |
| 361 | case MODE_PATH: if( t<0.5f ) vecNext = vecCurr+1; | |
| 362 | else vecNext = vecCurr==0 ? 1 : vecCurr-1; | |
| 363 | break; | |
| 364 | case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; | |
| 365 | break; | |
| 366 | default : vecNext = 0; | |
| 367 | } | |
| 368 |  | |
| 369 | int vecNext = getNext(vecCurr,t); | |
| 370 |  | |
| 369 | 371 | curr = vv.elementAt(vecCurr); | 
| 370 | next = vv.elementAt(vecNext); | |
| 371 | 372 | tmp1 = vc.elementAt(vecCurr); | 
| 372 | tmp2 = vc.elementAt(vecNext); | |
| 373 |  | |
| 374 | if( tmp2.vx!=next.x || tmp2.vy!=next.y || tmp2.vz!=next.z || tmp2.vw!=next.w ) recomputeCache(); | |
| 375 |  | |
| 373 | next = vv.elementAt(vecNext); | |
| 374 |  | |
| 375 | if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation | |
| 376 | else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed | |
| 377 |                   {
 | |
| 378 | tmp2 = vc.elementAt(vecNext); | |
| 379 |  | |
| 380 | if( tmp2.vx!=next.x || tmp2.vy!=next.y || tmp2.vz!=next.z || tmp2.vw!=next.w ) recomputeCache(); | |
| 381 | } | |
| 382 |  | |
| 383 | mSegment = segment; | |
| 384 |  | |
| 385 | time = time-vecCurr; | |
| 386 |  | |
| 376 | 387 | if( tmp1.sinOmega==0 ) | 
| 377 | 388 |                   {
 | 
| 378 |                   scale0 = 0f;
 | |
| 379 |                   scale1 = 1f;
 | |
| 389 |                   scale0 = 1f;
 | |
| 390 |                   scale1 = 0f;
 | |
| 380 | 391 | } | 
| 381 |                 else if( tmp1.cosOmega < 0.99 ) 
 | |
| 392 | else if( tmp1.cosOmega < 0.99 ) | |
| 382 | 393 |                   {
 | 
| 383 | 394 | scale0 = (float)Math.sin( (1f-time)*tmp1.omega ) / tmp1.sinOmega; | 
| 384 | 395 | scale1 = (float)Math.sin( time *tmp1.omega ) / tmp1.sinOmega; | 
| 385 | 396 | } | 
| 386 |                 else 
 | |
| 397 | else | |
| 387 | 398 |                   {
 | 
| 388 | 399 | scale0 = 1f-time; | 
| 389 | 400 | scale1 = time; | 
| 390 | 401 | } | 
| 391 | 402 |  | 
| 392 | 403 | buffer[offset ] = scale0*curr.x + scale1*next.x; | 
| 393 |                 buffer[offset+1] = scale0*curr.y + scale1*next.y; 
 | |
| 394 |                 buffer[offset+2] = scale0*curr.z + scale1*next.z; 
 | |
| 395 |                 buffer[offset+3] = scale0*curr.w + scale1*next.w; 
 | |
| 396 |  | |
| 404 | buffer[offset+1] = scale0*curr.y + scale1*next.y; | |
| 405 | buffer[offset+2] = scale0*curr.z + scale1*next.z; | |
| 406 | buffer[offset+3] = scale0*curr.w + scale1*next.w; | |
| 407 |  | |
| 397 | 408 | break; | 
| 398 | 409 | } | 
| 399 | 410 | } | 
Also available in: Unified diff
library: Fix DynamicQuat
cube app: progress with ScrambleEffects