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

Also available in: Unified diff