Revision 3002bef3
Added by Leszek Koltunski about 9 years ago
| src/main/java/org/distorted/library/type/Dynamic1D.java | ||
|---|---|---|
| 43 | 43 |
float x; |
| 44 | 44 |
float vx; |
| 45 | 45 |
} |
| 46 |
|
|
| 47 |
private class VectorNoise |
|
| 48 |
{
|
|
| 49 |
float[] nx; |
|
| 50 |
|
|
| 51 |
VectorNoise() |
|
| 52 |
{
|
|
| 53 |
nx = new float[NUM_NOISE]; |
|
| 54 |
nx[0] = mRnd.nextFloat(); |
|
| 55 |
for(int i=1; i<NUM_NOISE; i++) nx[i] = nx[i-1]+mRnd.nextFloat(); |
|
| 56 |
float sum = nx[NUM_NOISE-1] + mRnd.nextFloat(); |
|
| 57 |
for(int i=0; i<NUM_NOISE; i++) nx[i] /=sum; |
|
| 58 |
} |
|
| 59 |
} |
|
| 60 |
|
|
| 46 |
|
|
| 61 | 47 |
private Vector<VectorCache> vc; |
| 62 | 48 |
private VectorCache tmp1, tmp2; |
| 63 | 49 |
|
| 64 | 50 |
private Vector<Static1D> vv; |
| 65 | 51 |
private Static1D prev, curr, next; |
| 66 |
|
|
| 67 |
private Vector<VectorNoise> vn; |
|
| 68 |
private VectorNoise tmpN; |
|
| 69 |
|
|
| 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 71 | 52 |
|
| 72 |
synchronized void createNoise() |
|
| 73 |
{
|
|
| 74 |
if( vn==null ) |
|
| 75 |
{
|
|
| 76 |
vn = new Vector<>(); |
|
| 77 |
for(int i=0; i<numPoints; i++) vn.add(new VectorNoise()); |
|
| 78 |
} |
|
| 79 |
} |
|
| 80 |
|
|
| 81 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 82 | 54 |
// no array bounds checking! |
| 83 | 55 |
|
| ... | ... | |
| 173 | 145 |
|
| 174 | 146 |
cacheDirty = false; |
| 175 | 147 |
} |
| 176 |
|
|
| 177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 178 | 148 |
|
| 179 |
private float noise(float time,int vecNum) |
|
| 180 |
{
|
|
| 181 |
float lower, upper, len; |
|
| 182 |
float d = time*(NUM_NOISE+1); |
|
| 183 |
int index = (int)d; |
|
| 184 |
if( index>=NUM_NOISE+1 ) index=NUM_NOISE; |
|
| 185 |
tmpN = vn.elementAt(vecNum); |
|
| 186 |
|
|
| 187 |
if( index==0 ) |
|
| 188 |
{
|
|
| 189 |
len = 1.0f/(NUM_NOISE+1); |
|
| 190 |
return (len + mNoise*(tmpN.nx[0]-len))*d; |
|
| 191 |
} |
|
| 192 |
if( index==NUM_NOISE ) |
|
| 193 |
{
|
|
| 194 |
len = ((float)NUM_NOISE)/(NUM_NOISE+1); |
|
| 195 |
lower = len + mNoise*(tmpN.nx[NUM_NOISE-1]-len); |
|
| 196 |
return (1.0f-lower)*(d-NUM_NOISE) + lower; |
|
| 197 |
} |
|
| 198 |
|
|
| 199 |
len = ((float)index)/(NUM_NOISE+1); |
|
| 200 |
lower = len + mNoise*(tmpN.nx[index-1]-len); |
|
| 201 |
len = ((float)index+1)/(NUM_NOISE+1); |
|
| 202 |
upper = len + mNoise*(tmpN.nx[index ]-len); |
|
| 203 |
|
|
| 204 |
return (upper-lower)*(d-index) + lower; |
|
| 205 |
} |
|
| 206 |
|
|
| 207 | 149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 208 | 150 |
// PUBLIC API |
| 209 | 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 212 | 154 |
*/ |
| 213 | 155 |
public Dynamic1D() |
| 214 | 156 |
{
|
| 215 |
vv = new Vector<>(); |
|
| 216 |
vc = new Vector<>(); |
|
| 217 |
vn = null; |
|
| 218 |
numPoints = 0; |
|
| 219 |
cacheDirty = false; |
|
| 220 |
mMode = MODE_LOOP; |
|
| 221 |
mDuration = 0; |
|
| 222 |
mCount = 0.5f; |
|
| 157 |
this(0,0.5f); |
|
| 223 | 158 |
} |
| 224 | 159 |
|
| 225 | 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 242 | 177 |
mMode = MODE_LOOP; |
| 243 | 178 |
mDuration = duration; |
| 244 | 179 |
mCount = count; |
| 180 |
mDimension = 1; |
|
| 245 | 181 |
} |
| 246 | 182 |
|
| 247 | 183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 295 | 231 |
{
|
| 296 | 232 |
vv.add(v); |
| 297 | 233 |
|
| 298 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
| 234 |
if( vn!=null ) vn.add(new VectorNoise(1));
|
|
| 299 | 235 |
|
| 300 | 236 |
switch(numPoints) |
| 301 | 237 |
{
|
| ... | ... | |
| 327 | 263 |
{
|
| 328 | 264 |
vv.add(location, v); |
| 329 | 265 |
|
| 330 |
if( vn!=null ) vn.add(new VectorNoise()); |
|
| 266 |
if( vn!=null ) vn.add(new VectorNoise(1));
|
|
| 331 | 267 |
|
| 332 | 268 |
switch(numPoints) |
| 333 | 269 |
{
|
Also available in: Unified diff
Move most of the NOISE complications from DynamicND classes to the parent Dynamic class.