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/Dynamic2D.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 py = curr.y - prev.y;
......
59 59
      
60 60
      if( q>1 )
61 61
        {
62
        tmp1.tangent[0] = nx+px/q;
63
        tmp1.tangent[1] = ny+py/q;
62
        tmpCache1.velocity[0] = nx+px/q;
63
        tmpCache1.velocity[1] = ny+py/q;
64 64
        }
65 65
      else
66 66
        {
67
        tmp1.tangent[0] = px+nx*q;
68
        tmp1.tangent[1] = py+ny*q;
67
        tmpCache1.velocity[0] = px+nx*q;
68
        tmpCache1.velocity[1] = py+ny*q;
69 69
        }
70 70
      }
71 71
    else
72 72
      {
73
      tmp1.tangent[0] = 0.0f;
74
      tmp1.tangent[1] = 0.0f;
73
      tmpCache1.velocity[0] = 0.0f;
74
      tmpCache1.velocity[1] = 0.0f;
75 75
      }
76 76
    }
77 77
   
......
81 81
    {  
82 82
    if( numPoints==1 )
83 83
      {
84
      tmp1= vc.elementAt(0);
84
      tmpCache1 = vc.elementAt(0);
85 85
      curr= vv.elementAt(0);
86 86
              
87
      tmp1.a[0] = tmp1.a[1] = 0.0f;
88
      tmp1.b[0] = tmp1.b[1] = 0.0f;
89
      tmp1.c[0] = curr.x;
90
      tmp1.c[1] = curr.y;
91
      tmp1.d[0] = tmp1.d[1] = 0.0f;
87
      tmpCache1.a[0] = tmpCache1.a[1] = 0.0f;
88
      tmpCache1.b[0] = tmpCache1.b[1] = 0.0f;
89
      tmpCache1.c[0] = curr.x;
90
      tmpCache1.c[1] = curr.y;
91
      tmpCache1.d[0] = tmpCache1.d[1] = 0.0f;
92 92
      }
93 93
    else if( numPoints==2 )
94 94
      {
95
      tmp1= vc.elementAt(0);
96
      tmp2= vc.elementAt(1);
95
      tmpCache1 = vc.elementAt(0);
96
      tmpCache2 = vc.elementAt(1);
97 97
      curr= vv.elementAt(0);
98 98
      next= vv.elementAt(1);
99 99
          
100
      tmp1.a[0] = tmp1.a[1] = 0.0f;
101
      tmp1.b[0] = tmp1.b[1] = 0.0f;
102
      tmp1.c[0] = next.x - curr.x;
103
      tmp1.c[1] = next.y - curr.y;
104
      tmp1.d[0] = curr.x;
105
      tmp1.d[1] = curr.y;
100
      tmpCache1.a[0] = tmpCache1.a[1] = 0.0f;
101
      tmpCache1.b[0] = tmpCache1.b[1] = 0.0f;
102
      tmpCache1.c[0] = next.x - curr.x;
103
      tmpCache1.c[1] = next.y - curr.y;
104
      tmpCache1.d[0] = curr.x;
105
      tmpCache1.d[1] = curr.y;
106 106
      
107
      tmp2.a[0] = tmp2.a[1] = 0.0f;
108
      tmp2.b[0] = tmp2.b[1] = 0.0f;
109
      tmp2.c[0] = curr.x - next.x;
110
      tmp2.c[1] = curr.y - next.y;
111
      tmp2.d[0] = next.x;
112
      tmp2.d[1] = next.y;
107
      tmpCache2.a[0] = tmpCache2.a[1] = 0.0f;
108
      tmpCache2.b[0] = tmpCache2.b[1] = 0.0f;
109
      tmpCache2.c[0] = curr.x - next.x;
110
      tmpCache2.c[1] = curr.y - next.y;
111
      tmpCache2.d[0] = next.x;
112
      tmpCache2.d[1] = next.y;
113 113
      }
114 114
    else
115 115
      {
......
121 121
        {
122 122
        n = i<numPoints-1 ? i+1:0;  
123 123
      
124
        tmp1= vc.elementAt(i);
125
        tmp2= vc.elementAt(n);
124
        tmpCache1 = vc.elementAt(i);
125
        tmpCache2 = vc.elementAt(n);
126 126
        curr= vv.elementAt(i);
127 127
        next= vv.elementAt(n);
128 128
      
129
        tmp1.cached[0] = curr.x;
130
        tmp1.cached[1] = curr.y;
131

  
132
        tmp1.a[0] = mConvexity*( 2*curr.x +   tmp1.tangent[0] - 2*next.x + tmp2.tangent[0]);
133
        tmp1.b[0] = mConvexity*(-3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0]);
134
        tmp1.c[0] = mConvexity*(tmp1.tangent[0]) + (1.0f-mConvexity)*(next.x-curr.x);
135
        tmp1.d[0] = curr.x;
136

  
137
        tmp1.a[1] = mConvexity*( 2*curr.y +   tmp1.tangent[1] - 2*next.y + tmp2.tangent[1]);
138
        tmp1.b[1] = mConvexity*(-3*curr.y - 2*tmp1.tangent[1] + 3*next.y - tmp2.tangent[1]);
139
        tmp1.c[1] = mConvexity*(tmp1.tangent[1]) + (1.0f-mConvexity)*(next.y-curr.y);
140
        tmp1.d[1] = curr.y;
129
        tmpCache1.cached[0] = curr.x;
130
        tmpCache1.cached[1] = curr.y;
131

  
132
        tmpCache1.a[0] = mConvexity*( 2*curr.x +   tmpCache1.velocity[0] - 2*next.x + tmpCache2.velocity[0]);
133
        tmpCache1.b[0] = mConvexity*(-3*curr.x - 2* tmpCache1.velocity[0] + 3*next.x - tmpCache2.velocity[0]);
134
        tmpCache1.c[0] = mConvexity*(tmpCache1.velocity[0]) + (1.0f-mConvexity)*(next.x-curr.x);
135
        tmpCache1.d[0] = curr.x;
136

  
137
        tmpCache1.a[1] = mConvexity*( 2*curr.y +   tmpCache1.velocity[1] - 2*next.y + tmpCache2.velocity[1]);
138
        tmpCache1.b[1] = mConvexity*(-3*curr.y - 2* tmpCache1.velocity[1] + 3*next.y - tmpCache2.velocity[1]);
139
        tmpCache1.c[1] = mConvexity*(tmpCache1.velocity[1]) + (1.0f-mConvexity)*(next.y-curr.y);
140
        tmpCache1.d[1] = curr.y;
141

  
142
        if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) smoothOutSegment(tmpCache1);
141 143
        }
