Revision 0273ef2a
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/library/type/Dynamic.java | ||
---|---|---|
157 | 157 |
private static Random mRnd = new Random(); |
158 | 158 |
private static final int NUM_NOISE = 5; // used iff mNoise>0.0. Number of intermediary points between each pair of adjacent vectors |
159 | 159 |
// where we randomize noise factors to make the way between the two vectors not so smooth. |
160 |
private long mTimeOffset;
|
|
161 |
private boolean mSetOffset;
|
|
160 |
private long mStartTime;
|
|
161 |
private static long mPausedTime;
|
|
162 | 162 |
|
163 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
164 | 164 |
// hide this from Javadoc |
... | ... | |
184 | 184 |
mLastPos = -1; |
185 | 185 |
mAccessType= ACCESS_TYPE_RANDOM; |
186 | 186 |
mConvexity = 1.0f; |
187 |
|
|
188 |
mTimeOffset= 0; |
|
189 |
mSetOffset = true; |
|
187 |
mStartTime = 0; |
|
190 | 188 |
|
191 | 189 |
baseV = new float[mDimension][mDimension]; |
192 | 190 |
buf = new float[mDimension]; |
193 | 191 |
old = new float[mDimension]; |
194 | 192 |
} |
195 | 193 |
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
public static void onPause() |
|
197 |
{ |
|
198 |
mPausedTime = System.currentTimeMillis(); |
|
199 |
} |
|
200 |
|
|
196 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
197 | 202 |
|
198 | 203 |
protected float noise(float time,int vecNum) |
... | ... | |
580 | 585 |
*/ |
581 | 586 |
public void resetToBeginning() |
582 | 587 |
{ |
583 |
mSetOffset = true;
|
|
588 |
mStartTime = 0;
|
|
584 | 589 |
} |
585 | 590 |
|
586 | 591 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
655 | 660 |
return mDimension; |
656 | 661 |
} |
657 | 662 |
|
658 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
659 |
/** |
|
660 |
* Writes the results of interpolation between the Points at time 'time' to the passed float buffer. |
|
661 |
* |
|
662 |
* @param buffer Float buffer we will write the results to. |
|
663 |
* @param offset Offset in the buffer where to write the result. |
|
664 |
* @param time Time of interpolation. Time=0.0 is the beginning of the first revolution, time=1.0 - the end |
|
665 |
* of the first revolution, time=2.5 - the middle of the third revolution. |
|
666 |
* What constitutes 'one revolution' depends on the MODE: |
|
667 |
* {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}. |
|
668 |
*/ |
|
669 |
public void get(float[] buffer, int offset, long time) |
|
670 |
{ |
|
671 |
if( mDuration<=0.0f ) |
|
672 |
{ |
|
673 |
interpolate(buffer,offset,mCount-(int)mCount); |
|
674 |
} |
|
675 |
else |
|
676 |
{ |
|
677 |
if( mSetOffset ) |
|
678 |
{ |
|
679 |
mSetOffset = false; |
|
680 |
mTimeOffset= time; |
|
681 |
mLastPos = -1; |
|
682 |
} |
|
683 |
|
|
684 |
time -= mTimeOffset; |
|
685 |
|
|
686 |
double pos = (double)time/mDuration; |
|
687 |
|
|
688 |
if( pos<=mCount || mCount<=0.0f ) |
|
689 |
{ |
|
690 |
interpolate(buffer,offset, (float)(pos-(int)pos) ); |
|
691 |
} |
|
692 |
} |
|
693 |
} |
|
694 |
|
|
695 | 663 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
696 | 664 |
/** |
697 | 665 |
* Writes the results of interpolation between the Points at time 'time' to the passed float buffer. |
... | ... | |
717 | 685 |
return false; |
718 | 686 |
} |
719 | 687 |
|
720 |
if( mSetOffset )
|
|
688 |
if( mStartTime==0 )
|
|
721 | 689 |
{ |
722 |
mSetOffset = false; |
|
723 |
mTimeOffset= time; |
|
690 |
mStartTime = time; |
|
724 | 691 |
mLastPos = -1; |
725 | 692 |
} |
726 | 693 |
|
727 |
time -= mTimeOffset; |
|
694 |
long diff = time-mPausedTime; |
|
695 |
|
|
696 |
if( diff>=0 && diff<=step ) |
|
697 |
{ |
|
698 |
mStartTime += diff; |
|
699 |
step -= diff; |
|
700 |
} |
|
701 |
|
|
702 |
time -= mStartTime; |
|
728 | 703 |
|
729 | 704 |
if( time+step > mDuration*mCount && mCount>0.0f ) |
730 | 705 |
{ |
Also available in: Unified diff
Fixes for pausing and restarting.