Revision 291705f6
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/type/Dynamic5D.java | ||
---|---|---|
271 | 271 |
{ |
272 | 272 |
vv.add(v); |
273 | 273 |
|
274 |
if( vn!=null ) vn.add(new VectorNoise(5));
|
|
274 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
275 | 275 |
|
276 | 276 |
switch(numPoints) |
277 | 277 |
{ |
278 | 278 |
case 0: break; |
279 | 279 |
case 1: computeOrthonormalBase2(vv.elementAt(0),v); |
280 | 280 |
break; |
281 |
case 2: vc.add(new VectorCache(5));
|
|
282 |
vc.add(new VectorCache(5));
|
|
283 |
vc.add(new VectorCache(5));
|
|
281 |
case 2: vc.add(new VectorCache()); |
|
282 |
vc.add(new VectorCache()); |
|
283 |
vc.add(new VectorCache()); |
|
284 | 284 |
break; |
285 |
default:vc.add(new VectorCache(5));
|
|
285 |
default:vc.add(new VectorCache()); |
|
286 | 286 |
} |
287 | 287 |
|
288 | 288 |
numPoints++; |
... | ... | |
303 | 303 |
{ |
304 | 304 |
vv.add(location, v); |
305 | 305 |
|
306 |
if( vn!=null ) vn.add(new VectorNoise(5));
|
|
306 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
307 | 307 |
|
308 | 308 |
switch(numPoints) |
309 | 309 |
{ |
310 | 310 |
case 0: break; |
311 | 311 |
case 1: computeOrthonormalBase2(vv.elementAt(0),v); |
312 | 312 |
break; |
313 |
case 2: vc.add(new VectorCache(5));
|
|
314 |
vc.add(new VectorCache(5));
|
|
315 |
vc.add(new VectorCache(5));
|
|
313 |
case 2: vc.add(new VectorCache()); |
|
314 |
vc.add(new VectorCache()); |
|
315 |
vc.add(new VectorCache()); |
|
316 | 316 |
break; |
317 |
default:vc.add(location,new VectorCache(5));
|
|
317 |
default:vc.add(location,new VectorCache()); |
|
318 | 318 |
} |
319 | 319 |
|
320 | 320 |
numPoints++; |
... | ... | |
428 | 428 |
if( vn==null ) |
429 | 429 |
{ |
430 | 430 |
vn = new Vector<>(); |
431 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
|
|
431 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise()); |
|
432 | 432 |
|
433 | 433 |
if( mDimension>=2 ) |
434 | 434 |
{ |
... | ... | |
487 | 487 |
break; |
488 | 488 |
case 2: curr = vv.elementAt(0); |
489 | 489 |
next = vv.elementAt(1); |
490 |
|
|
490 |
|
|
491 |
int segment2= (int)(2*time); |
|
492 |
|
|
491 | 493 |
if( mMode==MODE_LOOP || mMode==MODE_PATH ) time = (time>0.5f ? 2-2*time : 2*time); |
492 |
|
|
494 |
|
|
493 | 495 |
if( vn!=null ) |
494 | 496 |
{ |
497 |
if( segment2 != mSegment ) |
|
498 |
{ |
|
499 |
if(mMode!=MODE_JUMP || mSegment==1) vn.elementAt(0).computeNoise(); |
|
500 |
mSegment = segment2; |
|
501 |
} |
|
502 |
|
|
495 | 503 |
time = noise(time,0); |
496 | 504 |
|
497 | 505 |
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]); |
... | ... | |
511 | 519 |
|
512 | 520 |
break; |
513 | 521 |
default:float t = time; |
514 |
|
|
522 |
int vecCurr, segment; |
|
523 |
|
|
515 | 524 |
switch(mMode) |
516 | 525 |
{ |
517 | 526 |
case MODE_LOOP: time = time*numPoints; |
527 |
segment = (int)time; |
|
528 |
vecCurr = segment; |
|
518 | 529 |
break; |
519 |
case MODE_PATH: time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1); |
|
530 |
case MODE_PATH: segment = (int)(2*t*(numPoints-1)); |
|
531 |
|
|
532 |
if( t<=0.5f ) |
|
533 |
{ |
|
534 |
time = 2*t*(numPoints-1); |
|
535 |
vecCurr = segment; |
|
536 |
} |
|
537 |
else |
|
538 |
{ |
|
539 |
time = 2*(1-t)*(numPoints-1); |
|
540 |
vecCurr = 2*numPoints-3-segment; |
|
541 |
} |
|
520 | 542 |
break; |
521 | 543 |
case MODE_JUMP: time = time*(numPoints-1); |
544 |
segment = (int)time; |
|
545 |
vecCurr = segment; |
|
522 | 546 |
break; |
547 |
default : vecCurr = 0; |
|
548 |
segment = 0; |
|
523 | 549 |
} |
524 |
|
|
525 |
int vecCurr = (int)time; |
|
526 |
time = time-vecCurr; |
|
527 |
|
|
550 |
|
|
528 | 551 |
if( vecCurr>=0 && vecCurr<numPoints ) |
529 | 552 |
{ |
530 |
if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation
|
|
531 |
else if( mVecCurr!= vecCurr ) // ...or if we have just passed a vector and the vector we are currently flying to has changed
|
|
553 |
if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation |
|
554 |
else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed
|
|
532 | 555 |
{ |
533 |
int vecNext; |
|
534 |
mVecCurr = vecCurr; |
|
535 |
|
|
556 |
int vecNext; |
|
557 |
|
|
536 | 558 |
switch(mMode) |
537 | 559 |
{ |
538 |
case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1;
|
|
560 |
case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; |
|
539 | 561 |
break; |
540 |
case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;
|
|
541 |
else vecNext = vecCurr==0 ? 1 : vecCurr-1;
|
|
562 |
case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; |
|
563 |
else vecNext = vecCurr==0 ? 1 : vecCurr-1; |
|
542 | 564 |
break; |
543 | 565 |
case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; |
544 | 566 |
break; |
545 |
default : vecNext = 0;
|
|
567 |
default : vecNext = 0; |
|
546 | 568 |
} |
547 |
|
|
569 |
|
|
548 | 570 |
next = vv.elementAt(vecNext); |
549 | 571 |
tmp2 = vc.elementAt(vecNext); |
550 |
|
|
551 |
if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y || tmp2.cached[2]!=next.z || tmp2.cached[3]!=next.w || tmp2.cached[4]!=next.v ) recomputeCache();
|
|
572 |
|
|
573 |
if( tmp2.cached[0]!=next.x ) recomputeCache(); |
|
552 | 574 |
} |
575 |
|
|
576 |
if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise(); |
|
577 |
|
|
578 |
mSegment = segment; |
|
579 |
|
|
580 |
time = time-vecCurr; |
|
553 | 581 |
|
554 | 582 |
tmp1 = vc.elementAt(vecCurr); |
555 | 583 |
|
Also available in: Unified diff
re-generate noise after passing each Point.