Project

General

Profile

« Previous | Next » 

Revision d403b466

Added by Leszek Koltunski over 3 years ago

Dynamics: consolidation of code.

View differences:

src/main/java/org/distorted/library/type/Dynamic.java
69 69
   * Have the speed be always, globally the same across all segments. Time to cover one segment will
70 70
   * thus generally no longer be the same.
71 71
   */
72
  public static final int SPEED_MODE_GLOBALLY_CONSTANT = 2;
72
  public static final int SPEED_MODE_GLOBALLY_CONSTANT = 2;  // TODO: not supported yet
73 73

  
74 74
  /**
75 75
   * One revolution takes us from the first point to the last and back to first through the shortest path.
......
109 109
  protected double mLastPos;
110 110
  protected int mAccessType;
111 111
  protected int mSpeedMode;
112
  protected float mTmpTime;
113
  protected int mTmpVec, mTmpSeg;
112 114

  
113 115
  protected class VectorNoise
114 116
    {
......
234 236
    mPausedTime = System.currentTimeMillis();
235 237
    }
236 238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
240

  
241
  protected void computeSegmentAndTime(float time)
242
    {
243
    switch(mMode)
244
      {
245
      case MODE_LOOP: mTmpTime= time*numPoints;
246
                      mTmpSeg = (int)mTmpTime;
247
                      mTmpVec = mTmpSeg;
248
                      break;
249
      case MODE_PATH: mTmpSeg = (int)(2*time*(numPoints-1));
250

  
251
                      if( time<=0.5f )  // this has to be <= (otherwise when effect ends at t=0.5, then time=1.0
252
                        {               // and end position is slightly not equal to the end point => might not get autodeleted!
253
                        mTmpTime = 2*time*(numPoints-1);
254
                        mTmpVec = mTmpSeg;
255
                        }
256
                      else
257
                        {
258
                        mTmpTime = 2*(1-time)*(numPoints-1);
259
                        mTmpVec  = 2*numPoints-3-mTmpSeg;
260
                        }
261
                      break;
262
      case MODE_JUMP: mTmpTime= time*(numPoints-1);
263
                      mTmpSeg = (int)mTmpTime;
264
                      mTmpVec = mTmpSeg;
265
                      break;
266
      default       : mTmpVec = 0;
267
                      mTmpSeg = 0;
268
      }
269
    }
270

  
237 271
///////////////////////////////////////////////////////////////////////////////////////////////////
238 272

  
239 273
  private float valueAtPoint(float t, VectorCache cache)
src/main/java/org/distorted/library/type/Dynamic1D.java
407 407
             
408 408
              buffer[offset] = (next.x-curr.x)*time + curr.x;
409 409
              break;
410
      default:float t = time;
411
              int vecCurr, segment;
410
      default:computeSegmentAndTime(time);
412 411

  
413
              switch(mMode)
414
                {
415
                case MODE_LOOP: time = time*numPoints;
416
                                segment = (int)time;
417
                                vecCurr = segment;
418
                                break;
419
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
420

  
421
                                if( t<=0.5f )  // this has to be <= (otherwise when effect ends at t=0.5, then time=1.0
422
                                  {            // and end position is slightly not equal to the end point => might not get autodeleted!
423
                                  time = 2*t*(numPoints-1);
424
                                  vecCurr = segment;
425
                                  }
426
                                else
427
                                  {
428
                                  time = 2*(1-t)*(numPoints-1);
429
                                  vecCurr = 2*numPoints-3-segment;
430
                                  }
431
                                break;
432
                case MODE_JUMP: time = time*(numPoints-1);
433
                                segment = (int)time;
434
                                vecCurr = segment;
435
                                break;
436
                default       : vecCurr = 0;
437
                                segment = 0;
438
                }
439

  
440
              if( vecCurr>=0 && vecCurr<numPoints )
412
              if( mTmpVec>=0 && mTmpVec<numPoints )
441 413
                {
442 414
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
443
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
415
                else if( mSegment!= mTmpSeg )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
444 416
                  {
445
                  int vecNext = getNext(vecCurr,t);
417
                  int vecNext = getNext(mTmpVec,time);
446 418
                  next = vv.elementAt(vecNext);
447 419
                  tmpCache2 = vc.elementAt(vecNext);
448
              
420

  
449 421
                  if( tmpCache2.cached[0]!=next.x ) recomputeCache();
450 422
                  }
451 423

  
452
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
424
                if( mSegment!= mTmpSeg && vn!=null ) vn.elementAt(mTmpVec).computeNoise();
453 425

  
454
                mSegment = segment;
455
                time = time-vecCurr;
456
                tmpCache1 = vc.elementAt(vecCurr);
426
                mSegment = mTmpSeg;
427
                time = mTmpTime-mTmpVec;
428
                tmpCache1 = vc.elementAt(mTmpVec);
457 429
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
458 430

  
459 431
                if( vn!=null )
460 432
                  {
461
                  time = noise(time,vecCurr);
433
                  time = noise(time,mTmpVec);
462 434
                  }
463 435
            
464 436
                buffer[offset] = ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0];
src/main/java/org/distorted/library/type/Dynamic2D.java
440 440
                }
441 441
              
442 442
              break;
443
      default:float t = time;
444
              int vecCurr, segment;
443
      default:computeSegmentAndTime(time);
445 444

  
446
              switch(mMode)
447
                {
448
                case MODE_LOOP: time = time*numPoints;
449
                                segment = (int)time;
450
                                vecCurr = segment;
451
                                break;
452
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
453

  
454
                                if( t<=0.5f )  // this has to be <= (otherwise when effect ends at t=0.5, then time=1.0
455
                                  {            // and end position is slightly not equal to the end point => might not get autodeleted!
456
                                  time = 2*t*(numPoints-1);
457
                                  vecCurr = segment;
458
                                  }
459
                                else
460
                                  {
461
                                  time = 2*(1-t)*(numPoints-1);
462
                                  vecCurr = 2*numPoints-3-segment;
463
                                  }
464
                                break;
465
                case MODE_JUMP: time = time*(numPoints-1);
466
                                segment = (int)time;
467
                                vecCurr = segment;
468
                                break;
469
                default       : vecCurr = 0;
470
                                segment = 0;
471
                }
472

  
473
              if( vecCurr>=0 && vecCurr<numPoints )
445
              if( mTmpVec>=0 && mTmpVec<numPoints )
474 446
                {
475 447
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
476
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
448
                else if( mSegment!= mTmpSeg )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
477 449
                  {
478
                  int vecNext = getNext(vecCurr,t);
450
                  int vecNext = getNext(mTmpVec,time);
479 451
                  next = vv.elementAt(vecNext);
480 452
                  tmpCache2 = vc.elementAt(vecNext);
481 453

  
482 454
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y ) recomputeCache();
483 455
                  }
484 456

  
485
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
457
                if( mSegment!= mTmpSeg && vn!=null ) vn.elementAt(mTmpVec).computeNoise();
486 458

  
487
                mSegment = segment;
488
                time = time-vecCurr;
489
                tmpCache1 = vc.elementAt(vecCurr);
459
                mSegment = mTmpSeg;
460
                time = mTmpTime-mTmpVec;
461
                tmpCache1 = vc.elementAt(mTmpVec);
490 462
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
491 463

  
492 464
                if( vn!=null )
493 465
                  {
494
                  time = noise(time,vecCurr);
466
                  time = noise(time,mTmpVec);
495 467

  
496
                  baseV[1][0] = (3* tmpCache1.a[0]*time+2* tmpCache1.b[0])*time + tmpCache1.c[0];
497
                  baseV[1][1] = (3* tmpCache1.a[1]*time+2* tmpCache1.b[1])*time + tmpCache1.c[1];
468
                  baseV[1][0] = (3*tmpCache1.a[0]*time + 2*tmpCache1.b[0])*time + tmpCache1.c[0];
469
                  baseV[1][1] = (3*tmpCache1.a[1]*time + 2*tmpCache1.b[1])*time + tmpCache1.c[1];
498 470
                 
499 471
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0] +baseV[1][1]*mFactor[0];
500 472
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1] -baseV[1][0]*mFactor[0];
src/main/java/org/distorted/library/type/Dynamic3D.java
464 464
                }
465 465
             
466 466
              break;
467
      default:float t = time;
468
              int vecCurr, segment;
467
      default:computeSegmentAndTime(time);
469 468

  
470
              switch(mMode)
471
                {
472
                case MODE_LOOP: time = time*numPoints;
473
                                segment = (int)time;
474
                                vecCurr = segment;
475
                                break;
476
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
477

  
478
                                if( t<=0.5f )  // this has to be <= (otherwise when effect ends at t=0.5, then time=1.0
479
                                  {            // and end position is slightly not equal to the end point => might not get autodeleted!
480
                                  time = 2*t*(numPoints-1);
481
                                  vecCurr = segment;
482
                                  }
483
                                else
484
                                  {
485
                                  time = 2*(1-t)*(numPoints-1);
486
                                  vecCurr = 2*numPoints-3-segment;
487
                                  }
488
                                break;
489
                case MODE_JUMP: time = time*(numPoints-1);
490
                                segment = (int)time;
491
                                vecCurr = segment;
492
                                break;
493
                default       : vecCurr = 0;
494
                                segment = 0;
495
                }
496

  
497
              if( vecCurr>=0 && vecCurr<numPoints )
469
              if( mTmpVec>=0 && mTmpVec<numPoints )
498 470
                {
499 471
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
500
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
472
                else if( mSegment!= mTmpSeg )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
501 473
                  {
502
                  int vecNext = getNext(vecCurr,t);
474
                  int vecNext = getNext(mTmpVec,time);
503 475
                  next = vv.elementAt(vecNext);
504 476
                  tmpCache2 = vc.elementAt(vecNext);
505 477

  
506 478
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y || tmpCache2.cached[2]!=next.z ) recomputeCache();
507 479
                  }
508 480

  
509
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
481
                if( mSegment!= mTmpSeg && vn!=null ) vn.elementAt(mTmpVec).computeNoise();
510 482

  
511
                mSegment = segment;
512
                time = time-vecCurr;
513
                tmpCache1 = vc.elementAt(vecCurr);
483
                mSegment = mTmpSeg;
484
                time = mTmpTime-mTmpVec;
485
                tmpCache1 = vc.elementAt(mTmpVec);
514 486
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
515 487

  
516 488
                if( vn!=null )
517 489
                  {
518
                  time = noise(time,vecCurr);
490
                  time = noise(time,mTmpVec);
519 491
              
520 492
                  computeOrthonormalBaseMore(time, tmpCache1);
521 493
                 
src/main/java/org/distorted/library/type/Dynamic4D.java
487 487
                }
488 488
                
489 489
              break;
490
      default:float t = time;
491
              int vecCurr, segment;
490
      default:computeSegmentAndTime(time);
492 491

  
493
              switch(mMode)
494
                {
495
                case MODE_LOOP: time = time*numPoints;
496
                                segment = (int)time;
497
                                vecCurr = segment;
498
                                break;
499
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
500

  
501
                                if( t<=0.5f )  // this has to be <= (otherwise when effect ends at t=0.5, then time=1.0
502
                                  {            // and end position is slightly not equal to the end point => might not get autodeleted!
503
                                  time = 2*t*(numPoints-1);
504
                                  vecCurr = segment;
505
                                  }
506
                                else
507
                                  {
508
                                  time = 2*(1-t)*(numPoints-1);
509
                                  vecCurr = 2*numPoints-3-segment;
510
                                  }
511
                                break;
512
                case MODE_JUMP: time = time*(numPoints-1);
513
                                segment = (int)time;
514
                                vecCurr = segment;
515
                                break;
516
                default       : vecCurr = 0;
517
                                segment = 0;
518
                }
519

  
520
              if( vecCurr>=0 && vecCurr<numPoints )
492
              if( mTmpVec>=0 && mTmpVec<numPoints )
521 493
                {
522 494
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
523
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
495
                else if( mSegment!= mTmpSeg )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
524 496
                  {
525
                  int vecNext = getNext(vecCurr,t);
497
                  int vecNext = getNext(mTmpVec,time);
526 498
                  next = vv.elementAt(vecNext);
527 499
                  tmpCache2 = vc.elementAt(vecNext);
528 500

  
529 501
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y || tmpCache2.cached[2]!=next.z || tmpCache2.cached[3]!=next.w ) recomputeCache();
530 502
                  }
531 503

  
532
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
504
                if( mSegment!= mTmpSeg && vn!=null ) vn.elementAt(mTmpVec).computeNoise();
533 505

  
534
                mSegment = segment;
535
                time = time-vecCurr;
536
                tmpCache1 = vc.elementAt(vecCurr);
506
                mSegment = mTmpSeg;
507
                time = mTmpTime-mTmpVec;
508
                tmpCache1 = vc.elementAt(mTmpVec);
537 509
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
538 510

  
539 511
                if( vn!=null )
540 512
                  {
541
                  time = noise(time,vecCurr);
513
                  time = noise(time,mTmpVec);
542 514
              
543 515
                  computeOrthonormalBaseMore(time, tmpCache1);
544 516

  
src/main/java/org/distorted/library/type/Dynamic5D.java
510 510
                }
511 511
                
512 512
              break;
513
      default:float t = time;
514
              int vecCurr, segment;
513
      default:computeSegmentAndTime(time);
515 514

  
516
              switch(mMode)
517
                {
518
                case MODE_LOOP: time = time*numPoints;
519
                                segment = (int)time;
520
                                vecCurr = segment;
521
                                break;
522
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
523

  
524
                                if( t<=0.5f )  // this has to be <= (otherwise when effect ends at t=0.5, then time=1.0
525
                                  {            // and end position is slightly not equal to the end point => might not get autodeleted!
526
                                  time = 2*t*(numPoints-1);
527
                                  vecCurr = segment;
528
                                  }
529
                                else
530
                                  {
531
                                  time = 2*(1-t)*(numPoints-1);
532
                                  vecCurr = 2*numPoints-3-segment;
533
                                  }
534
                                break;
535
                case MODE_JUMP: time = time*(numPoints-1);
536
                                segment = (int)time;
537
                                vecCurr = segment;
538
                                break;
539
                default       : vecCurr = 0;
540
                                segment = 0;
541
                }
542

  
543
              if( vecCurr>=0 && vecCurr<numPoints )
515
              if( mTmpVec>=0 && mTmpVec<numPoints )
544 516
                {
545 517
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
546
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
518
                else if( mSegment!= mTmpSeg )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
547 519
                  {
548
                  int vecNext= getNext(vecCurr,t);
520
                  int vecNext = getNext(mTmpVec,time);
549 521
                  next = vv.elementAt(vecNext);
550 522
                  tmpCache2 = vc.elementAt(vecNext);
551 523

  
552 524
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y || tmpCache2.cached[2]!=next.z || tmpCache2.cached[3]!=next.w || tmpCache2.cached[4]!=next.v ) recomputeCache();
553 525
                  }
554 526

  
555
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
527
                if( mSegment!= mTmpSeg && vn!=null ) vn.elementAt(mTmpVec).computeNoise();
556 528

  
557
                mSegment = segment;
558
                time = time-vecCurr;
559
                tmpCache1 = vc.elementAt(vecCurr);
529
                mSegment = mTmpSeg;
530
                time = mTmpTime-mTmpVec;
531
                tmpCache1 = vc.elementAt(mTmpVec);
560 532
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
561 533

  
562 534
                if( vn!=null )
563 535
                  {
564
                  time = noise(time,vecCurr);
536
                  time = noise(time,mTmpVec);
565 537
              
566 538
                  computeOrthonormalBaseMore(time, tmpCache1);
567 539

  

Also available in: Unified diff