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/Dynamic5D.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;
......
65 65
      
66 66
      if( q>1 )
67 67
        {
68
        tmp1.tangent[0] = nx+px/q;
69
        tmp1.tangent[1] = ny+py/q;
70
        tmp1.tangent[2] = nz+pz/q;
71
        tmp1.tangent[3] = nw+pw/q;
72
        tmp1.tangent[4] = nv+pv/q;
68
        tmpCache1.velocity[0] = nx+px/q;
69
        tmpCache1.velocity[1] = ny+py/q;
70
        tmpCache1.velocity[2] = nz+pz/q;
71
        tmpCache1.velocity[3] = nw+pw/q;
72
        tmpCache1.velocity[4] = nv+pv/q;
73 73
        }
74 74
      else
75 75
        {
76
        tmp1.tangent[0] = px+nx*q;
77
        tmp1.tangent[1] = py+ny*q;
78
        tmp1.tangent[2] = pz+nz*q;
79
        tmp1.tangent[3] = pw+nw*q;
80
        tmp1.tangent[4] = pv+nv*q;
76
        tmpCache1.velocity[0] = px+nx*q;
77
        tmpCache1.velocity[1] = py+ny*q;
78
        tmpCache1.velocity[2] = pz+nz*q;
79
        tmpCache1.velocity[3] = pw+nw*q;
80
        tmpCache1.velocity[4] = pv+nv*q;
81 81
        }
82 82
      }
83 83
    else
84 84
      {
85
      tmp1.tangent[0] = 0.0f;
86
      tmp1.tangent[1] = 0.0f;
87
      tmp1.tangent[2] = 0.0f;
88
      tmp1.tangent[3] = 0.0f;
89
      tmp1.tangent[4] = 0.0f;
85
      tmpCache1.velocity[0] = 0.0f;
86
      tmpCache1.velocity[1] = 0.0f;
87
      tmpCache1.velocity[2] = 0.0f;
88
      tmpCache1.velocity[3] = 0.0f;
89
      tmpCache1.velocity[4] = 0.0f;
90 90
      }
91 91
    }
92 92
    
