Revision 1e22c248
Added by Leszek Koltunski about 8 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 |
} |
src/main/java/org/distorted/library/type/Dynamic1D.java | ||
---|---|---|
341 | 341 |
|
342 | 342 |
if( vn!=null ) vn.removeAllElements(); |
343 | 343 |
} |
344 |
|
|
344 |
|
|
345 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
346 |
/** |
|
347 |
* Sets the 'smoothness' of interpolation. |
|
348 |
* <p> |
|
349 |
* When Noise=0 (the default), we interpolate between our Points through the most smooth path possible. |
|
350 |
* Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding |
|
351 |
* up and slowing down, etc. |
|
352 |
* |
|
353 |
* @param noise The noise level. Permitted range: 0 <= noise <= 1. |
|
354 |
*/ |
|
355 |
|
|
356 |
public synchronized void setNoise(Static1D noise) |
|
357 |
{ |
|
358 |
if( vn==null ) |
|
359 |
{ |
|
360 |
vn = new Vector<>(); |
|
361 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension)); |
|
362 |
|
|
363 |
if( mDimension>=2 ) |
|
364 |
{ |
|
365 |
mFactor = new float[mDimension-1]; |
|
366 |
} |
|
367 |
|
|
368 |
mNoise = new float[mDimension]; |
|
369 |
} |
|
370 |
|
|
371 |
if( noise.x<0.0f ) noise.x = 0.0f; |
|
372 |
if( noise.x>1.0f ) noise.x = 1.0f; |
|
373 |
|
|
374 |
mNoise[0] = noise.x; |
|
375 |
} |
|
376 |
|
|
345 | 377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
346 | 378 |
/** |
347 | 379 |
* Writes the results of interpolation between the Points at time 'time' to the passed float buffer. |
src/main/java/org/distorted/library/type/Dynamic2D.java | ||
---|---|---|
360 | 360 |
if( vn!=null ) vn.removeAllElements(); |
361 | 361 |
} |
362 | 362 |
|
363 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
364 |
/** |
|
365 |
* Sets the 'smoothness' of interpolation. |
|
366 |
* <p> |
|
367 |
* When Noise=0 (the default), we interpolate between our Points through the most smooth path possible. |
|
368 |
* Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding |
|
369 |
* up and slowing down, etc. |
|
370 |
* |
|
371 |
* @param noise The noise level. Permitted range: 0 <= noise <= 1. |
|
372 |
*/ |
|
373 |
|
|
374 |
public synchronized void setNoise(Static2D noise) |
|
375 |
{ |
|
376 |
if( vn==null ) |
|
377 |
{ |
|
378 |
vn = new Vector<>(); |
|
379 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension)); |
|
380 |
|
|
381 |
if( mDimension>=2 ) |
|
382 |
{ |
|
383 |
mFactor = new float[mDimension-1]; |
|
384 |
} |
|
385 |
|
|
386 |
mNoise = new float[mDimension]; |
|
387 |
} |
|
388 |
|
|
389 |
if( noise.x<0.0f ) noise.x = 0.0f; |
|
390 |
if( noise.x>1.0f ) noise.x = 1.0f; |
|
391 |
if( noise.y<0.0f ) noise.y = 0.0f; |
|
392 |
if( noise.y>1.0f ) noise.y = 1.0f; |
|
393 |
|
|
394 |
mNoise[0] = noise.x; |
|
395 |
mNoise[1] = noise.y; |
|
396 |
} |
|
397 |
|
|
363 | 398 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
364 | 399 |
/** |
365 | 400 |
* Writes the results of interpolation between the Points at time 'time' to the passed float buffer. |
src/main/java/org/distorted/library/type/Dynamic3D.java | ||
---|---|---|
379 | 379 |
|
380 | 380 |
if( vn!=null ) vn.removeAllElements(); |
381 | 381 |
} |
382 |
|
|
382 |
|
|
383 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
384 |
/** |
|
385 |
* Sets the 'smoothness' of interpolation. |
|
386 |
* <p> |
|
387 |
* When Noise=0 (the default), we interpolate between our Points through the most smooth path possible. |
|
388 |
* Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding |
|
389 |
* up and slowing down, etc. |
|
390 |
* |
|
391 |
* @param noise The noise level. Permitted range: 0 <= noise <= 1. |
|
392 |
*/ |
|
393 |
|
|
394 |
public synchronized void setNoise(Static3D noise) |
|
395 |
{ |
|
396 |
if( vn==null ) |
|
397 |
{ |
|
398 |
vn = new Vector<>(); |
|
399 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension)); |
|
400 |
|
|
401 |
if( mDimension>=2 ) |
|
402 |
{ |
|
403 |
mFactor = new float[mDimension-1]; |
|
404 |
} |
|
405 |
|
|
406 |
mNoise = new float[mDimension]; |
|
407 |
} |
|
408 |
|
|
409 |
if( noise.x<0.0f ) noise.x = 0.0f; |
|
410 |
if( noise.x>1.0f ) noise.x = 1.0f; |
|
411 |
if( noise.y<0.0f ) noise.y = 0.0f; |
|
412 |
if( noise.y>1.0f ) noise.y = 1.0f; |
|
413 |
if( noise.z<0.0f ) noise.z = 0.0f; |
|
414 |
if( noise.z>1.0f ) noise.z = 1.0f; |
|
415 |
|
|
416 |
mNoise[0] = noise.x; |
|
417 |
mNoise[1] = noise.y; |
|
418 |
mNoise[2] = noise.z; |
|
419 |
} |
|
420 |
|
|
383 | 421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
384 | 422 |
/** |
385 | 423 |
* Writes the results of interpolation between the Points at time 'time' to the passed float buffer. |
src/main/java/org/distorted/library/type/Dynamic4D.java | ||
---|---|---|
395 | 395 |
|
396 | 396 |
if( vn!=null ) vn.removeAllElements(); |
397 | 397 |
} |
398 |
|
|
398 |
|
|
399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
400 |
/** |
|
401 |
* Sets the 'smoothness' of interpolation. |
|
402 |
* <p> |
|
403 |
* When Noise=0 (the default), we interpolate between our Points through the most smooth path possible. |
|
404 |
* Increasing noise makes the Dynamic increasingly deviate from this path, pseudo-randomly speeding |
|
405 |
* up and slowing down, etc. |
|
406 |
* |
|
407 |
* @param noise The noise level. Permitted range: 0 <= noise <= 1. |
|
408 |
*/ |
|
409 |
|
|
410 |
public synchronized void setNoise(Static4D noise) |
|
411 |
{ |
|
412 |
if( vn==null ) |
|
413 |
{ |
|
414 |
vn = new Vector<>(); |
|
415 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension)); |
|
416 |
|
|
417 |
if( mDimension>=2 ) |
|
418 |
{ |
|
419 |
mFactor = new float[mDimension-1]; |
|
420 |
} |
|
421 |
|
|
422 |
mNoise = new float[mDimension]; |
|
423 |
} |
|
424 |
|
|
425 |
if( noise.x<0.0f ) noise.x = 0.0f; |
|
426 |
if( noise.x>1.0f ) noise.x = 1.0f; |
|
427 |
if( noise.y<0.0f ) noise.y = 0.0f; |
|
428 |
if( noise.y>1.0f ) noise.y = 1.0f; |
|
429 |
if( noise.z<0.0f ) noise.z = 0.0f; |
|
430 |
if( noise.z>1.0f ) noise.z = 1.0f; |
|
431 |
if( noise.w<0.0f ) noise.w = 0.0f; |
|
432 |
if( noise.w>1.0f ) noise.w = 1.0f; |
|
433 |
|
|
434 |
mNoise[0] = noise.x; |
|
435 |
mNoise[1] = noise.y; |
|
436 |
mNoise[2] = noise.z; |
|
437 |
mNoise[3] = noise.w; |
|
438 |
} |
|
439 |
|
|
399 | 440 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
400 | 441 |
/** |
401 | 442 |
* Writes the results of interpolation between the Points at time 'time' to the passed float buffer. |
... | ... | |
435 | 476 |
buffer[offset ] = (next.x-curr.x)*time + curr.x + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2]); |
436 | 477 |
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]); |
437 | 478 |
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]); |
438 |
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]);
|
|
479 |
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]);
|
|
439 | 480 |
} |
440 | 481 |
else |
441 | 482 |
{ |
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 |
{ |
src/main/java/org/distorted/library/type/DynamicQuat.java | ||
---|---|---|
133 | 133 |
mMode = MODE_LOOP; |
134 | 134 |
mDuration = duration; |
135 | 135 |
mCount = count; |
136 |
mNoise = 0.0f; |
|
137 | 136 |
mDimension = 4; |
138 | 137 |
} |
139 | 138 |
|
Also available in: Unified diff
Fix 4D and 5D noise, make noise N dimensional.