Revision 649544b8
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/type/Dynamic1D.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
public class Dynamic1D extends Dynamic implements Data1D |
31 | 31 |
{ |
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
// the coefficients of the X(t) polynomials: X(t) = ax*T^3 + bx*T^2 + cx*t + dx etc. |
|
35 |
// (x) is the vector tangent to the path. |
|
36 |
// (vx) 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 |
|
|
43 |
float x; |
|
44 |
float vx; |
|
45 |
} |
|
46 |
|
|
47 |
private Vector<VectorCache> vc; |
|
48 |
private VectorCache tmp1, tmp2; |
|
49 |
|
|
50 | 32 |
private Vector<Static1D> vv; |
51 | 33 |
private Static1D prev, curr, next; |
52 | 34 |
|
... | ... | |
75 | 57 |
|
76 | 58 |
if( q>1 ) |
77 | 59 |
{ |
78 |
tmp1.x = nx+px/q;
|
|
60 |
tmp1.tangent[0] = nx+px/q;
|
|
79 | 61 |
} |
80 | 62 |
else |
81 | 63 |
{ |
82 |
tmp1.x = px+nx*q;
|
|
64 |
tmp1.tangent[0] = px+nx*q;
|
|
83 | 65 |
} |
84 | 66 |
} |
85 | 67 |
else |
86 | 68 |
{ |
87 |
tmp1.x = 0.0f;
|
|
69 |
tmp1.tangent[0] = 0.0f;
|
|
88 | 70 |
} |
89 | 71 |
} |
90 | 72 |
|
... | ... | |
97 | 79 |
tmp1= vc.elementAt(0); |
98 | 80 |
curr= vv.elementAt(0); |
99 | 81 |
|
100 |
tmp1.ax = 0.0f;
|
|
101 |
tmp1.bx = 0.0f;
|
|
102 |
tmp1.cx = curr.x;
|
|
103 |
tmp1.dx = 0.0f;
|
|
82 |
tmp1.a[0] = 0.0f;
|
|
83 |
tmp1.b[0] = 0.0f;
|
|
84 |
tmp1.c[0] = curr.x;
|
|
85 |
tmp1.d[0] = 0.0f;
|
|
104 | 86 |
} |
105 | 87 |
else if( numPoints==2 ) |
106 | 88 |
{ |
... | ... | |
109 | 91 |
curr= vv.elementAt(0); |
110 | 92 |
next= vv.elementAt(1); |
111 | 93 |
|
112 |
tmp1.ax = 0.0f;
|
|
113 |
tmp1.bx = 0.0f;
|
|
114 |
tmp1.cx = next.x - curr.x;
|
|
115 |
tmp1.dx = curr.x;
|
|
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;
|
|
116 | 98 |
|
117 |
tmp2.ax = 0.0f;
|
|
118 |
tmp2.bx = 0.0f;
|
|
119 |
tmp2.cx = curr.x - next.x;
|
|
120 |
tmp2.dx = next.x;
|
|
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;
|
|
121 | 103 |
} |
122 | 104 |
else |
123 | 105 |
{ |
... | ... | |
134 | 116 |
curr= vv.elementAt(i); |
135 | 117 |
next= vv.elementAt(n); |
136 | 118 |
|
137 |
tmp1.vx = curr.x;
|
|
119 |
tmp1.cached[0] = curr.x;
|
|
138 | 120 |
|
139 |
tmp1.ax = 2*curr.x + tmp1.x - 2*next.x + tmp2.x;
|
|
140 |
tmp1.bx = -3*curr.x - 2*tmp1.x + 3*next.x - tmp2.x;
|
|
141 |
tmp1.cx = tmp1.x;
|
|
142 |
tmp1.dx = curr.x;
|
|
121 |
tmp1.a[0] = 2*curr.x + tmp1.tangent[0] - 2*next.x + tmp2.tangent[0];
|
|
122 |
tmp1.b[0] = -3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0];
|
|
123 |
tmp1.c[0] = tmp1.tangent[0];
|
|
124 |
tmp1.d[0] = curr.x;
|
|
143 | 125 |
} |
144 | 126 |
} |
145 | 127 |
|
... | ... | |
154 | 136 |
*/ |
155 | 137 |
public Dynamic1D() |
156 | 138 |
{ |
157 |
this(0,0.5f); |
|
139 |
super(0,0.5f,1); |
|
140 |
vv = new Vector<>(); |
|
158 | 141 |
} |
159 | 142 |
|
160 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
169 | 152 |
*/ |
170 | 153 |
public Dynamic1D(int duration, float count) |
171 | 154 |
{ |
155 |
super(duration,count,1); |
|
172 | 156 |
vv = new Vector<>(); |
173 |
vc = new Vector<>(); |
|
174 |
vn = null; |
|
175 |
numPoints = 0; |
|
176 |
cacheDirty = false; |
|
177 |
mMode = MODE_LOOP; |
|
178 |
mDuration = duration; |
|
179 |
mCount = count; |
|
180 |
mDimension = 1; |
|
181 | 157 |
} |
182 | 158 |
|
183 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
237 | 213 |
{ |
238 | 214 |
case 0: |
239 | 215 |
case 1: break; |
240 |
case 2: vc.add(new VectorCache()); |
|
241 |
vc.add(new VectorCache()); |
|
242 |
vc.add(new VectorCache()); |
|
216 |
case 2: vc.add(new VectorCache(1));
|
|
217 |
vc.add(new VectorCache(1));
|
|
218 |
vc.add(new VectorCache(1));
|
|
243 | 219 |
cacheDirty = true; |
244 | 220 |
break; |
245 |
default:vc.add(new VectorCache()); |
|
221 |
default:vc.add(new VectorCache(1));
|
|
246 | 222 |
cacheDirty = true; |
247 | 223 |
} |
248 | 224 |
|
... | ... | |
269 | 245 |
{ |
270 | 246 |
case 0: |
271 | 247 |
case 1: break; |
272 |
case 2: vc.add(new VectorCache()); |
|
273 |
vc.add(new VectorCache()); |
|
274 |
vc.add(new VectorCache()); |
|
248 |
case 2: vc.add(new VectorCache(1));
|
|
249 |
vc.add(new VectorCache(1));
|
|
250 |
vc.add(new VectorCache(1));
|
|
275 | 251 |
cacheDirty = true; |
276 | 252 |
break; |
277 |
default:vc.add(location,new VectorCache()); |
|
253 |
default:vc.add(location,new VectorCache(1));
|
|
278 | 254 |
cacheDirty = true; |
279 | 255 |
} |
280 | 256 |
|
... | ... | |
437 | 413 |
next = vv.elementAt(vecNext); |
438 | 414 |
tmp2 = vc.elementAt(vecNext); |
439 | 415 |
|
440 |
if( tmp2.vx!=next.x ) recomputeCache();
|
|
416 |
if( tmp2.cached[0]!=next.x ) recomputeCache();
|
|
441 | 417 |
} |
442 | 418 |
|
443 | 419 |
if( vn!=null ) |
... | ... | |
446 | 422 |
} |
447 | 423 |
|
448 | 424 |
tmp1 = vc.elementAt(vecCurr); |
449 |
buffer[offset] = ((tmp1.ax*time+tmp1.bx)*time+tmp1.cx)*time+tmp1.dx;
|
|
425 |
buffer[offset] = ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
|
|
450 | 426 |
break; |
451 | 427 |
} |
452 | 428 |
} |
Also available in: Unified diff
Completely redesign Noise in the Dynamics and move all the complexity to the parent class.
something does not work with it now :)