Project

General

Profile

« Previous | Next » 

Revision 1e22c248

Added by Leszek Koltunski over 7 years ago

Fix 4D and 5D noise, make noise N dimensional.

View differences:

src/main/java/org/distorted/library/type/Dynamic5D.java
411 411
   
412 412
    if( vn!=null ) vn.removeAllElements();
413 413
    }
414
  
414

  
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416
/**
417
 * Sets the 'smoothness' of interpolation.
418
 * <p>
419
 * When Noise=0 (the default), we interpolate between our Points through the most smooth path possible.
420
 * Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding
421
 * up and slowing down, etc.
422
 *
423
 * @param noise The noise level. Permitted range: 0 <= noise <= 1.
424
 */
425

  
426
  public synchronized void setNoise(Static5D noise)
427
    {
428
    if( vn==null )
429
      {
430
      vn = new Vector<>();
431
      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
432

  
433
      if( mDimension>=2 )
434
        {
435
        mFactor = new float[mDimension-1];
436
        }
437

  
438
      mNoise = new float[mDimension];
439
      }
440

  
441
    if( noise.x<0.0f ) noise.x = 0.0f;
442
    if( noise.x>1.0f ) noise.x = 1.0f;
443
    if( noise.y<0.0f ) noise.y = 0.0f;
444
    if( noise.y>1.0f ) noise.y = 1.0f;
445
    if( noise.z<0.0f ) noise.z = 0.0f;
446
    if( noise.z>1.0f ) noise.z = 1.0f;
447
    if( noise.w<0.0f ) noise.w = 0.0f;
448
    if( noise.w>1.0f ) noise.w = 1.0f;
449
    if( noise.v<0.0f ) noise.v = 0.0f;
450
    if( noise.v>1.0f ) noise.v = 1.0f;
451

  
452
    mNoise[0] = noise.x;
453
    mNoise[1] = noise.y;
454
    mNoise[2] = noise.z;
455
    mNoise[3] = noise.w;
456
    mNoise[4] = noise.v;
457
    }
458

  
415 459
///////////////////////////////////////////////////////////////////////////////////////////////////
416 460
/**
417 461
 * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
......
453 497
                buffer[offset  ] = (next.x-curr.x)*time + curr.x + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2] + baseV[4][0]*mFactor[3]);
454 498
                buffer[offset+1] = (next.y-curr.y)*time + curr.y + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1] + baseV[3][1]*mFactor[2] + baseV[4][1]*mFactor[3]);
455 499
                buffer[offset+2] = (next.z-curr.z)*time + curr.z + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1] + baseV[3][2]*mFactor[2] + baseV[4][2]*mFactor[3]);
456
                buffer[offset+3] = (next.z-curr.z)*time + curr.z + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2] + baseV[4][3]*mFactor[3]);
457
                buffer[offset+4] = (next.z-curr.z)*time + curr.z + (baseV[1][4]*mFactor[0] + baseV[2][4]*mFactor[1] + baseV[3][4]*mFactor[2] + baseV[4][4]*mFactor[3]);
500
                buffer[offset+3] = (next.w-curr.w)*time + curr.w + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2] + baseV[4][3]*mFactor[3]);
501
                buffer[offset+4] = (next.v-curr.v)*time + curr.v + (baseV[1][4]*mFactor[0] + baseV[2][4]*mFactor[1] + baseV[3][4]*mFactor[2] + baseV[4][4]*mFactor[3]);
458 502
                }
459 503
              else
460 504
                {

Also available in: Unified diff