Project

General

Profile

« Previous | Next » 

Revision b920c848

Added by Leszek Koltunski over 5 years ago

1. Change the API of Dynamic: split makeNowRunFor into two separate 'setDuration' and 'resetToBeginning'
2. Major changes to the 'Dynamic' app so that we can check more about the Dynamics.

View differences:

src/main/java/org/distorted/library/type/Dynamic.java
154 154
  private static Random mRnd = new Random();
155 155
  private static final int NUM_NOISE = 5; // used iff mNoise>0.0. Number of intermediary points between each pair of adjacent vectors
156 156
                                          // where we randomize noise factors to make the way between the two vectors not so smooth.
157
  private long mTimeLastInterpolated;
158
  private long mTimeWhenSetDuration;
157
  private long mTimeOffset;
158
  private boolean mSetOffset;
159 159

  
160 160
///////////////////////////////////////////////////////////////////////////////////////////////////
161 161
// hide this from Javadoc
......
181 181
    mLastPos   = -1;
182 182
    mAccessMode= ACCESS_RANDOM;
183 183

  
184
    mTimeLastInterpolated = 0;
185
    mTimeWhenSetDuration  = 0;
184
    mTimeOffset = 0;
185
    mSetOffset  = true;
186 186

  
187 187
    baseV      = new float[mDimension][mDimension];
188 188
    buf        = new float[mDimension];
......
544 544

  
545 545
///////////////////////////////////////////////////////////////////////////////////////////////////
546 546
/**
547
 * Sets the time it takes to do one full interpolation.
548
 * 
549
 * @param durationInMilliseconds time it takes to do one full interpolation, i.e. go from the first
550
 *                               Point to the last and back.
547
 * Return the number of times this Dynamic will interpolate.
548
 *
549
 * @return the number of times this Dynamic will interpolate.
550
 */
551
  public float getCount()
552
    {
553
    return mCount;
554
    }
555

  
556
///////////////////////////////////////////////////////////////////////////////////////////////////
557
/**
558
 * Start running from the beginning again.
551 559
 */
552
  public void makeRunNowFor(long durationInMilliseconds)
560
  public void resetToBeginning()
553 561
    {
554
    mDuration = durationInMilliseconds;
555
    mTimeWhenSetDuration = mTimeLastInterpolated;
562
    mSetOffset = true;
563
    }
564

  
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566
/**
567
 * @param duration Number of milliseconds this Dynamic will interpolate for.
568
 */
569
  public void setDuration(long duration)
570
    {
571
    mDuration = duration;
572
    }
573

  
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575
/**
576
 * @return Number of milliseconds this Dynamic will interpolate for.
577
 */
578
  public long getDuration()
579
    {
580
    return mDuration;
556 581
    }
557 582

  
558 583
///////////////////////////////////////////////////////////////////////////////////////////////////
......
587 612
 */
588 613
  public void get(float[] buffer, int offset, long time)
589 614
    {
590
    mTimeLastInterpolated = time;
591

  
592 615
    if( mDuration<=0.0f )
593 616
      {
594 617
      interpolate(buffer,offset,mCount-(int)mCount);
595 618
      }
596 619
    else
597 620
      {
598
      double pos = (double)(time-mTimeWhenSetDuration)/mDuration;
621
      if( mSetOffset )
622
        {
623
        mSetOffset = false;
624
        mTimeOffset= time;
625
        mLastPos   = -1;
626
        }
627

  
628
      time -= mTimeOffset;
629

  
630
      double pos = (double)time/mDuration;
599 631

  
600 632
      if( pos<=mCount || mCount<=0.0f )
601 633
        {
......
622 654
 */
623 655
  public boolean get(float[] buffer, int offset, long time, long step)
624 656
    {
625
    mTimeLastInterpolated = time;
626
    time -= mTimeWhenSetDuration;
627

  
628 657
    if( mDuration<=0.0f )
629 658
      {
630 659
      interpolate(buffer,offset,mCount-(int)mCount);
631 660
      return false;
632 661
      }
662

  
663
    if( mSetOffset )
664
      {
665
      mSetOffset = false;
666
      mTimeOffset= time;
667
      mLastPos   = -1;
668
      }
669

  
670
    time -= mTimeOffset;
671

  
633 672
    if( time+step > mDuration*mCount && mCount>0.0f )
634 673
      {
635 674
      interpolate(buffer,offset,mCount-(int)mCount);

Also available in: Unified diff