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;
src/main/java/org/distorted/library/type/Dynamic1D.java
143 143
///////////////////////////////////////////////////////////////////////////////////////////////////
144 144

  
145 145
/**
146
 * Default constructor.
146
 * Constructor setting the speed of interpolation and the number of revolutions.
147
 *
148
 * What constitutes 'one revolution' depends on the MODE:
149
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
147 150
 *
148
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
149
 *                 last and back to the first
150
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
151
 *                 to the last, back to first, and to the last again.
151
 * @param duration number of milliseconds it takes to do one revolution.
152
 * @param count    number of revolutions we will do. Count<=0 means 'infinite'.
152 153
 */
153 154
  public Dynamic1D(int duration, float count)
154 155
    {
src/main/java/org/distorted/library/type/Dynamic2D.java
157 157
    }
158 158

  
159 159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161 160
/**
162
 * Default constructor.
161
 * Constructor setting the speed of interpolation and the number of revolutions.
162
 *
163
 * What constitutes 'one revolution' depends on the MODE:
164
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
163 165
 *
164
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
165
 *                 last and back to the first
166
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
167
 *                 to the last, back to first, and to the last again.
166
 * @param duration number of milliseconds it takes to do one revolution.
167
 * @param count    number of revolutions we will do. Count<=0 means 'infinite'.
168 168
 */
169 169
  public Dynamic2D(int duration, float count)
170 170
    {
src/main/java/org/distorted/library/type/Dynamic3D.java
173 173
    }
174 174

  
175 175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177 176
/**
178
 * Default constructor.
177
 * Constructor setting the speed of interpolation and the number of revolutions.
178
 *
179
 * What constitutes 'one revolution' depends on the MODE:
180
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
179 181
 *
180
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
181
 *                 last and back to the first
182
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
183
 *                 to the last, back to first, and to the last again.
182
 * @param duration number of milliseconds it takes to do one revolution.
183
 * @param count    number of revolutions we will do. Count<=0 means 'infinite'.
184 184
 */
185 185
  public Dynamic3D(int duration, float count)
186 186
    {
src/main/java/org/distorted/library/type/Dynamic4D.java
189 189
    }
190 190

  
191 191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

  
193 192
/**
194
 * Default constructor.
193
 * Constructor setting the speed of interpolation and the number of revolutions.
194
 *
195
 * What constitutes 'one revolution' depends on the MODE:
196
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
195 197
 *
196
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
197
 *                 last and back to the first
198
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
199
 *                 to the last, back to first, and to the last again.
198
 * @param duration number of milliseconds it takes to do one revolution.
199
 * @param count    number of revolutions we will do. Count<=0 means 'infinite'.
200 200
 */
201 201
  public Dynamic4D(int duration, float count)
202 202
    {
src/main/java/org/distorted/library/type/Dynamic5D.java
205 205
    }
206 206

  
207 207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

  
209 208
/**
210
 * Default constructor.
209
 * Constructor setting the speed of interpolation and the number of revolutions.
210
 *
211
 * What constitutes 'one revolution' depends on the MODE:
212
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
211 213
 *
212
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
213
 *                 last and back to the first
214
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
215
 *                 to the last, back to first, and to the last again.
214
 * @param duration number of milliseconds it takes to do one revolution.
215
 * @param count    number of revolutions we will do. Count<=0 means 'infinite'.
216 216
 */
217 217
  public Dynamic5D(int duration, float count)
218 218
    {
src/main/java/org/distorted/library/type/DynamicQuat.java
115 115
    }
116 116

  
117 117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119 118
/**
120
 * Default constructor.
119
 * Constructor setting the speed of interpolation and the number of revolutions.
121 120
 *
122
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
123
 *                 last and back to the first
124
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
125
 *                 to the last, back to first, and to the last again.
121
 * What constitutes 'one revolution' depends on the MODE:
122
 * {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
123
 *
124
 * @param duration number of milliseconds it takes to do one revolution.
125
 * @param count    number of revolutions we will do. Count<=0 means 'infinite'.
126 126
 */
127 127
  public DynamicQuat(int duration, float count)
128 128
    {
......
134 134
    mDuration  = duration;
135 135
    mCount     = count;
136 136
    mLastPos   = -1;
137
    mAccessMode= ACCESS_RANDOM;
137
    mAccessType = ACCESS_TYPE_RANDOM;
138 138
    mDimension = 4;
139 139
    }
140 140

  
......
320 320
 * 
321 321
 * @param buffer Float buffer we will write the resulting Static4D to.
322 322
 * @param offset Offset in the buffer where to write the result.
323
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
324
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
325
 */    
323
 * @param time   Time of interpolation. Time=0.0 is the beginning of the first revolution, time=1.0 - the end
324
 *               of the first revolution, time=2.5 - the middle of the third revolution.
325
 *               What constitutes 'one revolution' depends on the MODE:
326
 *               {@link Dynamic#MODE_LOOP}, {@link Dynamic#MODE_PATH} or {@link Dynamic#MODE_JUMP}.
327
 **/
326 328
  synchronized void interpolate(float[] buffer, int offset, float time)
327 329
    {  
328 330
    switch(numPoints)

Also available in: Unified diff