......
96 96
    {  
97 97
    if( numPoints==1 )
98 98
      {
99
      tmp1= vc.elementAt(0);
99
      tmpCache1 = vc.elementAt(0);
100 100
      curr= vv.elementAt(0);
101 101
        
102
      tmp1.a[0] = tmp1.a[1] = tmp1.a[2] = tmp1.a[3] = tmp1.a[4] = 0.0f;
103
      tmp1.b[0] = tmp1.b[1] = tmp1.b[2] = tmp1.b[3] = tmp1.b[4] = 0.0f;
104
      tmp1.c[0] = curr.x;
105
      tmp1.c[1] = curr.y;
106
      tmp1.c[2] = curr.z;
107
      tmp1.c[3] = curr.w;
108
      tmp1.c[4] = curr.v;
109
      tmp1.d[0] = tmp1.d[1] = tmp1.d[2] = tmp1.d[3] = tmp1.d[4] = 0.0f;
102
      tmpCache1.a[0] = tmpCache1.a[1] = tmpCache1.a[2] = tmpCache1.a[3] = tmpCache1.a[4] = 0.0f;
103
      tmpCache1.b[0] = tmpCache1.b[1] = tmpCache1.b[2] = tmpCache1.b[3] = tmpCache1.b[4] = 0.0f;
104
      tmpCache1.c[0] = curr.x;
105
      tmpCache1.c[1] = curr.y;
106
      tmpCache1.c[2] = curr.z;
107
      tmpCache1.c[3] = curr.w;
108
      tmpCache1.c[4] = curr.v;
109
      tmpCache1.d[0] = tmpCache1.d[1] = tmpCache1.d[2] = tmpCache1.d[3] = tmpCache1.d[4] = 0.0f;
110 110
      }
111 111
    else if( numPoints==2 )
112 112
      {
113
      tmp1= vc.elementAt(0);
114
      tmp2= vc.elementAt(1);
113
      tmpCache1 = vc.elementAt(0);
114
      tmpCache2 = vc.elementAt(1);
115 115
      curr= vv.elementAt(0);
116 116
      next= vv.elementAt(1);
117 117
      
118
      tmp1.a[0] = tmp1.a[1] = tmp1.a[2] = tmp1.a[3] = tmp1.a[4] = 0.0f;
119
      tmp1.b[0] = tmp1.b[1] = tmp1.b[2] = tmp1.b[3] = tmp1.b[4] = 0.0f;
120
      tmp1.c[0] = next.x - curr.x;
121
      tmp1.c[1] = next.y - curr.y;
122
      tmp1.c[2] = next.z - curr.z;
123
      tmp1.c[3] = next.w - curr.w;
124
      tmp1.c[4] = next.v - curr.v;
125
      tmp1.d[0] = curr.x;
126
      tmp1.d[1] = curr.y;
127
      tmp1.d[2] = curr.z;
128
      tmp1.d[3] = curr.w;
129
      tmp1.d[4] = curr.v;
118
      tmpCache1.a[0] = tmpCache1.a[1] = tmpCache1.a[2] = tmpCache1.a[3] = tmpCache1.a[4] = 0.0f;
119
      tmpCache1.b[0] = tmpCache1.b[1] = tmpCache1.b[2] = tmpCache1.b[3] = tmpCache1.b[4] = 0.0f;
120
      tmpCache1.c[0] = next.x - curr.x;
121
      tmpCache1.c[1] = next.y - curr.y;
122
      tmpCache1.c[2] = next.z - curr.z;
123
      tmpCache1.c[3] = next.w - curr.w;
124
      tmpCache1.c[4] = next.v - curr.v;
125
      tmpCache1.d[0] = curr.x;
126
      tmpCache1.d[1] = curr.y;
127
      tmpCache1.d[2] = curr.z;
128
      tmpCache1.d[3] = curr.w;
129
      tmpCache1.d[4] = curr.v;
130 130
      
131
      tmp2.a[0] = tmp2.a[1] = tmp2.a[2] = tmp2.a[3] = tmp2.a[4] = 0.0f;
132
      tmp2.b[0] = tmp2.b[1] = tmp2.b[2] = tmp2.b[3] = tmp2.b[4] = 0.0f;
133
      tmp2.c[0] = curr.x - next.x;
134
      tmp2.c[1] = curr.y - next.y;
135
      tmp2.c[2] = curr.z - next.z;
136
      tmp2.c[3] = curr.w - next.w;
137
      tmp2.c[4] = curr.v - next.v;
138
      tmp2.d[0] = next.x;
139
      tmp2.d[1] = next.y;
140
      tmp2.d[2] = next.z;
141
      tmp2.d[3] = next.w;
142
      tmp2.d[4] = next.v;
131
      tmpCache2.a[0] = tmpCache2.a[1] = tmpCache2.a[2] = tmpCache2.a[3] = tmpCache2.a[4] = 0.0f;
132
      tmpCache2.b[0] = tmpCache2.b[1] = tmpCache2.b[2] = tmpCache2.b[3] = tmpCache2.b[4] = 0.0f;
133
      tmpCache2.c[0] = curr.x - next.x;
134
      tmpCache2.c[1] = curr.y - next.y;
135
      tmpCache2.c[2] = curr.z - next.z;
136
      tmpCache2.c[3] = curr.w - next.w;
137
      tmpCache2.c[4] = curr.v - next.v;
138
      tmpCache2.d[0] = next.x;
139
      tmpCache2.d[1] = next.y;
140
      tmpCache2.d[2] = next.z;
141
      tmpCache2.d[3] = next.w;
142
      tmpCache2.d[4] = next.v;
143 143
      }
144 144
    else
145 145
      {
......
151 151
        {
152 152
        n = i<numPoints-1 ? i+1:0;  
153 153
      
154
        tmp1= vc.elementAt(i);
155
        tmp2= vc.elementAt(n);
154
        tmpCache1 = vc.elementAt(i);
155
        tmpCache2 = vc.elementAt(n);
156 156
        curr= vv.elementAt(i);
157 157
        next= vv.elementAt(n);
158 158
      
159
        tmp1.cached[0] = curr.x;
160
        tmp1.cached[1] = curr.y;
161
        tmp1.cached[2] = curr.z;
162
        tmp1.cached[3] = curr.w;
163
        tmp1.cached[4] = curr.v;
159
        tmpCache1.cached[0] = curr.x;
160
        tmpCache1.cached[1] = curr.y;
161
        tmpCache1.cached[2] = curr.z;
162
        tmpCache1.cached[3] = curr.w;
163
        tmpCache1.cached[4] = curr.v;
164 164
        
165
        tmp1.a[0] = mConvexity*( 2*curr.x +   tmp1.tangent[0] - 2*next.x + tmp2.tangent[0]);
166
        tmp1.b[0] = mConvexity*(-3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0]);
167
        tmp1.c[0] = mConvexity*(tmp1.tangent[0]) + (1.0f-mConvexity)*(next.x-curr.x);
168
        tmp1.d[0] = curr.x;
165
        tmpCache1.a[0] = mConvexity*( 2*curr.x +   tmpCache1.velocity[0] - 2*next.x + tmpCache2.velocity[0]);
166
        tmpCache1.b[0] = mConvexity*(-3*curr.x - 2* tmpCache1.velocity[0] + 3*next.x - tmpCache2.velocity[0]);
167
        tmpCache1.c[0] = mConvexity*(tmpCache1.velocity[0]) + (1.0f-mConvexity)*(next.x-curr.x);
168
        tmpCache1.d[0] = curr.x;
169 169
      
170
        tmp1.a[1] = mConvexity*( 2*curr.y +   tmp1.tangent[1] - 2*next.y + tmp2.tangent[1]);
171
        tmp1.b[1] = mConvexity*(-3*curr.y - 2*tmp1.tangent[1] + 3*next.y - tmp2.tangent[1]);
172
        tmp1.c[1] = mConvexity*(tmp1.tangent[1]) + (1.0f-mConvexity)*(next.y-curr.y);
173
        tmp1.d[1] = curr.y;
170
        tmpCache1.a[1] = mConvexity*( 2*curr.y +   tmpCache1.velocity[1] - 2*next.y + tmpCache2.velocity[1]);
171
        tmpCache1.b[1] = mConvexity*(-3*curr.y - 2* tmpCache1.velocity[1] + 3*next.y - tmpCache2.velocity[1]);
172
        tmpCache1.c[1] = mConvexity*(tmpCache1.velocity[1]) + (1.0f-mConvexity)*(next.y-curr.y);
173
        tmpCache1.d[1] = curr.y;
174 174
      
175
        tmp1.a[2] = mConvexity*( 2*curr.z +   tmp1.tangent[2] - 2*next.z + tmp2.tangent[2]);
176
        tmp1.b[2] = mConvexity*(-3*curr.z - 2*tmp1.tangent[2] + 3*next.z - tmp2.tangent[2]);
177
        tmp1.c[2] = mConvexity*(tmp1.tangent[2]) + (1.0f-mConvexity)*(next.z-curr.z);
178
        tmp1.d[2] = curr.z;
175
        tmpCache1.a[2] = mConvexity*( 2*curr.z +   tmpCache1.velocity[2] - 2*next.z + tmpCache2.velocity[2]);
176
        tmpCache1.b[2] = mConvexity*(-3*curr.z - 2* tmpCache1.velocity[2] + 3*next.z - tmpCache2.velocity[2]);
177
        tmpCache1.c[2] = mConvexity*(tmpCache1.velocity[2]) + (1.0f-mConvexity)*(next.z-curr.z);
178
        tmpCache1.d[2] = curr.z;
179 179
        
180
        tmp1.a[3] = mConvexity*( 2*curr.w +   tmp1.tangent[3] - 2*next.w + tmp2.tangent[3]);
181
        tmp1.b[3] = mConvexity*(-3*curr.w - 2*tmp1.tangent[3] + 3*next.w - tmp2.tangent[3]);
182
        tmp1.c[3] = mConvexity*(tmp1.tangent[3]) + (1.0f-mConvexity)*(next.w-curr.w);
183
        tmp1.d[3] = curr.w;
180
        tmpCache1.a[3] = mConvexity*( 2*curr.w +   tmpCache1.velocity[3] - 2*next.w + tmpCache2.velocity[3]);
181
        tmpCache1.b[3] = mConvexity*(-3*curr.w - 2* tmpCache1.velocity[3] + 3*next.w - tmpCache2.velocity[3]);
182
        tmpCache1.c[3] = mConvexity*(tmpCache1.velocity[3]) + (1.0f-mConvexity)*(next.w-curr.w);
183
        tmpCache1.d[3] = curr.w;
184 184
        
185
        tmp1.a[4] = mConvexity*( 2*curr.v +   tmp1.tangent[4] - 2*next.v + tmp2.tangent[4]);
186
        tmp1.b[4] = mConvexity*(-3*curr.v - 2*tmp1.tangent[4] + 3*next.v - tmp2.tangent[4]);
187
        tmp1.c[4] = mConvexity*(tmp1.tangent[4]) + (1.0f-mConvexity)*(next.v-curr.v);
188
        tmp1.d[4] = curr.v;
185
        tmpCache1.a[4] = mConvexity*( 2*curr.v +   tmpCache1.velocity[4] - 2*next.v + tmpCache2.velocity[4]);
186
        tmpCache1.b[4] = mConvexity*(-3*curr.v - 2* tmpCache1.velocity[4] + 3*next.v - tmpCache2.velocity[4]);
187
        tmpCache1.c[4] = mConvexity*(tmpCache1.velocity[4]) + (1.0f-mConvexity)*(next.v-curr.v);
188
        tmpCache1.d[4] = curr.v;
189

  
190
        if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) smoothOutSegment(tmpCache1);
189 191
        }