142 144
      }
143 145
    
......
475 477
                  {
476 478
                  int vecNext = getNext(vecCurr,t);
477 479
                  next = vv.elementAt(vecNext);
478
                  tmp2 = vc.elementAt(vecNext);
480
                  tmpCache2 = vc.elementAt(vecNext);
479 481

  
480
                  if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y ) recomputeCache();
482
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y ) recomputeCache();
481 483
                  }
482 484

  
483 485
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
484 486

  
485 487
                mSegment = segment;
486

  
487 488
                time = time-vecCurr;
488
                tmp1 = vc.elementAt(vecCurr);
489
                tmpCache1 = vc.elementAt(vecCurr);
490
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
489 491

  
490 492
                if( vn!=null )
491 493
                  {
492 494
                  time = noise(time,vecCurr);
493 495

  
494
                  baseV[1][0] = (3*tmp1.a[0]*time+2*tmp1.b[0])*time + tmp1.c[0];
495
                  baseV[1][1] = (3*tmp1.a[1]*time+2*tmp1.b[1])*time + tmp1.c[1];
496
                  baseV[1][0] = (3* tmpCache1.a[0]*time+2* tmpCache1.b[0])*time + tmpCache1.c[0];
497
                  baseV[1][1] = (3* tmpCache1.a[1]*time+2* tmpCache1.b[1])*time + tmpCache1.c[1];
496 498
                 
497
                  buffer[offset  ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0] +baseV[1][1]*mFactor[0];
498
                  buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1] -baseV[1][0]*mFactor[0];
499
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0] +baseV[1][1]*mFactor[0];
500
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1] -baseV[1][0]*mFactor[0];
499 501
                  } 
500 502
                else
501 503
                  {
502
                  buffer[offset  ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
503
                  buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1];
504
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0];
505
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1];
504 506
                  }
505 507
                
506 508
                break;

Also available in: Unified diff