Project

General

Profile

« Previous | Next » 

Revision c6dec65b

Added by Leszek Koltunski over 7 years ago

1. Attempt to deal with unstable Orthonormal Base in Dynamic class (so far unsuccessful)
2. Improvements to the 'Dynamic' (and by necessity, 'MovingEffects') applications (to be able to debug the previous)

View differences:

src/main/java/org/distorted/library/type/Dynamic.java
103 103
  protected float[] mFactor;
104 104
  protected float[] mNoise;
105 105
  protected float[][] baseV;
106
  private float[] buffer;
106
  private float[] buf;
107
  private float[] old;
107 108

  
108 109
  ///////////////////////////////////////////////////////////////////////////////////////////////////
109 110
  // the coefficients of the X(t), Y(t) and Z(t) polynomials: X(t) = ax*T^3 + bx*T^2 + cx*t + dx  etc.
......
155 156
    mDimension = dimension;
156 157

  
157 158
    baseV = new float[mDimension][mDimension];
158
    buffer= new float[mDimension];
159
    buf= new float[mDimension];
160
    old= new float[mDimension];
159 161
    }
160 162

  
161 163
///////////////////////////////////////////////////////////////////////////////////////////////////
......
168 170
      }
169 171
    else
170 172
      {
171
      float x = (float)currentDuration/mDuration;
173
      double x = (double)currentDuration/mDuration;
172 174
           
173 175
      if( x<=mCount || mCount<=0.0f )
174 176
        {
175
        interpolate(buffer,offset,x-(int)x);
177
        interpolate(buffer,offset, (float)(x-(int)x) );
176 178
        }
177 179
      }
178 180
    }
......
187 189
      return false;
188 190
      }
189 191
     
190
    float x = (float)currentDuration/mDuration;
192
    double x = (double)currentDuration/mDuration;
191 193
           
192 194
    if( x<=mCount || mCount<=0.0f )
193 195
      {
194
      interpolate(buffer,offset,x-(int)x);
196
      interpolate(buffer,offset, (float)(x-(int)x) );
195 197
        
196 198
      if( currentDuration+step > mDuration*mCount && mCount>0.0f )
197 199
        {
......
296 298
      }
297 299
    }
298 300

  
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

  
303
  private void checkAngle(int index)
304
    {
305
    float cosA = 0.0f;
306

  
307
    for(int k=0;k<mDimension; k++)
308
      cosA += baseV[index][k]*old[k];
309

  
310
    if( cosA<0.0f )
311
      {
312
/*
313
      /// DEBUGGING ////
314
      String s = index+" (";
315
      float t;
316

  
317
      for(int j=0; j<mDimension; j++)
318
        {
319
        t = ((int)(100*baseV[index][j]))/(100.0f);
320
        s+=(" "+t);
321
        }
322
      s += ") (";
323

  
324
      for(int j=0; j<mDimension; j++)
325
        {
326
        t = ((int)(100*old[j]))/(100.0f);
327
        s+=(" "+t);
328
        }
329
      s+= ")";
330

  
331
      android.util.Log.e("dynamic", "kat: " + s);
332
      /// END DEBUGGING ///
333
*/
334
      for(int j=0; j<mDimension; j++)
335
        baseV[index][j] = -baseV[index][j];
336
      }
337
    }
338

  
299 339
///////////////////////////////////////////////////////////////////////////////////////////////////
300 340
// helper function in case we are interpolating through exactly 2 points
301 341

  
......
414 454
      }
415 455
    else
