Revision 291705f6
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/type/Dynamic1D.java | ||
---|---|---|
207 | 207 |
{ |
208 | 208 |
vv.add(v); |
209 | 209 |
|
210 |
if( vn!=null ) vn.add(new VectorNoise(1));
|
|
210 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
211 | 211 |
|
212 | 212 |
switch(numPoints) |
213 | 213 |
{ |
214 | 214 |
case 0: |
215 | 215 |
case 1: break; |
216 |
case 2: vc.add(new VectorCache(1));
|
|
217 |
vc.add(new VectorCache(1));
|
|
218 |
vc.add(new VectorCache(1));
|
|
216 |
case 2: vc.add(new VectorCache()); |
|
217 |
vc.add(new VectorCache()); |
|
218 |
vc.add(new VectorCache()); |
|
219 | 219 |
cacheDirty = true; |
220 | 220 |
break; |
221 |
default:vc.add(new VectorCache(1));
|
|
221 |
default:vc.add(new VectorCache()); |
|
222 | 222 |
cacheDirty = true; |
223 | 223 |
} |
224 | 224 |
|
... | ... | |
239 | 239 |
{ |
240 | 240 |
vv.add(location, v); |
241 | 241 |
|
242 |
if( vn!=null ) vn.add(new VectorNoise(1));
|
|
242 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
243 | 243 |
|
244 | 244 |
switch(numPoints) |
245 | 245 |
{ |
246 | 246 |
case 0: |
247 | 247 |
case 1: break; |
248 |
case 2: vc.add(new VectorCache(1));
|
|
249 |
vc.add(new VectorCache(1));
|
|
250 |
vc.add(new VectorCache(1));
|
|
248 |
case 2: vc.add(new VectorCache()); |
|
249 |
vc.add(new VectorCache()); |
|
250 |
vc.add(new VectorCache()); |
|
251 | 251 |
cacheDirty = true; |
252 | 252 |
break; |
253 |
default:vc.add(location,new VectorCache(1));
|
|
253 |
default:vc.add(location,new VectorCache()); |
|
254 | 254 |
cacheDirty = true; |
255 | 255 |
} |
256 | 256 |
|
... | ... | |
358 | 358 |
if( vn==null ) |
359 | 359 |
{ |
360 | 360 |
vn = new Vector<>(); |
361 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
|
|
361 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise()); |
|
362 | 362 |
|
363 | 363 |
if( mDimension>=2 ) |
364 | 364 |
{ |
... | ... | |
397 | 397 |
break; |
398 | 398 |
case 2: curr = vv.elementAt(0); |
399 | 399 |
next = vv.elementAt(1); |
400 |
|
|
400 |
|
|
401 |
int segment2= (int)(2*time); |
|
402 |
|
|
401 | 403 |
if( mMode==MODE_LOOP || mMode==MODE_PATH ) time = (time>0.5f ? 2-2*time : 2*time); |
402 |
|
|
404 |
|
|
403 | 405 |
if( vn!=null ) |
404 | 406 |
{ |
407 |
if( segment2 != mSegment ) |
|
408 |
{ |
|
409 |
if(mMode!=MODE_JUMP || mSegment==1) vn.elementAt(0).computeNoise(); |
|
410 |
mSegment = segment2; |
|
411 |
} |
|
412 |
|
|
405 | 413 |
time = noise(time,0); |
406 | 414 |
} |
407 | 415 |
|
408 | 416 |
buffer[offset] = (next.x-curr.x)*time + curr.x; |
409 | 417 |
break; |
410 | 418 |
default:float t = time; |
411 |
|
|
419 |
int vecCurr, segment; |
|
420 |
|
|
412 | 421 |
switch(mMode) |
413 | 422 |
{ |
414 | 423 |
case MODE_LOOP: time = time*numPoints; |
424 |
segment = (int)time; |
|
425 |
vecCurr = segment; |
|
415 | 426 |
break; |
416 |
case MODE_PATH: time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1); |
|
427 |
case MODE_PATH: segment = (int)(2*t*(numPoints-1)); |
|
428 |
|
|
429 |
if( t<=0.5f ) |
|
430 |
{ |
|
431 |
time = 2*t*(numPoints-1); |
|
432 |
vecCurr = segment; |
|
433 |
} |
|
434 |
else |
|
435 |
{ |
|
436 |
time = 2*(1-t)*(numPoints-1); |
|
437 |
vecCurr = 2*numPoints-3-segment; |
|
438 |
} |
|
417 | 439 |
break; |
418 | 440 |
case MODE_JUMP: time = time*(numPoints-1); |
441 |
segment = (int)time; |
|
442 |
vecCurr = segment; |
|
419 | 443 |
break; |
444 |
default : vecCurr = 0; |
|
445 |
segment = 0; |
|
420 | 446 |
} |
421 |
|
|
422 |
int vecCurr = (int)time; |
|
423 |
time = time-vecCurr; |
|
424 |
|
|
447 |
|
|
425 | 448 |
if( vecCurr>=0 && vecCurr<numPoints ) |
426 | 449 |
{ |
427 | 450 |
if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation |
428 |
else if( mVecCurr!= vecCurr ) // ...or if we have just passed a vector and the vector we are currently flying to has changed
|
|
451 |
else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed
|
|
429 | 452 |
{ |
430 |
int vecNext; |
|
431 |
mVecCurr = vecCurr; |
|
432 |
|
|
453 |
int vecNext; |
|
454 |
|
|
433 | 455 |
switch(mMode) |
434 | 456 |
{ |
435 |
case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1;
|
|
457 |
case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; |
|
436 | 458 |
break; |
437 |
case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;
|
|
438 |
else vecNext = vecCurr==0 ? 1 : vecCurr-1;
|
|
459 |
case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; |
|
460 |
else vecNext = vecCurr==0 ? 1 : vecCurr-1; |
|
439 | 461 |
break; |
440 | 462 |
case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; |
441 | 463 |
break; |
442 |
default : vecNext = 0;
|
|
464 |
default : vecNext = 0; |
|
443 | 465 |
} |
444 | 466 |
|
445 | 467 |
next = vv.elementAt(vecNext); |
... | ... | |
447 | 469 |
|
448 | 470 |
if( tmp2.cached[0]!=next.x ) recomputeCache(); |
449 | 471 |
} |
450 |
|
|
472 |
|
|
473 |
if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise(); |
|
474 |
|
|
475 |
mSegment = segment; |
|
476 |
|
|
477 |
time = time-vecCurr; |
|
478 |
|
|
479 |
tmp1 = vc.elementAt(vecCurr); |
|
480 |
|
|
451 | 481 |
if( vn!=null ) |
452 | 482 |
{ |
453 | 483 |
time = noise(time,vecCurr); |
454 | 484 |
} |
455 | 485 |
|
456 |
tmp1 = vc.elementAt(vecCurr); |
|
457 | 486 |
buffer[offset] = ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0]; |
458 | 487 |
break; |
459 | 488 |
} |
Also available in: Unified diff
re-generate noise after passing each Point.