Project

General

Profile

Download (22 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / type / Dynamic3D.java @ 8c893ffc

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.type;
21

    
22
import java.util.Vector;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
/** 
26
* A 3-dimensional implementation of the Dynamic class to interpolate between a list
27
* of Float3Ds.
28
*/
29

    
30
public class Dynamic3D extends Dynamic implements Data3D
31
  {
32
 
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
// the coefficients of the X(t), Y(t) and Z(t) polynomials: X(t) = ax*T^3 + bx*T^2 + cx*t + dx  etc.
35
// (x,y,z) is the vector tangent to the path.
36
// (vx,vy,vz) is the original vector from vv (copied here so when interpolating we can see if it is 
37
// still valid and if not - rebuild the Cache
38
  
39
  private class VectorCache
40
    {
41
    float ax, bx, cx, dx;
42
    float ay, by, cy, dy;
43
    float az, bz, cz, dz;
44
   
45
    float x,y,z;
46
    float vx,vy,vz;
47
    }
48
  
49
  private class VectorNoise
50
    {
51
    float[] nx;
52
    float[] ny;
53
    float[] nz;
54
   
55
    public VectorNoise()
56
      {
57
      nx = new float[NUM_NOISE]; 
58
      nx[0] = mRnd.nextFloat();
59
      for(int i=1; i<NUM_NOISE; i++) nx[i] = nx[i-1]+mRnd.nextFloat();
60
      float sum = nx[NUM_NOISE-1] + mRnd.nextFloat();
61
      for(int i=0; i<NUM_NOISE; i++) nx[i] /=sum;
62
     
63
      ny = new float[NUM_NOISE];
64
      for(int i=0; i<NUM_NOISE; i++) ny[i] = mRnd.nextFloat()-0.5f;
65
     
66
      nz = new float[NUM_NOISE];
67
      for(int i=0; i<NUM_NOISE; i++) nz[i] = mRnd.nextFloat()-0.5f;  
68
      }
69
    }
70
  
71
  private Vector<VectorCache> vc;
72
  private VectorCache tmp1, tmp2;
73

    
74
  private Vector<Static3D> vv;
75
  private Static3D prev, curr, next;
76
  
77
  private Vector<VectorNoise> vn;
78
  private VectorNoise tmpN;
79
  
80
  private float mFactor1, mFactor2;  // used in Noise only. Those are noise factors; 1=noise of the (vec1X,vec1Y,vec1Z) vector; 2=noise of (vec2X,vec2Y,vec2Z)
81
  private float vec1X,vec1Y,vec1Z;   // vector perpendicular to v(t) and in the same plane as v(t) and a(t) (for >2 points only, in case of 2 points this is calculated differently)
82
  private float vec2X,vec2Y,vec2Z;   // vector perpendicular to v(t0 and to vec1.
83
  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  synchronized void createNoise()
87
    {
88
    if( vn==null )
89
      {  
90
      vn = new Vector<VectorNoise>();
91
      for(int i=0; i<numPoints; i++) vn.add(new VectorNoise());
92
      }
93
    }
94
   
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// no array bounds checking!
97
  
98
  private void vec(int c)
99
    {
100
    int p = c>0 ? c-1: numPoints-1;
101
    int n = c<numPoints-1 ? c+1: 0;
102
    
103
    prev = vv.elementAt(p);
104
    curr = vv.elementAt(c);
105
    next = vv.elementAt(n);
106

    
107
    tmp1 = vc.elementAt(c);
108
    
109
    float px = curr.x - prev.x;
110
    float py = curr.y - prev.y;
111
    float pz = curr.z - prev.z;
112
    float nx = next.x - curr.x;
113
    float ny = next.y - curr.y;
114
    float nz = next.z - curr.z;
115
     
116
    float d = nx*nx+ny*ny+nz*nz;
117
    
118
    if( d>0 )
119
      {
120
      float q = (float)Math.sqrt((px*px+py*py+pz*pz)/d);
121
      
122
      if( q>1 )
123
        {
124
        tmp1.x = nx+px/q;
125
        tmp1.y = ny+py/q;
126
        tmp1.z = nz+pz/q;
127
        }
128
      else
129
        {
130
        tmp1.x = px+nx*q;
131
        tmp1.y = py+ny*q;
132
        tmp1.z = pz+nz*q;
133
        }
134
      }
135
    else
136
      {
137
      tmp1.x = 0.0f;
138
      tmp1.y = 0.0f;
139
      tmp1.z = 0.0f;  
140
      }
141
    }
142
    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
  
145
  private void recomputeCache()
146
    {  
147
    if( numPoints==1 )
148
      {
149
      tmp1= vc.elementAt(0);
150
      curr= vv.elementAt(0);
151
        
152
      tmp1.ax = tmp1.ay = tmp1.az = 0.0f;
153
      tmp1.bx = tmp1.by = tmp1.bz = 0.0f;
154
      tmp1.cx = curr.x;
155
      tmp1.cy = curr.y;
156
      tmp1.cz = curr.z;
157
      tmp1.dx = tmp1.dy = tmp1.dz = 0.0f;
158
      }
159
    else if( numPoints==2 )
160
      {
161
      tmp1= vc.elementAt(0);
162
      tmp2= vc.elementAt(1);
163
      curr= vv.elementAt(0);
164
      next= vv.elementAt(1);
165
          
166
      tmp1.ax = tmp1.ay = tmp1.az = 0.0f;
167
      tmp1.bx = tmp1.by = tmp1.bz = 0.0f;
168
      tmp1.cx = next.x - curr.x;
169
      tmp1.cy = next.y - curr.y;
170
      tmp1.cz = next.z - curr.z;
171
      tmp1.dx = curr.x;
172
      tmp1.dy = curr.y;
173
      tmp1.dz = curr.z;
174
      
175
      tmp2.ax = tmp2.ay = tmp2.az = 0.0f;
176
      tmp2.bx = tmp2.by = tmp2.bz = 0.0f;
177
      tmp2.cx = curr.x - next.x;
178
      tmp2.cy = curr.y - next.y;
179
      tmp2.cz = curr.z - next.z;
180
      tmp2.dx = next.x;
181
      tmp2.dy = next.y;
182
      tmp2.dz = next.z;
183
      }
184
    else
185
      {
186
      int i, n;  
187
         
188
      for(i=0; i<numPoints; i++) vec(i);
189
   
190
      for(i=0; i<numPoints; i++)
191
        {
192
        n = i<numPoints-1 ? i+1:0;  
193
      
194
        tmp1= vc.elementAt(i);
195
        tmp2= vc.elementAt(n);
196
        curr= vv.elementAt(i);
197
        next= vv.elementAt(n);
198
      
199
        tmp1.vx = curr.x;
200
        tmp1.vy = curr.y;
201
        tmp1.vz = curr.z;
202
        
203
        tmp1.ax =  2*curr.x +   tmp1.x - 2*next.x + tmp2.x;
204
        tmp1.bx = -3*curr.x - 2*tmp1.x + 3*next.x - tmp2.x;
205
        tmp1.cx = tmp1.x;
206
        tmp1.dx = curr.x;
207
      
208
        tmp1.ay =  2*curr.y +   tmp1.y - 2*next.y + tmp2.y;
209
        tmp1.by = -3*curr.y - 2*tmp1.y + 3*next.y - tmp2.y;
210
        tmp1.cy = tmp1.y;
211
        tmp1.dy = curr.y;
212
      
213
        tmp1.az =  2*curr.z +   tmp1.z - 2*next.z + tmp2.z;
214
        tmp1.bz = -3*curr.z - 2*tmp1.z + 3*next.z - tmp2.z;
215
        tmp1.cz = tmp1.z;
216
        tmp1.dz = curr.z;
217
        }
218
      }
219
   
220
    cacheDirty = false;
221
    }
222
  
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  private float noise(float time,int vecNum)
226
    {
227
    float lower, upper, len;  
228
    float d = time*(NUM_NOISE+1);
229
    int index = (int)d;
230
    if( index>=NUM_NOISE+1 ) index=NUM_NOISE;
231
    tmpN = vn.elementAt(vecNum);
232
   
233
    float t = d-index;
234
    t = t*t*(3-2*t);
235
   
236
    switch(index)
237
      {
238
      case 0        : mFactor1 = mNoise*tmpN.ny[0]*t;
239
                      mFactor2 = mNoise*tmpN.nz[0]*t;
240
                      return time + mNoise*(d*tmpN.nx[0]-time);
241
      case NUM_NOISE: mFactor1= mNoise*tmpN.ny[NUM_NOISE-1]*(1-t);
242
                      mFactor2= mNoise*tmpN.nz[NUM_NOISE-1]*(1-t);
243
                      len = ((float)NUM_NOISE)/(NUM_NOISE+1);
244
                      lower = len + mNoise*(tmpN.nx[NUM_NOISE-1]-len);  
245
                      return (1.0f-lower)*(d-NUM_NOISE) + lower;
246
      default       : float ya,yb;
247
                      yb = tmpN.ny[index  ];
248
                      ya = tmpN.ny[index-1];
249
                      mFactor1 = mNoise*((yb-ya)*t+ya);
250
                      yb = tmpN.nz[index  ];
251
                      ya = tmpN.nz[index-1];
252
                      mFactor2 = mNoise*((yb-ya)*t+ya);
253
   
254
                      len = ((float)index)/(NUM_NOISE+1);
255
                      lower = len + mNoise*(tmpN.nx[index-1]-len);   
256
                      len = ((float)index+1)/(NUM_NOISE+1); 
257
                      upper = len + mNoise*(tmpN.nx[index  ]-len);
258
            
259
                      return (upper-lower)*(d-index) + lower; 
260
      }
261
    }
262
     
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264
// v is the speed vector (i.e. position p(t) differentiated by time)
265
// a is the acceleration vector (differentiate once more)
266
// now what we are doing is compute vec1{X,Y,Z} to be a vector perpendicular to v and in the same plane as both v and a.
267
// vec2{X,Y,Z} would be (v)x(vec1).
268
//  
269
// vec1 = a-delta*v where delta = (v*a)/|v|^2   (see Gram-Schmidt)
270
  
271
  private void setUpVectors(float time,VectorCache vc)
272
    {
273
    if( vc!=null )
274
      {
275
      float vx = (3*vc.ax*time+2*vc.bx)*time+vc.cx;
276
      float vy = (3*vc.ay*time+2*vc.by)*time+vc.cy;
277
      float vz = (3*vc.az*time+2*vc.bz)*time+vc.cz;
278
     
279
      float ax = 6*vc.ax*time+2*vc.bx;
280
      float ay = 6*vc.ay*time+2*vc.by;
281
      float az = 6*vc.az*time+2*vc.bz;
282
     
283
      float v_sq = vx*vx+vy*vy+vz*vz;
284
      float delta = (vx*ax+vy*ay+vz*az)/v_sq;
285
     
286
      vec1X = ax-delta*vx;
287
      vec1Y = ay-delta*vy;
288
      vec1Z = az-delta*vz;
289
     
290
      vec2X = vy*vec1Z-vz*vec1Y;
291
      vec2Y = vz*vec1X-vx*vec1Z;
292
      vec2Z = vx*vec1Y-vy*vec1X;
293
     
294
      float len1 = (float)Math.sqrt(v_sq/(vec1X*vec1X+vec1Y*vec1Y+vec1Z*vec1Z));
295
      float len2 = (float)Math.sqrt(v_sq/(vec2X*vec2X+vec2Y*vec2Y+vec2Z*vec2Z));   
296
     
297
      vec1X*=len1;
298
      vec1Y*=len1;
299
      vec1Z*=len1;
300
     
301
      vec2X*=len2;
302
      vec2Y*=len2;
303
      vec2Z*=len2;
304
      }
305
    else
306
      {
307
      curr = vv.elementAt(0);
308
      next = vv.elementAt(1); 
309
     
310
      float vx = (next.x-curr.x);
311
      float vy = (next.y-curr.y);
312
      float vz = (next.z-curr.z);
313
     
314
      float b = (float)Math.sqrt(vx*vx+vy*vy);
315
     
316
      if( b>0.0f )
317
        {
318
        vec1X = vx*vz/b;
319
        vec1Y = vy*vz/b;
320
        vec1Z = -b;
321
      
322
        vec2X = vy*vec1Z-vz*vec1Y;
323
        vec2Y = vz*vec1X-vx*vec1Z;
324
        vec2Z = vx*vec1Y-vy*vec1X;
325
       
326
        float len2 = (float)Math.sqrt((vx*vx+vy*vy+vz*vz)/(vec2X*vec2X+vec2Y*vec2Y+vec2Z*vec2Z));
327
       
328
        vec2X*=len2;
329
        vec2Y*=len2;
330
        vec2Z*=len2;
331
        }
332
      else
333
        {
334
        vec1X = vz;
335
        vec1Y = 0.0f;
336
        vec1Z = 0.0f;
337
      
338
        vec2X = 0.0f;
339
        vec2Y = vz;
340
        vec2Z = 0.0f;
341
        }
342
      }
343
    }
344
  
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
// PUBLIC API
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348
/**
349
 * Default constructor.
350
 */
351
  public Dynamic3D()
352
    {
353
    vv = new Vector<>();
354
    vc = new Vector<>();
355
    vn = null;
356
    numPoints = 0;
357
    cacheDirty = false;
358
    mMode = MODE_LOOP;
359
    mDuration = 0;
360
    mCount = 0.5f;
361
    mNoise = 0.0f;
362
    }
363

    
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365

    
366
/**
367
 * Default constructor.
368
 *
369
 * @param duration number of milliseconds it takes to do a full loop/path from first vector to the
370
 *                 last and back to the first
371
 * @param count    number of loops/paths we will do; mCount = 1.5 means we go from the first vector
372
 *                 to the last, back to first, and to the last again.
373
 */
374
  public Dynamic3D(int duration, float count)
375
    {
376
    vv = new Vector<>();
377
    vc = new Vector<>();
378
    vn = null;
379
    numPoints = 0;
380
    cacheDirty = false;
381
    mMode = MODE_LOOP;
382
    mDuration = duration;
383
    mCount = count;
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387
/**
388
 * Returns the location'th Static3D.
389
 *   
390
 * @param location the index of the Point we are interested in.
391
 * @return The Static3D, if 0<=location&lt;getNumPoints(), or null otherwise.
392
 */  
393
  public synchronized Static3D getPoint(int location)
394
    {
395
    return (location>=0 && location<numPoints) ? vv.elementAt(location) : null;  
396
    }
397
  
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
/**
400
 * Resets the location'th Point.
401
 * 
402
 * @param location the index of the Point we are setting.
403
 * @param x New value of its first float.
404
 */
405
  public synchronized void setPoint(int location, float x, float y, float z)
406
    {
407
    if( location>=0 && location<numPoints )
408
      {
409
      curr = vv.elementAt(location);
410
   
411
      if( curr!=null )
412
        {
413
        curr.set(x,y,z);
414
        cacheDirty=true;
415
        }
416
      }
417
    }
418

    
419
///////////////////////////////////////////////////////////////////////////////////////////////////
420
/**
421
 * Adds a new Static3D to the end of our list of Points to interpolate through.
422
 * <p>   
423
 * Only a reference to the Point gets added to the List; this means that one can add a Point 
424
 * here, and later on {@link Static3D#set(float,float,float)} it to some new value and the
425
 * change will be seamlessly reflected in the interpolated path.  
426
 * <p>
427
 * A Point can be added multiple times.
428
 *   
429
 * @param v The Point to add.
430
 */    
431
  public synchronized void add(Static3D v)
432
    {
433
    if( v!=null )
434
      {
435
      vv.add(v);
436
        
437
      if( vn!=null ) vn.add(new VectorNoise());
438
       
439
      switch(numPoints)
440
        {
441
        case 0: break;
442
        case 1: setUpVectors(0.0f,null);
443
                break;
444
        case 2: vc.add(new VectorCache());
445
                vc.add(new VectorCache());
446
                vc.add(new VectorCache());
447
                break;
448
        default:vc.add(new VectorCache());
449
        }
450

    
451
      numPoints++;
452
      cacheDirty = true;
453
      }
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457
/**
458
 * Adds a new Static3D to the location'th place in our List of Points to interpolate through.
459
 *   
460
 * @param location Index in our List to add the new Point at.
461
 * @param v The Point to add.
462
 */  
463
  public synchronized void add(int location, Static3D v)
464
    {
465
    if( v!=null )
466
      {
467
      vv.add(location, v);
468
      
469
      if( vn!=null ) vn.add(new VectorNoise());
470
      
471
      switch(numPoints)
472
        {
473
        case 0: break;
474
        case 1: setUpVectors(0.0f,null);
475
                break;
476
        case 2: vc.add(new VectorCache());
477
                vc.add(new VectorCache());
478
                vc.add(new VectorCache());
479
                break;
480
        default:vc.add(location,new VectorCache());
481
        }
482

    
483
      numPoints++;
484
      cacheDirty = true;
485
      }
486
    }
487
  
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489
/**
490
 * Removes all occurrences of Point v from the List of Points to interpolate through.  
491
 * 
492
 * @param v The Point to remove.
493
 * @return <code>true</code> if we have removed at least one Point.
494
 */
495
  public synchronized boolean remove(Static3D v)
496
    {
497
    int n = vv.indexOf(v);
498
    boolean found = false;
499
   
500
    while( n>=0 ) 
501
      {
502
      vv.remove(n);
503
     
504
      if( vn!=null ) vn.remove(0);
505
     
506
      switch(numPoints)
507
        {
508
        case 0:
509
        case 1: 
510
        case 2: break;
511
        case 3: vc.removeAllElements();
512
                setUpVectors(0.0f,null);
513
                break;
514
        default:vc.remove(n);
515
        }
516

    
517
      numPoints--;
518
      found = true;
519
      n = vv.indexOf(v);
520
      }
521
   
522
    if( found ) 
523
      {
524
      cacheDirty=true;
525
      }
526
   
527
    return found;
528
    }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531
/**
532
 * Removes a location'th Point from the List of Points we interpolate through.
533
 * 
534
 * @param location index of the Point we want to remove. 
535
 * @return <code>true</code> if location is valid, i.e. if 0<=location&lt;getNumPoints().
536
 */
537
  public synchronized boolean remove(int location)
538
    {
539
    if( location>=0 && location<numPoints ) 
540
      {
541
      vv.removeElementAt(location);
542
       
543
      if( vn!=null ) vn.remove(0);
544
      
545
      switch(numPoints)
546
        {
547
        case 0:
548
        case 1: 
549
        case 2: break;
550
        case 3: vc.removeAllElements();
551
                setUpVectors(0.0f,null);
552
                break;
553
        default:vc.removeElementAt(location);
554
        }
555

    
556
      numPoints--;
557
      cacheDirty = true; 
558
      return true;
559
      }
560

    
561
   return false;
562
   }
563
  
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565
/**
566
 * Removes all Points.
567
 */
568
  public synchronized void removeAll()
569
    {
570
    numPoints = 0;
571
    vv.removeAllElements();
572
    vc.removeAllElements();
573
    cacheDirty = false;
574
   
575
    if( vn!=null ) vn.removeAllElements();
576
    }
577
  
578
///////////////////////////////////////////////////////////////////////////////////////////////////
579
/**
580
 * Writes the results of interpolation between the Points at time 'time' to the passed float buffer.
581
 * <p>
582
 * Since this is a 3-dimensional Dynamic, the resulting interpolated Static3D gets written
583
 * to three locations in the buffer: buffer[offset], buffer[offset+1] and buffer[offset+2]. 
584
 * 
585
 * @param buffer Float buffer we will write the resulting Static3D to.
586
 * @param offset Offset in the buffer where to write the result.
587
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
588
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
589
 */    
590
  public synchronized void interpolate(float[] buffer, int offset, float time)
591
    {  
592
    switch(numPoints)
593
      {
594
      case 0: buffer[offset  ] = 0.0f;
595
              buffer[offset+1] = 0.0f;
596
              buffer[offset+2] = 0.0f;
597
              break;
598
      case 1: curr = vv.elementAt(0);
599
              buffer[offset  ] = curr.x;
600
              buffer[offset+1] = curr.y;
601
              buffer[offset+2] = curr.z;
602
              break;
603
      case 2: curr = vv.elementAt(0);
604
              next = vv.elementAt(1);
605
             
606
              if( mMode==MODE_LOOP || mMode==MODE_PATH ) time = (time>0.5f ? 2-2*time : 2*time);
607
             
608
              if( vn!=null )
609
                {
610
                time = noise(time,0);
611
            
612
                buffer[offset  ] = (next.x-curr.x)*time + curr.x + (vec1X*mFactor1 + vec2X*mFactor2);
613
                buffer[offset+1] = (next.y-curr.y)*time + curr.y + (vec1Y*mFactor1 + vec2Y*mFactor2);
614
                buffer[offset+2] = (next.z-curr.z)*time + curr.z + (vec1Z*mFactor1 + vec2Z*mFactor2); 
615
                }
616
              else
617
                {
618
                buffer[offset  ] = (next.x-curr.x)*time + curr.x;
619
                buffer[offset+1] = (next.y-curr.y)*time + curr.y;
620
                buffer[offset+2] = (next.z-curr.z)*time + curr.z;
621
                }
622
             
623
              break;
624
      default:float t = time;
625
        
626
              switch(mMode)
627
                {
628
                case MODE_LOOP: time = time*numPoints;
629
                                break;
630
                case MODE_PATH: time = (time<=0.5f) ? 2*time*(numPoints-1) : 2*(1-time)*(numPoints-1);
631
                                break;
632
                case MODE_JUMP: time = time*(numPoints-1);
633
                                break;
634
                }
635
           
636
              int vecCurr = (int)time;
637
              time = time-vecCurr;
638
      
639
              if( vecCurr>=0 && vecCurr<numPoints )
640
                {
641
                if( cacheDirty ) recomputeCache();    // recompute cache if we have added or remove vectors since last computation
642
                else if( mVecCurr!= vecCurr )         // ...or if we have just passed a vector and the vector we are currently flying to has changed
643
                  {
644
                  int vecNext;   
645
                  mVecCurr = vecCurr;
646
                       
647
                  switch(mMode)
648
                    {
649
                    case MODE_LOOP: vecNext = vecCurr==numPoints-1 ? 0:vecCurr+1; 
650
                                    break;
651
                    case MODE_PATH: if( t<0.5f ) vecNext = vecCurr==numPoints-1 ? numPoints-2: vecCurr+1;  
652
                                    else         vecNext = vecCurr==0 ? 1 : vecCurr-1;  
653
                                    break;
654
                    case MODE_JUMP: vecNext = vecCurr==numPoints-1 ? 1:vecCurr+1;
655
                                    break;
656
                    default       : vecNext = 0;                
657
                    }
658
              
659
                  next = vv.elementAt(vecNext);
660
                  tmp2 = vc.elementAt(vecNext);
661
              
662
                  if( tmp2.vx!=next.x || tmp2.vy!=next.y || tmp2.vz!=next.z ) recomputeCache();
663
                  }
664
            
665
                tmp1 = vc.elementAt(vecCurr);
666
               
667
                if( vn!=null )
668
                  {
669
                  time = noise(time,vecCurr);
670
              
671
                  setUpVectors(time,tmp1);
672
                 
673
                  buffer[offset  ]= ((tmp1.ax*time+tmp1.bx)*time+tmp1.cx)*time+tmp1.dx + (vec1X*mFactor1 + vec2X*mFactor2);
674
                  buffer[offset+1]= ((tmp1.ay*time+tmp1.by)*time+tmp1.cy)*time+tmp1.dy + (vec1Y*mFactor1 + vec2Y*mFactor2);
675
                  buffer[offset+2]= ((tmp1.az*time+tmp1.bz)*time+tmp1.cz)*time+tmp1.dz + (vec1Z*mFactor1 + vec2Z*mFactor2);
676
                  }
677
                else
678
                  {
679
                  buffer[offset  ]= ((tmp1.ax*time+tmp1.bx)*time+tmp1.cx)*time+tmp1.dx;
680
                  buffer[offset+1]= ((tmp1.ay*time+tmp1.by)*time+tmp1.cy)*time+tmp1.dy;
681
                  buffer[offset+2]= ((tmp1.az*time+tmp1.bz)*time+tmp1.cz)*time+tmp1.dz;
682
                  }
683
               
684
                break;
685
                }
686
       }
687
     }  
688

    
689
  }
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
//
(8-8/14)