190 192
      }
191 193
   
......
545 547
                  {
546 548
                  int vecNext= getNext(vecCurr,t);
547 549
                  next = vv.elementAt(vecNext);
548
                  tmp2 = vc.elementAt(vecNext);
550
                  tmpCache2 = vc.elementAt(vecNext);
549 551

  
550
                  if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y || tmp2.cached[2]!=next.z || tmp2.cached[3]!=next.w || tmp2.cached[4]!=next.v ) recomputeCache();
552
                  if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y || tmpCache2.cached[2]!=next.z || tmpCache2.cached[3]!=next.w || tmpCache2.cached[4]!=next.v ) recomputeCache();
551 553
                  }
552 554

  
553 555
                if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise();
554 556

  
555 557
                mSegment = segment;
556

  
557 558
                time = time-vecCurr;
558
            
559
                tmp1 = vc.elementAt(vecCurr);
560
               
559
                tmpCache1 = vc.elementAt(vecCurr);
560
                if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
561

  
561 562
                if( vn!=null )
562 563
                  {
563 564
                  time = noise(time,vecCurr);
564 565
              
565
                  computeOrthonormalBaseMore(time,tmp1);
566
                  computeOrthonormalBaseMore(time, tmpCache1);
566 567

  
567
                  buffer[offset  ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0] + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2] + baseV[4][0]*mFactor[3]);
