Revision 649544b8
Added by Leszek Koltunski about 9 years ago
| src/main/java/org/distorted/library/type/Dynamic5D.java | ||
|---|---|---|
| 29 | 29 |
|
| 30 | 30 |
public class Dynamic5D extends Dynamic implements Data5D |
| 31 | 31 |
{
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
// the coefficients of the X(t), Y(t), Z(t), W(t), V(t) polynomials: X(t) = ax*T^3 + bx*T^2 + cx*t + dx etc. |
|
| 35 |
// (x,y,z,w,v) is the vector tangent to the path. |
|
| 36 |
// (vx,vy,vz,vw,vv) 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 |
float ay, by, cy, dy; |
|
| 43 |
float az, bz, cz, dz; |
|
| 44 |
float aw, bw, cw, dw; |
|
| 45 |
float av, bv, cv, dv; |
|
| 46 |
|
|
| 47 |
float x,y,z,w,v; |
|
| 48 |
float vx,vy,vz,vw,vv; |
|
| 49 |
} |
|
| 50 |
|
|
| 51 |
private Vector<VectorCache> vc; |
|
| 52 |
private VectorCache tmp1, tmp2; |
|
| 53 |
|
|
| 54 | 32 |
private Vector<Static5D> vv; |
| 55 | 33 |
private Static5D prev, curr, next; |
| 56 | 34 |
|
| 57 |
private float vec1X,vec1Y,vec1Z,vec1W,vec1V; // |
|
| 58 |
private float vec2X,vec2Y,vec2Z,vec2W,vec2V; // 4 base noise vectors. |
|
| 59 |
private float vec3X,vec3Y,vec3Z,vec3W,vec3V; // |
|
| 60 |
private float vec4X,vec4Y,vec4Z,vec4W,vec4V; // |
|
| 61 |
|
|
| 62 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 63 | 36 |
// no array bounds checking! |
| 64 | 37 |
|
| ... | ... | |
| 92 | 65 |
|
| 93 | 66 |
if( q>1 ) |
| 94 | 67 |
{
|
| 95 |
tmp1.x = nx+px/q;
|
|
| 96 |
tmp1.y = ny+py/q;
|
|
| 97 |
tmp1.z = nz+pz/q;
|
|
| 98 |
tmp1.w = nw+pw/q;
|
|
| 99 |
tmp1.v = nv+pv/q;
|
|
| 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;
|
|
| 100 | 73 |
} |
| 101 | 74 |
else |
| 102 | 75 |
{
|
| 103 |
tmp1.x = px+nx*q;
|
|
| 104 |
tmp1.y = py+ny*q;
|
|
| 105 |
tmp1.z = pz+nz*q;
|
|
| 106 |
tmp1.w = pw+nw*q;
|
|
| 107 |
tmp1.v = pv+nv*q;
|
|
| 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;
|
|
| 108 | 81 |
} |
| 109 | 82 |
} |
| 110 | 83 |
else |
| 111 | 84 |
{
|
| 112 |
tmp1.x = 0.0f;
|
|
| 113 |
tmp1.y = 0.0f;
|
|
| 114 |
tmp1.z = 0.0f;
|
|
| 115 |
tmp1.w = 0.0f;
|
|
| 116 |
tmp1.v = 0.0f;
|
|
| 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;
|
|
| 117 | 90 |
} |
| 118 | 91 |
} |
| 119 | 92 |
|
| ... | ... | |
| 126 | 99 |
tmp1= vc.elementAt(0); |
| 127 | 100 |
curr= vv.elementAt(0); |
| 128 | 101 |
|
| 129 |
tmp1.ax = tmp1.ay = tmp1.az = tmp1.aw = tmp1.av = 0.0f;
|
|
| 130 |
tmp1.bx = tmp1.by = tmp1.bz = tmp1.bw = tmp1.bv = 0.0f;
|
|
| 131 |
tmp1.cx = curr.x;
|
|
| 132 |
tmp1.cy = curr.y;
|
|
| 133 |
tmp1.cz = curr.z;
|
|
| 134 |
tmp1.cw = curr.w;
|
|
| 135 |
tmp1.cv = curr.v;
|
|
| 136 |
tmp1.dx = tmp1.dy = tmp1.dz = tmp1.dw = tmp1.dv = 0.0f;
|
|
| 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;
|
|
| 137 | 110 |
} |
| 138 | 111 |
else if( numPoints==2 ) |
| 139 | 112 |
{
|
| ... | ... | |
| 142 | 115 |
curr= vv.elementAt(0); |
| 143 | 116 |
next= vv.elementAt(1); |
| 144 | 117 |
|
| 145 |
tmp1.ax = tmp1.ay = tmp1.az = tmp1.aw = tmp1.av = 0.0f;
|
|
| 146 |
tmp1.bx = tmp1.by = tmp1.bz = tmp1.bw = tmp1.bv = 0.0f;
|
|
| 147 |
tmp1.cx = next.x - curr.x;
|
|
| 148 |
tmp1.cy = next.y - curr.y;
|
|
| 149 |
tmp1.cz = next.z - curr.z;
|
|
| 150 |
tmp1.cw = next.w - curr.w;
|
|
| 151 |
tmp1.cv = next.v - curr.v;
|
|
| 152 |
tmp1.dx = curr.x;
|
|
| 153 |
tmp1.dy = curr.y;
|
|
| 154 |
tmp1.dz = curr.z;
|
|
| 155 |
tmp1.dw = curr.w;
|
|
| 156 |
tmp1.dv = curr.v;
|
|
| 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;
|
|
| 157 | 130 |
|
| 158 |
tmp2.ax = tmp2.ay = tmp2.az = tmp2.aw = tmp2.av = 0.0f;
|
|
| 159 |
tmp2.bx = tmp2.by = tmp2.bz = tmp2.bw = tmp2.bv = 0.0f;
|
|
| 160 |
tmp2.cx = curr.x - next.x;
|
|
| 161 |
tmp2.cy = curr.y - next.y;
|
|
| 162 |
tmp2.cz = curr.z - next.z;
|
|
| 163 |
tmp2.cw = curr.w - next.w;
|
|
| 164 |
tmp2.cv = curr.v - next.v;
|
|
| 165 |
tmp2.dx = next.x;
|
|
| 166 |
tmp2.dy = next.y;
|
|
| 167 |
tmp2.dz = next.z;
|
|
| 168 |
tmp2.dw = next.w;
|
|
| 169 |
tmp2.dv = next.v;
|
|
| 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;
|
|
| 170 | 143 |
} |
| 171 | 144 |
else |
| 172 | 145 |
{
|
| ... | ... | |
| 183 | 156 |
curr= vv.elementAt(i); |
| 184 | 157 |
next= vv.elementAt(n); |
| 185 | 158 |
|
| 186 |
tmp1.vx = curr.x;
|
|
| 187 |
tmp1.vy = curr.y;
|
|
| 188 |
tmp1.vz = curr.z;
|
|
| 189 |
tmp1.vw = curr.w;
|
|
| 190 |
tmp1.vv = curr.v;
|
|
| 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;
|
|
| 191 | 164 |
|
| 192 |
tmp1.ax = 2*curr.x + tmp1.x - 2*next.x + tmp2.x;
|
|
| 193 |
tmp1.bx = -3*curr.x - 2*tmp1.x + 3*next.x - tmp2.x;
|
|
| 194 |
tmp1.cx = tmp1.x;
|
|
| 195 |
tmp1.dx = curr.x;
|
|
| 165 |
tmp1.a[0] = 2*curr.x + tmp1.tangent[0] - 2*next.x + tmp2.tangent[0];
|
|
| 166 |
tmp1.b[0] = -3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0];
|
|
| 167 |
tmp1.c[0] = tmp1.tangent[0];
|
|
| 168 |
tmp1.d[0] = curr.x;
|
|
| 196 | 169 |
|
| 197 |
tmp1.ay = 2*curr.y + tmp1.y - 2*next.y + tmp2.y;
|
|
| 198 |
tmp1.by = -3*curr.y - 2*tmp1.y + 3*next.y - tmp2.y;
|
|
| 199 |
tmp1.cy = tmp1.y;
|
|
| 200 |
tmp1.dy = curr.y;
|
|
| 170 |
tmp1.a[1] = 2*curr.y + tmp1.tangent[1] - 2*next.y + tmp2.tangent[1];
|
|
| 171 |
tmp1.b[1] = -3*curr.y - 2*tmp1.tangent[1] + 3*next.y - tmp2.tangent[1];
|
|
| 172 |
tmp1.c[1] = tmp1.tangent[1];
|
|
| 173 |
tmp1.d[1] = curr.y;
|
|
| 201 | 174 |
|
| 202 |
tmp1.az = 2*curr.z + tmp1.z - 2*next.z + tmp2.z;
|
|
| 203 |
tmp1.bz = -3*curr.z - 2*tmp1.z + 3*next.z - tmp2.z;
|
|
| 204 |
tmp1.cz = tmp1.z;
|
|
| 205 |
tmp1.dz = curr.z;
|
|
| 175 |
tmp1.a[2] = 2*curr.z + tmp1.tangent[2] - 2*next.z + tmp2.tangent[2];
|
|
| 176 |
tmp1.b[2] = -3*curr.z - 2*tmp1.tangent[2] + 3*next.z - tmp2.tangent[2];
|
|
| 177 |
tmp1.c[2] = tmp1.tangent[2];
|
|
| 178 |
tmp1.d[2] = curr.z;
|
|
| 206 | 179 |
|
| 207 |
tmp1.aw = 2*curr.w + tmp1.w - 2*next.w + tmp2.w;
|
|
| 208 |
tmp1.bw = -3*curr.w - 2*tmp1.w + 3*next.w - tmp2.w;
|
|
| 209 |
tmp1.cw = tmp1.w;
|
|
| 210 |
tmp1.dw = curr.w;
|
|
| 180 |
tmp1.a[3] = 2*curr.w + tmp1.tangent[3] - 2*next.w + tmp2.tangent[3];
|
|
| 181 |
tmp1.b[3] = -3*curr.w - 2*tmp1.tangent[3] + 3*next.w - tmp2.tangent[3];
|
|
| 182 |
tmp1.c[3] = tmp1.tangent[3];
|
|
| 183 |
tmp1.d[3] = curr.w;
|
|
| 211 | 184 |
|
| 212 |
tmp1.av = 2*curr.v + tmp1.v - 2*next.v + tmp2.v;
|
|
| 213 |
tmp1.bv = -3*curr.v - 2*tmp1.v + 3*next.v - tmp2.v;
|
|
| 214 |
tmp1.cv = tmp1.v;
|
|
| 215 |
tmp1.dv = curr.v;
|
|
| 185 |
tmp1.a[4] = 2*curr.v + tmp1.tangent[4] - 2*next.v + tmp2.tangent[4];
|
|
| 186 |
tmp1.b[4] = -3*curr.v - 2*tmp1.tangent[4] + 3*next.v - tmp2.tangent[4];
|
|
| 187 |
tmp1.c[4] = tmp1.tangent[4];
|
|
| 188 |
tmp1.d[4] = curr.v;
|
|
| 216 | 189 |
} |
| 217 | 190 |
} |
| 218 | 191 |
|
| 219 | 192 |
cacheDirty = false; |
| 220 | 193 |
} |
| 221 | 194 |
|
| 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 223 |
// v is the speed vector (i.e. position p(t) differentiated by time) |
|
| 224 |
// a is the acceleration vector (differentiate once more) |
|
| 225 |
// |
|
| 226 |
// Now we construct orthogonal basis with Gram-Schmidt: |
|
| 227 |
// |
|
| 228 |
// vec1 = a-delta*v |
|
| 229 |
// where delta = (v*a)/|v|^2 |
|
| 230 |
// vec2 = (0,0,1,0,0) - coeff1*(vx,vy,vz,vw,vv) - coeff2*(vec1x,vec1y,vec1z,vec1w,vec1v) |
|
| 231 |
// where coeff1 = vz/|v|^2, coeff2 = vec1Z/|vec1|^2 |
|
| 232 |
// vec3 = (0,0,0,1,0) - coeff1*(vx,vy,vz,vw,vv) - coeff2*(vec1x,vec1y,vec1z,vec1w,vec1v) - coeff3*(vec2x,vec2y,vec2z,vec2w,vec2v) |
|
| 233 |
// where coeff1 = vw/|v|^2, coeff2 = vec1W/|vec1|^2, coeff3 = vec2W/|vec2|^2 |
|
| 234 |
// vec4 = (0,0,0,0,1) - coeff1*(vx,vy,vz,vw,vv) - coeff2*(vec1x,vec1y,vec1z,vec1w,vec1v) - coeff3*(vec2x,vec2y,vec2z,vec2w,vec2v) - coeff4*(vec3x,vec3y,vec3z,vec3w,vec3v) |
|
| 235 |
// where coeff1 = vv/|v|^2, coeff2 = vec1V/|vec1|^2, coeff3 = vec2V/|vec2|^2, coeff4 = vec3V/|vec3|^2 |
|
| 236 |
// |
|
| 237 |
// this is going to fail if by chance v(t) happens to be one of the standard (0,...,1,...,0) vectors of the orthonormal base! |
|
| 238 |
|
|
| 239 |
private void setUpVectors(float time,VectorCache vc) |
|
| 240 |
{
|
|
| 241 |
if( vc!=null ) |
|
| 242 |
{
|
|
| 243 |
float vx = (3*vc.ax*time+2*vc.bx)*time+vc.cx; |
|
| 244 |
float vy = (3*vc.ay*time+2*vc.by)*time+vc.cy; |
|
| 245 |
float vz = (3*vc.az*time+2*vc.bz)*time+vc.cz; |
|
| 246 |
float vw = (3*vc.aw*time+2*vc.bw)*time+vc.cw; |
|
| 247 |
float vv = (3*vc.av*time+2*vc.bv)*time+vc.cv; |
|
| 248 |
|
|
| 249 |
float ax = 6*vc.ax*time+2*vc.bx; |
|
| 250 |
float ay = 6*vc.ay*time+2*vc.by; |
|
| 251 |
float az = 6*vc.az*time+2*vc.bz; |
|
| 252 |
float aw = 6*vc.aw*time+2*vc.bw; |
|
| 253 |
float av = 6*vc.av*time+2*vc.bv; |
|
| 254 |
|
|
| 255 |
float v_sq = vx*vx+vy*vy+vz*vz+vw*vw+vv*vv; |
|
| 256 |
float delta = (vx*ax+vy*ay+vz*az+vw*aw+vv*av)/v_sq; |
|
| 257 |
|
|
| 258 |
vec1X = ax-delta*vx; |
|
| 259 |
vec1Y = ay-delta*vy; |
|
| 260 |
vec1Z = az-delta*vz; |
|
| 261 |
vec1W = aw-delta*vw; |
|
| 262 |
vec1V = av-delta*vv; |
|
| 263 |
|
|
| 264 |
// construct vec2, vec3 and vec4. Cross product does not work in 5th dimension! |
|
| 265 |
float vec1_sq = vec1X*vec1X+vec1Y*vec1Y+vec1Z*vec1Z+vec1W*vec1W+vec1V*vec1V; |
|
| 266 |
float coeff21 = vz/v_sq; |
|
| 267 |
float coeff22 = vec1Z/vec1_sq; |
|
| 268 |
vec2X = 0.0f - coeff21*vx - coeff22*vec1X; |
|
| 269 |
vec2Y = 0.0f - coeff21*vy - coeff22*vec1Y; |
|
| 270 |
vec2Z = 1.0f - coeff21*vz - coeff22*vec1Z; |
|
| 271 |
vec2W = 0.0f - coeff21*vw - coeff22*vec1W; |
|
| 272 |
vec2V = 0.0f - coeff21*vv - coeff22*vec1V; |
|
| 273 |
|
|
| 274 |
float vec2_sq = vec2X*vec2X+vec2Y*vec2Y+vec2Z*vec2Z+vec2W*vec2W+vec2V*vec2V; |
|
| 275 |
float coeff31 = vw/v_sq; |
|
| 276 |
float coeff32 = vec1W/vec1_sq; |
|
| 277 |
float coeff33 = vec2W/vec2_sq; |
|
| 278 |
vec3X = 0.0f - coeff31*vx - coeff32*vec1X - coeff33*vec2X; |
|
| 279 |
vec3Y = 0.0f - coeff31*vy - coeff32*vec1Y - coeff33*vec2Y; |
|
| 280 |
vec3Z = 0.0f - coeff31*vz - coeff32*vec1Z - coeff33*vec2Z; |
|
| 281 |
vec3W = 1.0f - coeff31*vw - coeff32*vec1W - coeff33*vec2W; |
|
| 282 |
vec3V = 0.0f - coeff31*vv - coeff32*vec1V - coeff33*vec2V; |
|
| 283 |
|
|
| 284 |
float vec3_sq = vec3X*vec3X+vec3Y*vec3Y+vec3Z*vec3Z+vec3W*vec3W+vec3V*vec3V; |
|
| 285 |
float coeff41 = vv/v_sq; |
|
| 286 |
float coeff42 = vec1V/vec1_sq; |
|
| 287 |
float coeff43 = vec2V/vec2_sq; |
|
| 288 |
float coeff44 = vec3V/vec3_sq; |
|
| 289 |
vec4X = 0.0f - coeff41*vx - coeff42*vec1X - coeff43*vec2X - coeff44*vec3X; |
|
| 290 |
vec4Y = 0.0f - coeff41*vy - coeff42*vec1Y - coeff43*vec2Y - coeff44*vec3Y; |
|
| 291 |
vec4Z = 0.0f - coeff41*vz - coeff42*vec1Z - coeff43*vec2Z - coeff44*vec3Z; |
|
| 292 |
vec4W = 0.0f - coeff41*vw - coeff42*vec1W - coeff43*vec2W - coeff44*vec3W; |
|
| 293 |
vec4V = 1.0f - coeff41*vv - coeff42*vec1V - coeff43*vec2V - coeff44*vec3V; |
|
| 294 |
|
|
| 295 |
float vec4_sq = vec4X*vec4X+vec4Y*vec4Y+vec4Z*vec4Z+vec4W*vec4W+vec4V*vec4V; |
|
| 296 |
|
|
| 297 |
float len1 = (float)Math.sqrt(v_sq/vec1_sq); |
|
| 298 |
float len2 = (float)Math.sqrt(v_sq/vec2_sq); |
|
| 299 |
float len3 = (float)Math.sqrt(v_sq/vec3_sq); |
|
| 300 |
float len4 = (float)Math.sqrt(v_sq/vec4_sq); |
|
| 301 |
|
|
| 302 |
vec1X*=len1; |
|
| 303 |
vec1Y*=len1; |
|
| 304 |
vec1Z*=len1; |
|
| 305 |
vec1W*=len1; |
|
| 306 |
vec1V*=len1; |
|
| 307 |
|
|
| 308 |
vec2X*=len2; |
|
| 309 |
vec2Y*=len2; |
|
| 310 |
vec2Z*=len2; |
|
| 311 |
vec2W*=len2; |
|
| 312 |
vec2V*=len2; |
|
| 313 |
|
|
| 314 |
vec3X*=len3; |
|
| 315 |
vec3Y*=len3; |
|
| 316 |
vec3Z*=len3; |
|
| 317 |
vec3W*=len3; |
|
| 318 |
vec3V*=len3; |
|
| 319 |
|
|
| 320 |
vec4X*=len4; |
|
| 321 |
vec4Y*=len4; |
|
| 322 |
vec4Z*=len4; |
|
| 323 |
vec4W*=len4; |
|
| 324 |
vec4V*=len4; |
|
| 325 |
} |
|
| 326 |
else |
|
| 327 |
{
|
|
| 328 |
curr = vv.elementAt(0); |
|
| 329 |
next = vv.elementAt(1); |
|
| 330 |
|
|
| 331 |
float vx = (next.x-curr.x); |
|
| 332 |
float vy = (next.y-curr.y); |
|
| 333 |
float vz = (next.z-curr.z); |
|
| 334 |
float vw = (next.w-curr.w); |
|
| 335 |
float vv = (next.v-curr.v); |
|
| 336 |
|
|
| 337 |
float b = (float)Math.sqrt(vx*vx+vy*vy+vz*vz+vw*vw); |
|
| 338 |
|
|
| 339 |
if( b>0.0f ) |
|
| 340 |
{
|
|
| 341 |
vec1X = vx*vv/b; |
|
| 342 |
vec1Y = vy*vv/b; |
|
| 343 |
vec1Z = vz*vv/b; |
|
| 344 |
vec1W = vw*vv/b; |
|
| 345 |
vec1V = -b; |
|
| 346 |
|
|
| 347 |
float v_sq = vx*vx+vy*vy+vz*vz+vw*vw+vv*vv; |
|
| 348 |
|
|
| 349 |
// construct vec2, vec3 and vec4. Cross product does not work in 5th dimension! |
|
| 350 |
float vec1_sq = vec1X*vec1X+vec1Y*vec1Y+vec1Z*vec1Z+vec1W*vec1W+vec1V*vec1V; |
|
| 351 |
float coeff21 = vz/v_sq; |
|
| 352 |
float coeff22 = vec1Z/vec1_sq; |
|
| 353 |
vec2X = 0.0f - coeff21*vx - coeff22*vec1X; |
|
| 354 |
vec2Y = 0.0f - coeff21*vy - coeff22*vec1Y; |
|
| 355 |
vec2Z = 1.0f - coeff21*vz - coeff22*vec1Z; |
|
| 356 |
vec2W = 0.0f - coeff21*vw - coeff22*vec1W; |
|
| 357 |
vec2V = 0.0f - coeff21*vv - coeff22*vec1V; |
|
| 358 |
|
|
| 359 |
float vec2_sq = vec2X*vec2X+vec2Y*vec2Y+vec2Z*vec2Z+vec2W*vec2W+vec2V*vec2V; |
|
| 360 |
float coeff31 = vw/v_sq; |
|
| 361 |
float coeff32 = vec1W/vec1_sq; |
|
| 362 |
float coeff33 = vec2W/vec2_sq; |
|
| 363 |
vec3X = 0.0f - coeff31*vx - coeff32*vec1X - coeff33*vec2X; |
|
| 364 |
vec3Y = 0.0f - coeff31*vy - coeff32*vec1Y - coeff33*vec2Y; |
|
| 365 |
vec3Z = 0.0f - coeff31*vz - coeff32*vec1Z - coeff33*vec2Z; |
|
| 366 |
vec3W = 1.0f - coeff31*vw - coeff32*vec1W - coeff33*vec2W; |
|
| 367 |
vec3V = 0.0f - coeff31*vv - coeff32*vec1V - coeff33*vec2V; |
|
| 368 |
|
|
| 369 |
float vec3_sq = vec3X*vec3X+vec3Y*vec3Y+vec3Z*vec3Z+vec3W*vec3W+vec3V*vec3V; |
|
| 370 |
float coeff41 = vv/v_sq; |
|
| 371 |
float coeff42 = vec1V/vec1_sq; |
|
| 372 |
float coeff43 = vec2V/vec2_sq; |
|
| 373 |
float coeff44 = vec3V/vec3_sq; |
|
| 374 |
vec4X = 0.0f - coeff41*vx - coeff42*vec1X - coeff43*vec2X - coeff44*vec3X; |
|
| 375 |
vec4Y = 0.0f - coeff41*vy - coeff42*vec1Y - coeff43*vec2Y - coeff44*vec3Y; |
|
| 376 |
vec4Z = 0.0f - coeff41*vz - coeff42*vec1Z - coeff43*vec2Z - coeff44*vec3Z; |
|
| 377 |
vec4W = 0.0f - coeff41*vw - coeff42*vec1W - coeff43*vec2W - coeff44*vec3W; |
|
| 378 |
vec4V = 1.0f - coeff41*vv - coeff42*vec1V - coeff43*vec2V - coeff44*vec3V; |
|
| 379 |
|
|
| 380 |
float vec4_sq = vec4X*vec4X+vec4Y*vec4Y+vec4Z*vec4Z+vec4W*vec4W+vec4V*vec4V; |
|
| 381 |
|
|
| 382 |
float len1 = (float)Math.sqrt(v_sq/vec1_sq); |
|
| 383 |
float len2 = (float)Math.sqrt(v_sq/vec2_sq); |
|
| 384 |
float len3 = (float)Math.sqrt(v_sq/vec3_sq); |
|
| 385 |
float len4 = (float)Math.sqrt(v_sq/vec4_sq); |
|
| 386 |
|
|
| 387 |
vec1X*=len1; |
|
| 388 |
vec1Y*=len1; |
|
| 389 |
vec1Z*=len1; |
|
| 390 |
vec1W*=len1; |
|
| 391 |
vec1V*=len1; |
|
| 392 |
|
|
| 393 |
vec2X*=len2; |
|
| 394 |
vec2Y*=len2; |
|
| 395 |
vec2Z*=len2; |
|
| 396 |
vec2W*=len2; |
|
| 397 |
vec2V*=len2; |
|
| 398 |
|
|
| 399 |
vec3X*=len3; |
|
| 400 |
vec3Y*=len3; |
|
| 401 |
vec3Z*=len3; |
|
| 402 |
vec3W*=len3; |
|
| 403 |
vec3V*=len3; |
|
| 404 |
|
|
| 405 |
vec4X*=len4; |
|
| 406 |
vec4Y*=len4; |
|
| 407 |
vec4Z*=len4; |
|
| 408 |
vec4W*=len4; |
|
| 409 |
vec4V*=len4; |
|
| 410 |
} |
|
| 411 |
else |
|
| 412 |
{
|
|
| 413 |
vec1X = vv; |
|
| 414 |
vec1Y = 0.0f; |
|
| 415 |
vec1Z = 0.0f; |
|
| 416 |
vec1W = 0.0f; |
|
| 417 |
vec1V = 0.0f; |
|
| 418 |
|
|
| 419 |
vec2X = 0.0f; |
|
| 420 |
vec2Y = vv; |
|
| 421 |
vec2Z = 0.0f; |
|
| 422 |
vec2W = 0.0f; |
|
| 423 |
vec2V = 0.0f; |
|
| 424 |
|
|
| 425 |
vec3X = 0.0f; |
|
| 426 |
vec3Y = 0.0f; |
|
| 427 |
vec3Z = vv; |
|
| 428 |
vec3W = 0.0f; |
|
| 429 |
vec3V = 0.0f; |
|
| 430 |
|
|
| 431 |
vec4X = 0.0f; |
|
| 432 |
vec4Y = 0.0f; |
|
| 433 |
vec4Z = 0.0f; |
|
| 434 |
vec4W = vv; |
|
| 435 |
vec4V = 0.0f; |
|
| 436 |
} |
|
| 437 |
} |
|
| 438 |
} |
|
| 439 |
|
|
| 440 | 195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 441 | 196 |
// PUBLIC API |
| 442 | 197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 445 | 200 |
*/ |
| 446 | 201 |
public Dynamic5D() |
| 447 | 202 |
{
|
| 448 |
this(0,0.5f); |
|
| 203 |
super(0,0.5f,5); |
|
| 204 |
vv = new Vector<>(); |
|
| 449 | 205 |
} |
| 450 | 206 |
|
| 451 | 207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 460 | 216 |
*/ |
| 461 | 217 |
public Dynamic5D(int duration, float count) |
| 462 | 218 |
{
|
| 219 |
super(duration,count,5); |
|
| 463 | 220 |
vv = new Vector<>(); |
| 464 |
vc = new Vector<>(); |
|
| 465 |
vn = null; |
|
| 466 |
numPoints = 0; |
|
| 467 |
cacheDirty = false; |
|
| 468 |
mMode = MODE_LOOP; |
|
| 469 |
mDuration = duration; |
|
| 470 |
mCount = count; |
|
| 471 |
mDimension = 5; |
|
| 472 | 221 |
} |
| 473 | 222 |
|
| 474 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 527 | 276 |
switch(numPoints) |
| 528 | 277 |
{
|
| 529 | 278 |
case 0: break; |
| 530 |
case 1: setUpVectors(0.0f,null);
|
|
| 279 |
case 1: computeOrthonormalBase2(vv.elementAt(0),v);
|
|
| 531 | 280 |
break; |
| 532 |
case 2: vc.add(new VectorCache()); |
|
| 533 |
vc.add(new VectorCache()); |
|
| 534 |
vc.add(new VectorCache()); |
|
| 281 |
case 2: vc.add(new VectorCache(5));
|
|
| 282 |
vc.add(new VectorCache(5));
|
|
| 283 |
vc.add(new VectorCache(5));
|
|
| 535 | 284 |
break; |
| 536 |
default:vc.add(new VectorCache()); |
|
| 285 |
default:vc.add(new VectorCache(5));
|
|
| 537 | 286 |
} |
| 538 | 287 |
|
| 539 | 288 |
numPoints++; |
| ... | ... | |
| 559 | 308 |
switch(numPoints) |
| 560 | 309 |
{
|
| 561 | 310 |
case 0: break; |
| 562 |
case 1: setUpVectors(0.0f,null);
|
|
| 311 |
case 1: computeOrthonormalBase2(vv.elementAt(0),v);
|
|
| 563 | 312 |
break; |
| 564 |
case 2: vc.add(new VectorCache()); |
|
| 565 |
vc.add(new VectorCache()); |
|
| 566 |
vc.add(new VectorCache()); |
|
| 313 |
case 2: vc.add(new VectorCache(5));
|
|
| 314 |
vc.add(new VectorCache(5));
|
|
| 315 |
vc.add(new VectorCache(5));
|
|
| 567 | 316 |
break; |
| 568 |
default:vc.add(location,new VectorCache()); |
|
| 317 |
default:vc.add(location,new VectorCache(5));
|
|
| 569 | 318 |
} |
| 570 | 319 |
|
| 571 | 320 |
numPoints++; |
| ... | ... | |
| 597 | 346 |
case 1: |
| 598 | 347 |
case 2: break; |
| 599 | 348 |
case 3: vc.removeAllElements(); |
| 600 |
setUpVectors(0.0f,null);
|
|
| 349 |
computeOrthonormalBase2(vv.elementAt(0),vv.elementAt(1));
|
|
| 601 | 350 |
break; |
| 602 | 351 |
default:vc.remove(n); |
| 603 | 352 |
} |
| ... | ... | |
| 636 | 385 |
case 1: |
| 637 | 386 |
case 2: break; |
| 638 | 387 |
case 3: vc.removeAllElements(); |
| 639 |
setUpVectors(0.0f,null);
|
|
| 388 |
computeOrthonormalBase2(vv.elementAt(0),vv.elementAt(1));
|
|
| 640 | 389 |
break; |
| 641 | 390 |
default:vc.removeElementAt(location); |
| 642 | 391 |
} |
| ... | ... | |
| 700 | 449 |
if( vn!=null ) |
| 701 | 450 |
{
|
| 702 | 451 |
time = noise(time,0); |
| 703 |
|
|
| 704 |
buffer[offset ] = (next.x-curr.x)*time + curr.x + (vec1X*mFactor[0] + vec2X*mFactor[1] + vec3X*mFactor[2] + vec4X*mFactor[3]);
|
|
| 705 |
buffer[offset+1] = (next.y-curr.y)*time + curr.y + (vec1Y*mFactor[0] + vec2Y*mFactor[1] + vec3Y*mFactor[2] + vec4Y*mFactor[3]);
|
|
| 706 |
buffer[offset+2] = (next.z-curr.z)*time + curr.z + (vec1Z*mFactor[0] + vec2Z*mFactor[1] + vec3Z*mFactor[2] + vec4Z*mFactor[3]);
|
|
| 707 |
buffer[offset+3] = (next.w-curr.w)*time + curr.w + (vec1W*mFactor[0] + vec2W*mFactor[1] + vec3W*mFactor[2] + vec4W*mFactor[3]);
|
|
| 708 |
buffer[offset+4] = (next.v-curr.v)*time + curr.v + (vec1V*mFactor[0] + vec2V*mFactor[1] + vec3V*mFactor[2] + vec4V*mFactor[3]);
|
|
| 452 |
|
|
| 453 |
buffer[offset ] = (next.x-curr.x)*time + curr.x + (baseV[0][0]*mFactor[0] + baseV[1][0]*mFactor[1] + baseV[2][0]*mFactor[2] + baseV[3][0]*mFactor[3]);
|
|
| 454 |
buffer[offset+1] = (next.y-curr.y)*time + curr.y + (baseV[0][1]*mFactor[0] + baseV[1][1]*mFactor[1] + baseV[2][1]*mFactor[2] + baseV[3][1]*mFactor[3]);
|
|
| 455 |
buffer[offset+2] = (next.z-curr.z)*time + curr.z + (baseV[0][2]*mFactor[0] + baseV[1][2]*mFactor[1] + baseV[2][2]*mFactor[2] + baseV[3][2]*mFactor[3]);
|
|
| 456 |
buffer[offset+3] = (next.z-curr.z)*time + curr.z + (baseV[0][3]*mFactor[0] + baseV[1][3]*mFactor[1] + baseV[2][3]*mFactor[2] + baseV[3][3]*mFactor[3]);
|
|
| 457 |
buffer[offset+4] = (next.z-curr.z)*time + curr.z + (baseV[0][4]*mFactor[0] + baseV[1][4]*mFactor[1] + baseV[2][4]*mFactor[2] + baseV[3][4]*mFactor[3]);
|
|
| 709 | 458 |
} |
| 710 | 459 |
else |
| 711 | 460 |
{
|
| ... | ... | |
| 755 | 504 |
next = vv.elementAt(vecNext); |
| 756 | 505 |
tmp2 = vc.elementAt(vecNext); |
| 757 | 506 |
|
| 758 |
if( tmp2.vx!=next.x || tmp2.vy!=next.y || tmp2.vz!=next.z || tmp2.vw!=next.w || tmp2.vv!=next.v ) recomputeCache();
|
|
| 507 |
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();
|
|
| 759 | 508 |
} |
| 760 | 509 |
|
| 761 | 510 |
tmp1 = vc.elementAt(vecCurr); |
| ... | ... | |
| 764 | 513 |
{
|
| 765 | 514 |
time = noise(time,vecCurr); |
| 766 | 515 |
|
| 767 |
setUpVectors(time,tmp1);
|
|
| 768 |
|
|
| 769 |
buffer[offset ]= ((tmp1.ax*time+tmp1.bx)*time+tmp1.cx)*time+tmp1.dx + (vec1X*mFactor[0] + vec2X*mFactor[1] + vec3X*mFactor[2] + vec4X*mFactor[3]);
|
|
| 770 |
buffer[offset+1]= ((tmp1.ay*time+tmp1.by)*time+tmp1.cy)*time+tmp1.dy + (vec1Y*mFactor[0] + vec2Y*mFactor[1] + vec3Y*mFactor[2] + vec4Y*mFactor[3]);
|
|
| 771 |
buffer[offset+2]= ((tmp1.az*time+tmp1.bz)*time+tmp1.cz)*time+tmp1.dz + (vec1Z*mFactor[0] + vec2Z*mFactor[1] + vec3Z*mFactor[2] + vec4Z*mFactor[3]);
|
|
| 772 |
buffer[offset+3]= ((tmp1.aw*time+tmp1.bw)*time+tmp1.cw)*time+tmp1.dw + (vec1W*mFactor[0] + vec2W*mFactor[1] + vec3W*mFactor[2] + vec4W*mFactor[3]);
|
|
| 773 |
buffer[offset+4]= ((tmp1.av*time+tmp1.bv)*time+tmp1.cv)*time+tmp1.dv + (vec1V*mFactor[0] + vec2V*mFactor[1] + vec3V*mFactor[2] + vec4V*mFactor[3]);
|
|
| 516 |
computeOrthonormalBaseMore(time,tmp1);
|
|
| 517 |
|
|
| 518 |
buffer[offset ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0] + (baseV[0][0]*mFactor[0] + baseV[1][0]*mFactor[1] + baseV[2][0]*mFactor[2] + baseV[3][0]*mFactor[3]);
|
|
| 519 |
buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1] + (baseV[0][1]*mFactor[0] + baseV[1][1]*mFactor[1] + baseV[2][1]*mFactor[2] + baseV[3][1]*mFactor[3]);
|
|
| 520 |
buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2] + (baseV[0][2]*mFactor[0] + baseV[1][2]*mFactor[1] + baseV[2][2]*mFactor[2] + baseV[3][2]*mFactor[3]);
|
|
| 521 |
buffer[offset+3]= ((tmp1.a[3]*time+tmp1.b[3])*time+tmp1.c[3])*time+tmp1.d[3] + (baseV[0][3]*mFactor[0] + baseV[1][3]*mFactor[1] + baseV[2][3]*mFactor[2] + baseV[3][3]*mFactor[3]);
|
|
| 522 |
buffer[offset+4]= ((tmp1.a[4]*time+tmp1.b[4])*time+tmp1.c[4])*time+tmp1.d[4] + (baseV[0][4]*mFactor[0] + baseV[1][4]*mFactor[1] + baseV[2][4]*mFactor[2] + baseV[3][4]*mFactor[3]);
|
|
| 774 | 523 |
} |
| 775 | 524 |
else |
| 776 | 525 |
{
|
| 777 |
buffer[offset ]= ((tmp1.ax*time+tmp1.bx)*time+tmp1.cx)*time+tmp1.dx;
|
|
| 778 |
buffer[offset+1]= ((tmp1.ay*time+tmp1.by)*time+tmp1.cy)*time+tmp1.dy;
|
|
| 779 |
buffer[offset+2]= ((tmp1.az*time+tmp1.bz)*time+tmp1.cz)*time+tmp1.dz;
|
|
| 780 |
buffer[offset+3]= ((tmp1.aw*time+tmp1.bw)*time+tmp1.cw)*time+tmp1.dw;
|
|
| 781 |
buffer[offset+4]= ((tmp1.av*time+tmp1.bv)*time+tmp1.cv)*time+tmp1.dv;
|
|
| 526 |
buffer[offset ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
|
|
| 527 |
buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1];
|
|
| 528 |
buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2];
|
|
| 529 |
buffer[offset+3]= ((tmp1.a[3]*time+tmp1.b[3])*time+tmp1.c[3])*time+tmp1.d[3];
|
|
| 530 |
buffer[offset+4]= ((tmp1.a[4]*time+tmp1.b[4])*time+tmp1.c[4])*time+tmp1.d[4];
|
|
| 782 | 531 |
} |
| 783 | 532 |
|
| 784 | 533 |
break; |
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 :)