Project

General

Profile

« Previous | Next » 

Revision 291705f6

Added by Leszek Koltunski over 7 years ago

re-generate noise after passing each Point.

View differences:

src/main/java/org/distorted/library/type/Dynamic3D.java
246 246
      {
247 247
      vv.add(v);
248 248
        
249
      if( vn!=null ) vn.add(new VectorNoise(3));
249
      if( vn!=null ) vn.add(new VectorNoise());
250 250
       
251 251
      switch(numPoints)
252 252
        {
253 253
        case 0: break;
254 254
        case 1: computeOrthonormalBase2(vv.elementAt(0),v);
255 255
                break;
256
        case 2: vc.add(new VectorCache(3));
257
                vc.add(new VectorCache(3));
258
                vc.add(new VectorCache(3));
256
        case 2: vc.add(new VectorCache());
257
                vc.add(new VectorCache());
258
                vc.add(new VectorCache());
259 259
                break;
260
        default:vc.add(new VectorCache(3));
260
        default:vc.add(new VectorCache());
261 261
        }
262 262

  
263 263
      numPoints++;
......
278 278
      {
279 279
      vv.add(location, v);
280 280
      
281
      if( vn!=null ) vn.add(new VectorNoise(3));
281
      if( vn!=null ) vn.add(new VectorNoise());
282 282
      
283 283
      switch(numPoints)
284 284
        {
285 285
        case 0: break;
286 286
        case 1: computeOrthonormalBase2(vv.elementAt(0),v);
287 287
                break;
288
        case 2: vc.add(new VectorCache(3));
289
                vc.add(new VectorCache(3));
290
                vc.add(new VectorCache(3));
288
        case 2: vc.add(new VectorCache());
289
                vc.add(new VectorCache());
290
                vc.add(new VectorCache());
291 291
                break;
292
        default:vc.add(location,new VectorCache(3));
292
        default:vc.add(location,new VectorCache());
293 293
        }
294 294

  
295 295
      numPoints++;
......
403 403
    if( vn==null )
404 404
      {
405 405
      vn = new Vector<>();
406
      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
406
      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise());
407 407

  
408 408
      if( mDimension>=2 )
409 409
        {
......
452 452
              break;
453 453
      case 2: curr = vv.elementAt(0);
454 454
              next = vv.elementAt(1);
455
             
455

  
456
              int segment2= (int)(2*time);
457

  
456 458
              if( mMode==MODE_LOOP || mMode==MODE_PATH ) time = (time>0.5f ? 2-2*time : 2*time);
457
             
459

  
458 460
              if( vn!=null )
459 461
                {
462
                if( segment2 != mSegment )
463
                  {
464
                  if(mMode!=MODE_JUMP || mSegment==1) vn.elementAt(0).computeNoise();
465
                  mSegment = segment2;
466
                  }
467

  
460 468
                time = noise(time,0);
461 469
            
462 470
                buffer[offset  ] = (next.x-curr.x)*time + curr.x + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1]);
......
472 480
             
473 481
              break;
474 482
      default:float t = time;
475
        
483
              int vecCurr, segment;
484

  
476 485
              switch(mMode)
477 486
                {
478 487
                case MODE_LOOP: time = time*numPoints;
488
                                segment = (int)time;
489
                                vecCurr = segment;
479 490
                                break;
480
                case MODE_PATH: time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1);
491
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
492

  
493
                                if( t<=0.5f )
494
                                  {
495
                                  time = 2*t*(numPoints-1);
496
                                  vecCurr = segment;
497
                                  }
498
                                else
499
                                  {
500
                                  time = 2*(1-t)*(numPoints-1);
501
                                  vecCurr = 2*numPoints-3-segment;
502
                                  }
481 503
                                break;
482 504
                case MODE_JUMP: time = time*(numPoints-1);
505
                                segment = (int)time;
506
                                vecCurr = segment;
483 507
                                break;
508
                default       : vecCurr = 0;
509
                                segment = 0;
484 510
                }
485
           
486
              int vecCurr = (int)time;
487
              time = time-vecCurr;
488
      
511

  
489 512
              if( vecCurr>=0 && vecCurr<numPoints )
490 513
                {
491
                if( cacheDirty ) recomputeCache();    // recompute cache if we have added or remove vectors since last computation
492
                else if( mVecCurr!= vecCurr )         // ...or if we have just passed a vector and the vector we are currently flying to has changed
514
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
515
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
493 516
                  {
494
                  int vecNext;   
495
                  mVecCurr = vecCurr;
496
                       
517
                  int vecNext;
518

  
497 519
                  switch(mMode)
498 520
                    {
499
                    case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; 
521
                    case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1;
500 522
                                    break;
501
                    case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;  
502
                                    else         vecNext = vecCurr==0 ? 1 : vecCurr-1;  
523
                    case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;
524
                                    else         vecNext = vecCurr==0 ? 1 : vecCurr-1;
503 525
                                    break;
504 526
                    case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1;
505 527
                                    break;
506
                    default       : vecNext = 0;                
528
                    default       : vecNext = 0;
507 529
                    }
508
              
530

  
509 531
                  next = vv.elementAt(vecNext);
510 532
                  tmp2 = vc.elementAt(vecNext);
511
              
512
                  if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y || tmp2.cached[2]!=next.z ) recomputeCache();
533

  
534
                  if( tmp2.cached[0]!=next.x ) recomputeCache();
513 535
                  }
536

  
537
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
538

  
539
                mSegment = segment;
540

  
541
                time = time-vecCurr;
514 542
            
515 543
                tmp1 = vc.elementAt(vecCurr);
516 544
               

Also available in: Unified diff