568
                  buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1] + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1] + baseV[3][1]*mFactor[2] + baseV[4][1]*mFactor[3]);
569
                  buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2] + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1] + baseV[3][2]*mFactor[2] + baseV[4][2]*mFactor[3]);
570
                  buffer[offset+3]= ((tmp1.a[3]*time+tmp1.b[3])*time+tmp1.c[3])*time+tmp1.d[3] + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2] + baseV[4][3]*mFactor[3]);
571
                  buffer[offset+4]= ((tmp1.a[4]*time+tmp1.b[4])*time+tmp1.c[4])*time+tmp1.d[4] + (baseV[1][4]*mFactor[0] + baseV[2][4]*mFactor[1] + baseV[3][4]*mFactor[2] + baseV[4][4]*mFactor[3]);
568
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0] + (baseV[1][0]*mFactor[0] + baseV[2][0]*mFactor[1] + baseV[3][0]*mFactor[2] + baseV[4][0]*mFactor[3]);
569
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1] + (baseV[1][1]*mFactor[0] + baseV[2][1]*mFactor[1] + baseV[3][1]*mFactor[2] + baseV[4][1]*mFactor[3]);
570
                  buffer[offset+2]= ((tmpCache1.a[2]*time+ tmpCache1.b[2])*time+ tmpCache1.c[2])*time+ tmpCache1.d[2] + (baseV[1][2]*mFactor[0] + baseV[2][2]*mFactor[1] + baseV[3][2]*mFactor[2] + baseV[4][2]*mFactor[3]);
571
                  buffer[offset+3]= ((tmpCache1.a[3]*time+ tmpCache1.b[3])*time+ tmpCache1.c[3])*time+ tmpCache1.d[3] + (baseV[1][3]*mFactor[0] + baseV[2][3]*mFactor[1] + baseV[3][3]*mFactor[2] + baseV[4][3]*mFactor[3]);
572
                  buffer[offset+4]= ((tmpCache1.a[4]*time+ tmpCache1.b[4])*time+ tmpCache1.c[4])*time+ tmpCache1.d[4] + (baseV[1][4]*mFactor[0] + baseV[2][4]*mFactor[1] + baseV[3][4]*mFactor[2] + baseV[4][4]*mFactor[3]);
572 573
                  }
573 574
                else
574 575
                  {
575
                  buffer[offset  ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
576
                  buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1];
577
                  buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2];
578
                  buffer[offset+3]= ((tmp1.a[3]*time+tmp1.b[3])*time+tmp1.c[3])*time+tmp1.d[3];
579
                  buffer[offset+4]= ((tmp1.a[4]*time+tmp1.b[4])*time+tmp1.c[4])*time+tmp1.d[4];
576
                  buffer[offset  ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0];
577
                  buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1];
578
                  buffer[offset+2]= ((tmpCache1.a[2]*time+ tmpCache1.b[2])*time+ tmpCache1.c[2])*time+ tmpCache1.d[2];
579
                  buffer[offset+3]= ((tmpCache1.a[3]*time+ tmpCache1.b[3])*time+ tmpCache1.c[3])*time+ tmpCache1.d[3];
580
                  buffer[offset+4]= ((tmpCache1.a[4]*time+ tmpCache1.b[4])*time+ tmpCache1.c[4])*time+ tmpCache1.d[4];
580 581
                  }
581 582
 
582 583
                break;

Also available in: Unified diff