Project

General

Profile

« Previous | Next » 

Revision c45c2ab1

Added by Leszek Koltunski about 5 years ago

Minor improvements in the Dynamics.

View differences:

src/main/java/org/distorted/library/type/Dynamic.java
25 25
///////////////////////////////////////////////////////////////////////////////////////////////////
26 26
/** A class to interpolate between a list of Statics.
27 27
* <p><ul>
28
* <li>if there is only one Point, just jump to it.
28
* <li>if there is only one Point, just return it.
29 29
* <li>if there are two Points, linearly bounce between them
30
* <li>if there are more, interpolate a loop (or a path!) between them.
30
* <li>if there are more, interpolate a path between them. Exact way we interpolate depends on the MODE.
31 31
* </ul>
32 32
*/
33 33

  
......
54 54
public abstract class Dynamic
55 55
  {
56 56
  /**
57
   * One revolution takes us from the first vector to the last and back to first through the shortest path. 
57
   * One revolution takes us from the first point to the last and back to first through the shortest path.
58 58
   */
59 59
  public static final int MODE_LOOP = 0; 
60 60
  /**
61
   * We come back from the last to the first vector through the same way we got there.
61
   * One revolution takes us from the first point to the last and back to first through the same path.
62 62
   */
63 63
  public static final int MODE_PATH = 1; 
64 64
  /**
65
   * We just jump back from the last point to the first.
65
   * One revolution takes us from the first point to the last and jumps straight back to the first point.
66 66
   */
67 67
  public static final int MODE_JUMP = 2; 
68 68

  
......
72 72
   * On the other hand, when in this mode, it is not possible to smoothly interpolate when mDuration suddenly
73 73
   * changes.
74 74
   */
75
  public static final int ACCESS_RANDOM     = 0;
75
  public static final int ACCESS_TYPE_RANDOM     = 0;
76 76
  /**
77 77
   * Set the mode to ACCESS_SEQUENTIAL if you need to change mDuration and you would rather have the Dynamic
78 78
   * keep on smoothly interpolating.
79 79
   * On the other hand, in this mode, a Dynamic can only be accessed in sequential manner, which means one
80 80
   * Dynamic can only be used in one effect at a time.
81 81
   */
82
  public static final int ACCESS_SEQUENTIAL = 1;
82
  public static final int ACCESS_TYPE_SEQUENTIAL = 1;
83 83

  
84 84
  protected int mDimension;
85 85
  protected int numPoints;
......
89 89
  protected long mDuration;     // number of milliseconds it takes to do a full loop/path from first vector to the last and back to the first
90 90
  protected float mCount;       // number of loops/paths we will do; mCount = 1.5 means we go from the first vector to the last, back to first, and to the last again. 
91 91
  protected double mLastPos;
92
  protected int mAccessMode;
92
  protected int mAccessType;
93 93

  
94 94
  protected class VectorNoise
95 95
    {
......
179 179
    mDimension = dimension;
180 180
    mSegment   = -1;
181 181
    mLastPos   = -1;
182
    mAccessMode= ACCESS_RANDOM;
182
    mAccessType = ACCESS_TYPE_RANDOM;
183 183

  
184 184
    mTimeOffset = 0;
185 185
    mSetOffset  = true;
......
505 505
 * <li>Loop is when we go from the first point all the way to the last, and the back to the first through 
506 506
 * the shortest way.
507 507
 * <li>Path is when we come back from the last point back to the first the same way we got there.
508
 * <li>Jump is when we go from first to last and then jump back to the first.
508
 * <li>Jump is when we go from first to last and then jump straight back to the first.
509 509
 * </ul>
510 510
 * 
511 511
 * @param mode {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
......
517 517

  
518 518
///////////////////////////////////////////////////////////////////////////////////////////////////
519 519
/**
520
 * Returns the number of Statics this Dynamic has been fed with.
520
 * Returns the number of Points this Dynamic has been fed with.
521 521
 *   
522
 * @return the number of Statics we are currently interpolating through.
522
 * @return the number of Points we are currently interpolating through.
523 523
 */
524 524
  public synchronized int getNumPoints()
525 525
    {
......
528 528

  
529 529
///////////////////////////////////////////////////////////////////////////////////////////////////
530 530
/**
531
 * Controls how many times we want to interpolate.
531
 * Sets how many revolutions we want to do.
532 532
 * <p>
533
 * Count equal to 1 means 'go from the first Static to the last and back'. Does not have to be an
534
 * integer - i.e. count=1.5 would mean 'start at the first Point, go to the last, come back to the first, 
535
 * go to the last again and stop'.
533
 * Does not have to be an integer. What constitutes 'one revolution' depends on the MODE:
534
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
536 535
 * Count<=0 means 'go on interpolating indefinitely'.
537 536
 * 
538
 * @param count the number of times we want to interpolate between our collection of Statics.
537
 * @param count the number of times we want to interpolate between our collection of Points.
539 538
 */
540 539
  public void setCount(float count)
541 540
    {
......
544 543

  
545 544
///////////////////////////////////////////////////////////////////////////////////////////////////
546 545
/**
547
 * Return the number of times this Dynamic will interpolate.
546
 * Return the number of revolutions this Dynamic will make.
547
 * What constitutes 'one revolution' depends on the MODE:
548
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
548 549
 *
549
 * @return the number of times this Dynamic will interpolate.
550
 * @return the number revolutions this Dynamic will make.
550 551
 */
551 552
  public float getCount()
552 553
    {
......
556 557
///////////////////////////////////////////////////////////////////////////////////////////////////
557 558
/**
558 559
 * Start running from the beginning again.
560
 *
561
 * If a Dynamic has been used already, and we want to use it again and start interpolating from the
562
 * first Point, first we need to reset it using this method.
559 563
 */
560 564
  public void resetToBeginning()
561 565
    {
......
564 568

  
565 569
///////////////////////////////////////////////////////////////////////////////////////////////////
566 570
/**
567
 * @param duration Number of milliseconds this Dynamic will interpolate for.
571
 * @param duration Number of milliseconds one revolution will take.
572
 *                 What constitutes 'one revolution' depends on the MODE:
573
 *                 {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
568 574
 */
569 575
  public void setDuration(long duration)
570 576
    {
......
573 579

  
574 580
///////////////////////////////////////////////////////////////////////////////////////////////////
575 581
/**
576
 * @return Number of milliseconds this Dynamic will interpolate for.
582
 * @return Number of milliseconds one revolution will take.
577 583
 */
578 584
  public long getDuration()
579 585
    {
......
582 588

  
583 589
///////////////////////////////////////////////////////////////////////////////////////////////////
584 590
/**
585
 * Sets the access mode this Dynamic will be working in.
591
 * Sets the access type this Dynamic will be working in.
586 592
 *
587
 * @param mode {@link Dynamic#ACCESS_RANDOM} or {@link Dynamic#ACCESS_SEQUENTIAL}.
593
 * @param type {@link Dynamic#ACCESS_TYPE_RANDOM} or {@link Dynamic#ACCESS_TYPE_SEQUENTIAL}.
588 594
 */
589
  public void setAccessMode(int mode)
595
  public void setAccessType(int type)
590 596
    {
591
    mAccessMode = mode;
597
    mAccessType = type;
592 598
    mLastPos = -1;
593 599
    }
594 600

  
595 601
///////////////////////////////////////////////////////////////////////////////////////////////////
596 602
/**
597 603
 * Return the Dimension, ie number of floats in a single Point this Dynamic interpolates through.
604
 *
605
 * @return number of floats in a single Point (ie its dimension) contained in the Dynamic.
598 606
 */
599 607
  public int getDimension()
600 608
    {
......
607 615
 *
608 616
 * @param buffer Float buffer we will write the results to.
609 617
 * @param offset Offset in the buffer where to write the result.
610
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
611
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
618
 * @param time   Time of interpolation. Time=0.0 is the beginning of the first revolution, time=1.0 - the end
619
 *               of the first revolution, time=2.5 - the middle of the third revolution.
620
 *               What constitutes 'one revolution' depends on the MODE:
621
 *               {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
612 622
 */
613 623
  public void get(float[] buffer, int offset, long time)
614 624
    {
......
645 655
 *
646 656
 * @param buffer Float buffer we will write the results to.
647 657
 * @param offset Offset in the buffer where to write the result.
648
 * @param time   Time of interpolation. Time=0.0 would return the first Point, Time=0.5*mDuration - the
649
 *               last, time=1.0*mDuration - the first again, and time 0.1*mDuration would be 1/5 of the
650
 *               way between the first and the last Points.
658
 * @param time   Time of interpolation. Time=0.0 is the beginning of the first revolution, time=1.0 - the end
659
 *               of the first revolution, time=2.5 - the middle of the third revolution.
660
 *               What constitutes 'one revolution' depends on the MODE:
661
 *               {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
651 662
 * @param step   Time difference between now and the last time we called this function. Needed to figure
652 663
 *               out if the previous time we were called the effect wasn't finished yet, but now it is.
653 664
 * @return true if the interpolation reached its end.
......
677 688

  
678 689
    double pos;
679 690

  
680
    if( mAccessMode==ACCESS_SEQUENTIAL )
691
    if( mAccessType ==ACCESS_TYPE_SEQUENTIAL )
681 692
      {
682 693
      pos = mLastPos<0 ? (double)time/mDuration : (double)step/mDuration + mLastPos;
683 694
      mLastPos = pos;

Also available in: Unified diff