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

Also available in: Unified diff