Revision 291705f6
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/type/Dynamic2D.java | ||
---|---|---|
223 | 223 |
{ |
224 | 224 |
vv.add(v); |
225 | 225 |
|
226 |
if( vn!=null ) vn.add(new VectorNoise(2));
|
|
226 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
227 | 227 |
|
228 | 228 |
switch(numPoints) |
229 | 229 |
{ |
230 | 230 |
case 0: |
231 | 231 |
case 1: break; |
232 |
case 2: vc.add(new VectorCache(2));
|
|
233 |
vc.add(new VectorCache(2));
|
|
234 |
vc.add(new VectorCache(2));
|
|
232 |
case 2: vc.add(new VectorCache()); |
|
233 |
vc.add(new VectorCache()); |
|
234 |
vc.add(new VectorCache()); |
|
235 | 235 |
break; |
236 |
default:vc.add(new VectorCache(2));
|
|
236 |
default:vc.add(new VectorCache()); |
|
237 | 237 |
} |
238 | 238 |
|
239 | 239 |
numPoints++; |
... | ... | |
254 | 254 |
{ |
255 | 255 |
vv.add(location, v); |
256 | 256 |
|
257 |
if( vn!=null ) vn.add(new VectorNoise(2));
|
|
257 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
258 | 258 |
|
259 | 259 |
switch(numPoints) |
260 | 260 |
{ |
261 | 261 |
case 0: |
262 | 262 |
case 1: break; |
263 |
case 2: vc.add(new VectorCache(2));
|
|
264 |
vc.add(new VectorCache(2));
|
|
265 |
vc.add(new VectorCache(2));
|
|
263 |
case 2: vc.add(new VectorCache()); |
|
264 |
vc.add(new VectorCache()); |
|
265 |
vc.add(new VectorCache()); |
|
266 | 266 |
break; |
267 |
default:vc.add(location,new VectorCache(2));
|
|
267 |
default:vc.add(location,new VectorCache()); |
|
268 | 268 |
} |
269 | 269 |
|
270 | 270 |
numPoints++; |
... | ... | |
376 | 376 |
if( vn==null ) |
377 | 377 |
{ |
378 | 378 |
vn = new Vector<>(); |
379 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise(mDimension));
|
|
379 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise()); |
|
380 | 380 |
|
381 | 381 |
if( mDimension>=2 ) |
382 | 382 |
{ |
... | ... | |
420 | 420 |
break; |
421 | 421 |
case 2: curr = vv.elementAt(0); |
422 | 422 |
next = vv.elementAt(1); |
423 |
|
|
423 |
|
|
424 |
int segment2= (int)(2*time); |
|
425 |
|
|
424 | 426 |
if( mMode==MODE_LOOP || mMode==MODE_PATH ) time = (time>0.5f ? 2-2*time : 2*time); |
425 |
|
|
427 |
|
|
426 | 428 |
if( vn!=null ) |
427 | 429 |
{ |
430 |
if( segment2 != mSegment ) |
|
431 |
{ |
|
432 |
if(mMode!=MODE_JUMP || mSegment==1) vn.elementAt(0).computeNoise(); |
|
433 |
mSegment = segment2; |
|
434 |
} |
|
435 |
|
|
428 | 436 |
time = noise(time,0); |
429 | 437 |
|
430 | 438 |
baseV[1][0] = next.x-curr.x; |
... | ... | |
441 | 449 |
|
442 | 450 |
break; |
443 | 451 |
default:float t = time; |
444 |
|
|
452 |
int vecCurr, segment; |
|
453 |
|
|
445 | 454 |
switch(mMode) |
446 | 455 |
{ |
447 | 456 |
case MODE_LOOP: time = time*numPoints; |
457 |
segment = (int)time; |
|
458 |
vecCurr = segment; |
|
448 | 459 |
break; |
449 |
case MODE_PATH: time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1); |
|
460 |
case MODE_PATH: segment = (int)(2*t*(numPoints-1)); |
|
461 |
|
|
462 |
if( t<=0.5f ) |
|
463 |
{ |
|
464 |
time = 2*t*(numPoints-1); |
|
465 |
vecCurr = segment; |
|
466 |
} |
|
467 |
else |
|
468 |
{ |
|
469 |
time = 2*(1-t)*(numPoints-1); |
|
470 |
vecCurr = 2*numPoints-3-segment; |
|
471 |
} |
|
450 | 472 |
break; |
451 | 473 |
case MODE_JUMP: time = time*(numPoints-1); |
474 |
segment = (int)time; |
|
475 |
vecCurr = segment; |
|
452 | 476 |
break; |
477 |
default : vecCurr = 0; |
|
478 |
segment = 0; |
|
453 | 479 |
} |
454 |
|
|
455 |
int vecCurr = (int)time; |
|
456 |
time = time-vecCurr; |
|
457 |
|
|
480 |
|
|
458 | 481 |
if( vecCurr>=0 && vecCurr<numPoints ) |
459 |
{
|
|
460 |
if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation
|
|
461 |
else if( mVecCurr!= vecCurr ) // ...or if we have just passed a vector and the vector we are currently flying to has changed
|
|
482 |
{ |
|
483 |
if( cacheDirty ) recomputeCache(); // recompute cache if we have added or remove vectors since last computation |
|
484 |
else if( mSegment!= segment ) // ...or if we have just passed a vector and the vector we are currently flying to has changed
|
|
462 | 485 |
{ |
463 |
int vecNext; |
|
464 |
mVecCurr = vecCurr; |
|
465 |
|
|
486 |
int vecNext; |
|
487 |
|
|
466 | 488 |
switch(mMode) |
467 | 489 |
{ |
468 |
case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1;
|
|
490 |
case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; |
|
469 | 491 |
break; |
470 |
case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;
|
|
471 |
else vecNext = vecCurr==0 ? 1 : vecCurr-1;
|
|
492 |
case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1; |
|
493 |
else vecNext = vecCurr==0 ? 1 : vecCurr-1; |
|
472 | 494 |
break; |
473 | 495 |
case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1; |
474 | 496 |
break; |
475 |
default : vecNext = 0;
|
|
497 |
default : vecNext = 0; |
|
476 | 498 |
} |
477 |
|
|
499 |
|
|
478 | 500 |
next = vv.elementAt(vecNext); |
479 | 501 |
tmp2 = vc.elementAt(vecNext); |
480 |
|
|
481 |
if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y ) recomputeCache();
|
|
502 |
|
|
503 |
if( tmp2.cached[0]!=next.x ) recomputeCache(); |
|
482 | 504 |
} |
483 | 505 |
|
506 |
if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise(); |
|
507 |
|
|
508 |
mSegment = segment; |
|
509 |
|
|
510 |
time = time-vecCurr; |
|
484 | 511 |
tmp1 = vc.elementAt(vecCurr); |
485 | 512 |
|
486 | 513 |
if( vn!=null ) |
Also available in: Unified diff
re-generate noise after passing each Point.