416 456
      {
417
      for(int i=0; i<mDimension-1; i++)
418
        for(int j=0; j<mDimension; j++)
419
          {
420
          if( (i<last_non_zero && j==i) || (i>=last_non_zero && j==i+1) )
421
            baseV[i+1][j]= baseV[0][last_non_zero];
422
          else
423
            baseV[i+1][j]= 0.0f;
424
          }
425

  
426
      // That's it if velocity vector is already one of the standard orthonormal
427
      // vectors. Otherwise (i.e. non_zeros>1) velocity is linearly independent
428
      // to what's in baseV right now and we can use (modified!) Gram-Schmidt.
457
      // We can use (modified!) Gram-Schmidt.
429 458
      //
430 459
      // b[0] = b[0]
431 460
      // b[1] = b[1] - (<b[1],b[0]>/<b[0],b[0]>)*b[0]
432 461
      // b[2] = b[2] - (<b[2],b[0]>/<b[0],b[0]>)*b[0] - (<b[2],b[1]>/<b[1],b[1]>)*b[1]
433 462
      // b[3] = b[3] - (<b[3],b[0]>/<b[0],b[0]>)*b[0] - (<b[3],b[1]>/<b[1],b[1]>)*b[1] - (<b[3],b[2]>/<b[2],b[2]>)*b[2]
434
      //
463
      // (...)
435 464
      // then b[i] = b[i] / |b[i]|
436 465

  
437
      if( non_zeros>1 )
466
      float tmp;
467

  
468
      for(int i=1; i<mDimension; i++)          /// one iteration computes baseV[i][*], the i-th orthonormal vector.
438 469
        {
439
        float tmp;
470
        buf[i-1]=0.0f;
440 471

  
441
        for(int i=1; i<mDimension; i++)
472
        for(int k=0; k<mDimension; k++)
442 473
          {
443
          buffer[i-1]=0.0f;
444

  
445
          for(int k=0; k<mDimension; k++)
446
            {
447
            value = baseV[i-1][k];
448
            buffer[i-1] += value*value;
449
            }
450

  
451
          for(int j=0; j<i; j++)
452
            {
453
            tmp = 0.0f;
474
          old[k] = baseV[i][k];
454 475

  
455
            for(int k=0;k<mDimension; k++)
456
              {
457
              tmp += baseV[i][k]*baseV[j][k];
458
              }
459

  
460
            tmp /= buffer[j];
476
          if( (i<=last_non_zero && k==i-1) || (i>=(last_non_zero+1) && k==i) )
477
            baseV[i][k]= baseV[0][last_non_zero];
478
          else
479
            baseV[i][k]= 0.0f;
461 480

  
462
            for(int k=0;k<mDimension; k++)
463
              {
464
              baseV[i][k] -= tmp*baseV[j][k];
465
              }
466
            }
481
          value = baseV[i-1][k];
482
          buf[i-1] += value*value;
467 483
          }
468 484

  
469
        buffer[mDimension-1]=0.0f;
470
        for(int k=0; k<mDimension; k++)
485
        for(int j=0; j<i; j++)
471 486
          {
472
          value = baseV[mDimension-1][k];
473
          buffer[mDimension-1] += value*value;
474
          }
487
          tmp = 0.0f;
475 488

  
476
        for(int i=1; i<mDimension; i++)
477
          {
478
          tmp = (float)Math.sqrt(buffer[0]/buffer[i]);
489
          for(int k=0;k<mDimension; k++)
490
            {
491
            tmp += baseV[i][k]*baseV[j][k];
492
            }
493

  
494
          tmp /= buf[j];
479 495

  
480 496
          for(int k=0;k<mDimension; k++)
481 497
            {
482
            baseV[i][k] *= tmp;
498
            baseV[i][k] -= tmp*baseV[j][k];
483 499
            }
484 500
          }
485
        }
501

  
502
        if( i>=2 ) checkAngle(i);
503
        }                                       /// end compute baseV[i][*]
504

  
505
      buf[mDimension-1]=0.0f;                   /// Normalize
506
      for(int k=0; k<mDimension; k++)           //
507
        {                                       //
508
        value = baseV[mDimension-1][k];         //
509
        buf[mDimension-1] += value*value;       //
510
        }                                       //
511
                                                //
512
      for(int i=1; i<mDimension; i++)           //
513
        {                                       //
514
        tmp = (float)Math.sqrt(buf[0]/buf[i]);  //
515
                                                //
516
        for(int k=0;k<mDimension; k++)          //
517
          {                                     //
518
          baseV[i][k] *= tmp;                   //
519
          }                                     //
520
        }                                       /// End Normalize
486 521
      }
487 522

  
488 523
    //printBase("end");
src/main/java/org/distorted/library/type/Dynamic1D.java
386 386
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
387 387
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
388 388
 */
389
  public synchronized void interpolate(float[] buffer, int offset, float time)
389
  synchronized void interpolate(float[] buffer, int offset, float time)
390 390
    {
391 391
    switch(numPoints)
392 392
      {
src/main/java/org/distorted/library/type/Dynamic2D.java
407 407
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
408 408
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
409 409
 */  
410
  public synchronized void interpolate(float[] buffer, int offset, float time)
410
  synchronized void interpolate(float[] buffer, int offset, float time)
411 411
    {
412 412
    switch(numPoints)
413 413
      {
src/main/java/org/distorted/library/type/Dynamic3D.java
430 430
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
431 431
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
432 432
 */    
433
  public synchronized void interpolate(float[] buffer, int offset, float time)
433
  synchronized void interpolate(float[] buffer, int offset, float time)
434 434
    {  
435 435
    switch(numPoints)
436 436
      {
src/main/java/org/distorted/library/type/Dynamic4D.java
449 449
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
450 450
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
451 451
 */    
452
  public synchronized void interpolate(float[] buffer, int offset, float time)
452
  synchronized void interpolate(float[] buffer, int offset, float time)
453 453
    {  
454 454
    switch(numPoints)
455 455
      {
src/main/java/org/distorted/library/type/Dynamic5D.java
468 468
 * @param time Time of interpolation. Time=0.0 would return the first Point, Time=0.5 - the last,
469 469
 *             time=1.0 - the first again, and time 0.1 would be 1/5 of the way between the first and the last Points.
470 470
 */    
471
  public synchronized void interpolate(float[] buffer, int offset, float time)
471
  synchronized void interpolate(float[] buffer, int offset, float time)
472 472
    {  
473 473
    switch(numPoints)
474 474
      {

Also available in: Unified diff