Project

General

Profile

« Previous | Next » 

Revision 9aabc9eb

Added by Leszek Koltunski almost 3 years ago

Dynamics: introduce two speed modes - smooth and segment_constant.
Prepare the third mode - globally_constant.

View differences:

src/main/java/org/distorted/library/type/Dynamic1D.java
44 44
    curr = vv.elementAt(c);
45 45
    next = vv.elementAt(n);
46 46

  
47
    tmp1 = vc.elementAt(c);
47
    tmpCache1 = vc.elementAt(c);
48 48
    
49 49
    float px = curr.x - prev.x;
50 50
    float nx = next.x - curr.x;
......
57 57
      
58 58
      if( q>1 )
59 59
        {
60
        tmp1.tangent[0] = nx+px/q;
60
        tmpCache1.velocity[0] = nx+px/q;
61 61
        }
62 62
      else
63 63
        {
64
        tmp1.tangent[0] = px+nx*q;
64
        tmpCache1.velocity[0] = px+nx*q;
65 65
        }
66 66
      }
67 67
    else
68 68
      {
69
      tmp1.tangent[0] = 0.0f;
69
      tmpCache1.velocity[0] = 0.0f;
70 70
      }
71 71
    }
72 72
      
......
76 76
    {  
77 77
    if( numPoints==1 )
78 78
      {
79
      tmp1= vc.elementAt(0);
79
      tmpCache1 = vc.elementAt(0);
80 80
      curr= vv.elementAt(0);
81 81
        
82
      tmp1.a[0] = 0.0f;
83
      tmp1.b[0] = 0.0f;
84
      tmp1.c[0] = curr.x;
85
      tmp1.d[0] = 0.0f;
82
      tmpCache1.a[0] = 0.0f;
83
      tmpCache1.b[0] = 0.0f;
84
      tmpCache1.c[0] = curr.x;
85
      tmpCache1.d[0] = 0.0f;
86 86
      }
87 87
    else if( numPoints==2 )
88 88
      {
89
      tmp1= vc.elementAt(0);
90
      tmp2= vc.elementAt(1);
89
      tmpCache1 = vc.elementAt(0);
90
      tmpCache2 = vc.elementAt(1);
91 91
      curr= vv.elementAt(0);
92 92
      next= vv.elementAt(1);
93 93
          
94
      tmp1.a[0] = 0.0f;
95
      tmp1.b[0] = 0.0f;
96
      tmp1.c[0] = next.x - curr.x;
97
      tmp1.d[0] = curr.x;
94
      tmpCache1.a[0] = 0.0f;
95
      tmpCache1.b[0] = 0.0f;
96
      tmpCache1.c[0] = next.x - curr.x;
97
      tmpCache1.d[0] = curr.x;
98 98
      
99
      tmp2.a[0] = 0.0f;
100
      tmp2.b[0] = 0.0f;
101
      tmp2.c[0] = curr.x - next.x;
102
      tmp2.d[0] = next.x;
99
      tmpCache2.a[0] = 0.0f;
100
      tmpCache2.b[0] = 0.0f;
101
      tmpCache2.c[0] = curr.x - next.x;
102
      tmpCache2.d[0] = next.x;
103 103
      }
104 104
    else
105 105
      {
......
111 111
        {
112 112
        n = i<numPoints-1 ? i+1:0;  
113 113
      
114
        tmp1= vc.elementAt(i);
115
        tmp2= vc.elementAt(n);
114
        tmpCache1 = vc.elementAt(i);
115
        tmpCache2 = vc.elementAt(n);
116 116
        curr= vv.elementAt(i);
117 117
        next= vv.elementAt(n);
118 118
    
119
        tmp1.cached[0] = curr.x;
119
        tmpCache1.cached[0] = curr.x;
120 120
        
121
        tmp1.a[0] = mConvexity*( 2*curr.x +   tmp1.tangent[0] - 2*next.x + tmp2.tangent[0]);
122
        tmp1.b[0] = mConvexity*(-3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0]);
123
        tmp1.c[0] = mConvexity*(tmp1.tangent[0]) + (1.0f-mConvexity)*(next.x-curr.x);
124
        tmp1.d[0] = curr.x;
121
        tmpCache1.a[0] = mConvexity*( 2*curr.x +   tmpCache1.velocity[0] - 2*next.x + tmpCache2.velocity[0]);
122
        tmpCache1.b[0] = mConvexity*(-3*curr.x - 2* tmpCache1.velocity[0] + 3*next.x - tmpCache2.velocity[0]);
123
        tmpCache1.c[0] = mConvexity*(tmpCache1.velocity[0]) + (1.0f-mConvexity)*(next.x-curr.x);
124
        tmpCache1.d[0] = curr.x;
125

  
126
        if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) smoothOutSegment(tmpCache1);
125 127
        }
126 128
      }
127 129
   
......
442 444
                  {
443 445
                  int vecNext = getNext(vecCurr,t);
444 446
                  next = vv.elementAt(vecNext);
445
                  tmp2 = vc.elementAt(vecNext);
447
                  tmpCache2 = vc.elementAt(vecNext);
446 448
              
447
                  if( tmp2.cached[0]!=next.x ) recomputeCache();
449
                  if( tmpCache2.cached[0]!=next.x ) recomputeCache();
448 450
                  }
449 451

  
450 452
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
451 453

  
452 454
                mSegment = segment;
453

  
454 455
                time = time-vecCurr;
455

  
456
                tmp1 = vc.elementAt(vecCurr);
456
                tmpCache1 = vc.elementAt(vecCurr);
457
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
457 458

  
458 459
                if( vn!=null )
459 460
                  {
460 461
                  time = noise(time,vecCurr);
461 462
                  }
462 463
            
463
                buffer[offset] = ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
464
                buffer[offset] = ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0];
464 465
                break;
465 466
                }
466 467
        }

Also available in: Unified diff