Revision 1e22c248
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/type/Dynamic.java | ||
---|---|---|
78 | 78 |
protected int mMode; // LOOP, PATH or JUMP |
79 | 79 |
protected long mDuration; // number of milliseconds it takes to do a full loop/path from first vector to the last and back to the first |
80 | 80 |
protected float mCount; // number of loops/paths we will do; mCount = 1.5 means we go from the first vector to the last, back to first, and to the last again. |
81 |
protected float mNoise; // how 'smooth' our path form each vector to the next is. mNoise = 0.0 (min) --> completely smooth; mNoise==1.0 (max) --> very uneven |
|
82 | 81 |
|
83 | 82 |
protected class VectorNoise |
84 | 83 |
{ |
... | ... | |
102 | 101 |
|
103 | 102 |
protected Vector<VectorNoise> vn; |
104 | 103 |
protected float[] mFactor; |
104 |
protected float[] mNoise; |
|
105 | 105 |
protected float[][] baseV; |
106 | 106 |
private float[] buffer; |
107 | 107 |
|
... | ... | |
218 | 218 |
|
219 | 219 |
switch(index) |
220 | 220 |
{ |
221 |
case 0 : for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise*tmpN.n[i+1][0]*t; |
|
222 |
return time + mNoise*(d*tmpN.n[0][0]-time); |
|
223 |
case NUM_NOISE: for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise*tmpN.n[i+1][NUM_NOISE-1]*(1-t); |
|
221 |
case 0 : for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise[i+1]*tmpN.n[i+1][0]*t;
|
|
222 |
return time + mNoise[0]*(d*tmpN.n[0][0]-time);
|
|
223 |
case NUM_NOISE: for(int i=0;i<mDimension-1;i++) mFactor[i] = mNoise[i+1]*tmpN.n[i+1][NUM_NOISE-1]*(1-t);
|
|
224 | 224 |
len = ((float)NUM_NOISE)/(NUM_NOISE+1); |
225 |
lower = len + mNoise*(tmpN.n[0][NUM_NOISE-1]-len); |
|
225 |
lower = len + mNoise[0]*(tmpN.n[0][NUM_NOISE-1]-len);
|
|
226 | 226 |
return (1.0f-lower)*(d-NUM_NOISE) + lower; |
227 | 227 |
default : float ya,yb; |
228 | 228 |
|
... | ... | |
230 | 230 |
{ |
231 | 231 |
yb = tmpN.n[i+1][index ]; |
232 | 232 |
ya = tmpN.n[i+1][index-1]; |
233 |
mFactor[i] = mNoise*((yb-ya)*t+ya); |
|
233 |
mFactor[i] = mNoise[i+1]*((yb-ya)*t+ya);
|
|
234 | 234 |
} |
235 | 235 |
|
236 | 236 |
len = ((float)index)/(NUM_NOISE+1); |
237 |
lower = len + mNoise*(tmpN.n[0][index-1]-len); |
|
237 |
lower = len + mNoise[0]*(tmpN.n[0][index-1]-len);
|
|
238 | 238 |
len = ((float)index+1)/(NUM_NOISE+1); |
239 |
upper = len + mNoise*(tmpN.n[0][index ]-len); |
|
239 |
upper = len + mNoise[0]*(tmpN.n[0][index ]-len);
|
|
240 | 240 |
|
241 | 241 |
return (upper-lower)*(d-index) + lower; |
242 | 242 |
} |
... | ... | |
562 | 562 |
mDuration = duration; |
563 | 563 |
} |
564 | 564 |
|
565 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
566 |
/** |
|
567 |
* Sets the 'smoothness' of interpolation. |
|
568 |
* <p> |
|
569 |
* When Noise=0 (the default), we interpolate between our Points through the most smooth path possible. |
|
570 |
* Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding |
|
571 |
* up and slowing down, etc. |
|
572 |
* |
|
573 |
* @param noise The noise level. Permitted range: 0 <= noise <= 1. |
|
574 |
*/ |
|
575 |
|
|
576 |
public synchronized void setNoise(float noise) |
|
577 |
{ |
|
578 |
if( mNoise==0.0f && noise != 0.0f && vn==null ) |
|
579 |
{ |
|
580 |
vn = new Vector<>(); |
|
581 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension)); |
|
582 |
|
|
583 |
if( mDimension>=2 ) |
|
584 |
{ |
|
585 |
mFactor = new float[mDimension-1]; |
|
586 |
} |
|
587 |
} |
|
588 |
|
|
589 |
if( mNoise<0.0f ) mNoise = 0.0f; |
|
590 |
if( mNoise>1.0f ) mNoise = 1.0f; |
|
591 |
|
|
592 |
mNoise = noise; |
|
593 |
} |
|
594 |
|
|
595 | 565 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
596 | 566 |
// end of DistortedInterpolator |
597 | 567 |
} |
Also available in: Unified diff
Fix 4D and 5D noise, make noise N dimensional.