Project

General

Profile

« Previous | Next » 

Revision d403b466

Added by Leszek Koltunski almost 3 years ago

Dynamics: consolidation of code.

View differences:

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
                 

Also available in: Unified diff