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/Dynamic4D.java
255 255
      {
256 256
      vv.add(v);
257 257
        
258
      if( vn!=null ) vn.add(new VectorNoise(4));
258
      if( vn!=null ) vn.add(new VectorNoise());
259 259
       
260
       switch(numPoints)
261
         {
262
         case 0: break;
263
         case 1: computeOrthonormalBase2(vv.elementAt(0),v);
264
                 break;
265
         case 2: vc.add(new VectorCache(4));
266
                 vc.add(new VectorCache(4));
267
                 vc.add(new VectorCache(4));
268
                 break;
269
         default:vc.add(new VectorCache(4));
270
         }
271

  
272
       numPoints++;
273
       cacheDirty = true;
274
       }
260
      switch(numPoints)
261
        {
262
        case 0: break;
263
        case 1: computeOrthonormalBase2(vv.elementAt(0),v);
264
                break;
265
        case 2: vc.add(new VectorCache());
266
                vc.add(new VectorCache());
267
                vc.add(new VectorCache());
268
                break;
269
        default:vc.add(new VectorCache());
270
        }
271

  
272
      numPoints++;
273
      cacheDirty = true;
274
      }
275 275
    }
276 276

  
277 277
///////////////////////////////////////////////////////////////////////////////////////////////////
......
287 287
      {
288 288
      vv.add(location, v);
289 289
      
290
      if( vn!=null ) vn.add(new VectorNoise(4));
290
      if( vn!=null ) vn.add(new VectorNoise());
291 291
      
292 292
      switch(numPoints)
293 293
        {
294 294
        case 0: break;
295 295
        case 1: computeOrthonormalBase2(vv.elementAt(0),v);
296 296
                break;
297
        case 2: vc.add(new VectorCache(4));
298
                vc.add(new VectorCache(4));
299
                vc.add(new VectorCache(4));
297
        case 2: vc.add(new VectorCache());
298
                vc.add(new VectorCache());
299
                vc.add(new VectorCache());
300 300
                break;
301
        default:vc.add(location,new VectorCache(4));
301
        default:vc.add(location,new VectorCache());
302 302
        }
303 303

  
304 304
      numPoints++;
......
412 412
    if( vn==null )
413 413
      {
414 414
      vn = new Vector<>();
415
      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
415
      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise());
416 416

  
417 417
      if( mDimension>=2 )
418 418
        {
......
466 466
              break;
467 467
      case 2: curr = vv.elementAt(0);
468 468
              next = vv.elementAt(1);
469
            
469

  
470
              int segment2= (int)(2*time);
471

  
470 472
              if( mMode==MODE_LOOP || mMode==MODE_PATH ) time = (time>0.5f ? 2-2*time : 2*time);
471
             
473

  
472 474
              if( vn!=null )
473 475
                {
476
                if( segment2 != mSegment )
477
                  {
478
                  if(mMode!=MODE_JUMP || mSegment==1) vn.elementAt(0).computeNoise();
479
                  mSegment = segment2;
480
                  }
481

  
474 482
                time = noise(time,0);
475 483

  
476 484
                buffer[offset  ] = (next.x-curr.x)*time + curr.x + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2]);
......
488 496
                
489 497
              break;
490 498
      default:float t = time;
491
        
499
              int vecCurr, segment;
500

  
492 501
              switch(mMode)
493 502
                {
494 503
                case MODE_LOOP: time = time*numPoints;
504
                                segment = (int)time;
505
                                vecCurr = segment;
495 506
                                break;
496
                case MODE_PATH: time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1);
507
                case MODE_PATH: segment = (int)(2*t*(numPoints-1));
508

  
509
                                if( t<=0.5f )
510
                                  {
511
                                  time = 2*t*(numPoints-1);
512
                                  vecCurr = segment;
513
                                  }
514
                                else
515
                                  {
516
                                  time = 2*(1-t)*(numPoints-1);
517
                                  vecCurr = 2*numPoints-3-segment;
518
                                  }
497 519
                                break;
498 520
                case MODE_JUMP: time = time*(numPoints-1);
521
                                segment = (int)time;
522
                                vecCurr = segment;
499 523
                                break;
524
                default       : vecCurr = 0;
525
                                segment = 0;
500 526
                }
501
     
502
              int vecCurr = (int)time;
503
              time = time-vecCurr;
504
      
527

  
505 528
              if( vecCurr>=0 && vecCurr<numPoints )
506 529
                {
507
                if( cacheDirty ) recomputeCache();    // recompute cache if we have added or remove vectors since last computation
508
                else if( mVecCurr!= vecCurr )         // ...or if we have just passed a vector and the vector we are currently flying to has changed
530
                if( cacheDirty ) recomputeCache();  // recompute cache if we have added or remove vectors since last computation
531
                else if( mSegment!= segment )       // ...or if we have just passed a vector and the vector we are currently flying to has changed
509 532
                  {
510
                  int vecNext;   
511
                  mVecCurr = vecCurr;
512
                       
533
                  int vecNext;
534

  
513 535
                  switch(mMode)
514 536
                    {
515
                    case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; 
537
                    case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1;
516 538
                                    break;
517
                    case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;  
518
                                    else         vecNext = vecCurr==0 ? 1 : vecCurr-1;  
539
                    case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;
540
                                    else         vecNext = vecCurr==0 ? 1 : vecCurr-1;
519 541
                                    break;
520 542
                    case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1;
521 543
                                    break;
522
                    default       : vecNext = 0;                
544
                    default       : vecNext = 0;
523 545
                    }
524
     
546

  
525 547
                  next = vv.elementAt(vecNext);
526 548
                  tmp2 = vc.elementAt(vecNext);
527
              
528
                  if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y || tmp2.cached[2]!=next.z || tmp2.cached[3]!=next.w ) recomputeCache();
549

  
550
                  if( tmp2.cached[0]!=next.x ) recomputeCache();
529 551
                  }
552

  
553
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
554

  
555
                mSegment = segment;
556

  
557
                time = time-vecCurr;
530 558
            
531 559
                tmp1 = vc.elementAt(vecCurr);
532 560
               

Also available in: Unified diff