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/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

  

Also available in: Unified diff