Revision 9aabc9eb
Added by Leszek Koltunski almost 3 years ago
src/main/java/org/distorted/library/type/Dynamic4D.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; |
... | ... | |
63 | 63 |
|
64 | 64 |
if( q>1 ) |
65 | 65 |
{ |
66 |
tmp1.tangent[0] = nx+px/q;
|
|
67 |
tmp1.tangent[1] = ny+py/q;
|
|
68 |
tmp1.tangent[2] = nz+pz/q;
|
|
69 |
tmp1.tangent[3] = nw+pw/q;
|
|
66 |
tmpCache1.velocity[0] = nx+px/q;
|
|
67 |
tmpCache1.velocity[1] = ny+py/q;
|
|
68 |
tmpCache1.velocity[2] = nz+pz/q;
|
|
69 |
tmpCache1.velocity[3] = nw+pw/q;
|
|
70 | 70 |
} |
71 | 71 |
else |
72 | 72 |
{ |
73 |
tmp1.tangent[0] = px+nx*q;
|
|
74 |
tmp1.tangent[1] = py+ny*q;
|
|
75 |
tmp1.tangent[2] = pz+nz*q;
|
|
76 |
tmp1.tangent[3] = pw+nw*q;
|
|
73 |
tmpCache1.velocity[0] = px+nx*q;
|
|
74 |
tmpCache1.velocity[1] = py+ny*q;
|
|
75 |
tmpCache1.velocity[2] = pz+nz*q;
|
|
76 |
tmpCache1.velocity[3] = pw+nw*q;
|
|
77 | 77 |
} |
78 | 78 |
} |
79 | 79 |
else |
80 | 80 |
{ |
81 |
tmp1.tangent[0] = 0.0f;
|
|
82 |
tmp1.tangent[1] = 0.0f;
|
|
83 |
tmp1.tangent[2] = 0.0f;
|
|
84 |
tmp1.tangent[3] = 0.0f;
|
|
81 |
tmpCache1.velocity[0] = 0.0f;
|
|
82 |
tmpCache1.velocity[1] = 0.0f;
|
|
83 |
tmpCache1.velocity[2] = 0.0f;
|
|
84 |
tmpCache1.velocity[3] = 0.0f;
|
|
85 | 85 |
} |
86 | 86 |
} |
87 | 87 |
|
... | ... | |
91 | 91 |
{ |
92 | 92 |
if( numPoints==1 ) |
93 | 93 |
{ |
94 |
tmp1= vc.elementAt(0);
|
|
94 |
tmpCache1 = vc.elementAt(0);
|
|
95 | 95 |
curr= vv.elementAt(0); |
96 | 96 |
|
97 |
tmp1.a[0] = tmp1.a[1] = tmp1.a[2] = tmp1.a[3] = 0.0f;
|
|
98 |
tmp1.b[0] = tmp1.b[1] = tmp1.b[2] = tmp1.b[3] = 0.0f;
|
|
99 |
tmp1.c[0] = curr.x; |
|
100 |
tmp1.c[1] = curr.y; |
|
101 |
tmp1.c[2] = curr.z; |
|
102 |
tmp1.c[3] = curr.w; |
|
103 |
tmp1.d[0] = tmp1.d[1] = tmp1.d[3] = tmp1.d[3] = 0.0f;
|
|
97 |
tmpCache1.a[0] = tmpCache1.a[1] = tmpCache1.a[2] = tmpCache1.a[3] = 0.0f;
|
|
98 |
tmpCache1.b[0] = tmpCache1.b[1] = tmpCache1.b[2] = tmpCache1.b[3] = 0.0f;
|
|
99 |
tmpCache1.c[0] = curr.x;
|
|
100 |
tmpCache1.c[1] = curr.y;
|
|
101 |
tmpCache1.c[2] = curr.z;
|
|
102 |
tmpCache1.c[3] = curr.w;
|
|
103 |
tmpCache1.d[0] = tmpCache1.d[1] = tmpCache1.d[3] = tmpCache1.d[3] = 0.0f;
|
|
104 | 104 |
} |
105 | 105 |
else if( numPoints==2 ) |
106 | 106 |
{ |
107 |
tmp1= vc.elementAt(0);
|
|
108 |
tmp2= vc.elementAt(1);
|
|
107 |
tmpCache1 = vc.elementAt(0);
|
|
108 |
tmpCache2 = vc.elementAt(1);
|
|
109 | 109 |
curr= vv.elementAt(0); |
110 | 110 |
next= vv.elementAt(1); |
111 | 111 |
|
112 |
tmp1.a[0] = tmp1.a[1] = tmp1.a[2] = tmp1.a[3] = 0.0f;
|
|
113 |
tmp1.b[0] = tmp1.b[1] = tmp1.b[2] = tmp1.b[3] = 0.0f;
|
|
114 |
tmp1.c[0] = next.x - curr.x; |
|
115 |
tmp1.c[1] = next.y - curr.y; |
|
116 |
tmp1.c[2] = next.z - curr.z; |
|
117 |
tmp1.c[3] = next.w - curr.w; |
|
118 |
tmp1.d[0] = curr.x; |
|
119 |
tmp1.d[1] = curr.y; |
|
120 |
tmp1.d[2] = curr.z; |
|
121 |
tmp1.d[3] = curr.w; |
|
112 |
tmpCache1.a[0] = tmpCache1.a[1] = tmpCache1.a[2] = tmpCache1.a[3] = 0.0f;
|
|
113 |
tmpCache1.b[0] = tmpCache1.b[1] = tmpCache1.b[2] = tmpCache1.b[3] = 0.0f;
|
|
114 |
tmpCache1.c[0] = next.x - curr.x;
|
|
115 |
tmpCache1.c[1] = next.y - curr.y;
|
|
116 |
tmpCache1.c[2] = next.z - curr.z;
|
|
117 |
tmpCache1.c[3] = next.w - curr.w;
|
|
118 |
tmpCache1.d[0] = curr.x;
|
|
119 |
tmpCache1.d[1] = curr.y;
|
|
120 |
tmpCache1.d[2] = curr.z;
|
|
121 |
tmpCache1.d[3] = curr.w;
|
|
122 | 122 |
|
123 |
tmp2.a[0] = tmp2.a[1] = tmp2.a[2] = tmp2.a[3] = 0.0f;
|
|
124 |
tmp2.b[0] = tmp2.b[1] = tmp2.b[2] = tmp2.b[3] = 0.0f;
|
|
125 |
tmp2.c[0] = curr.x - next.x; |
|
126 |
tmp2.c[1] = curr.y - next.y; |
|
127 |
tmp2.c[2] = curr.z - next.z; |
|
128 |
tmp2.c[3] = curr.w - next.w; |
|
129 |
tmp2.d[0] = next.x; |
|
130 |
tmp2.d[1] = next.y; |
|
131 |
tmp2.d[2] = next.z; |
|
132 |
tmp2.d[3] = next.w; |
|
123 |
tmpCache2.a[0] = tmpCache2.a[1] = tmpCache2.a[2] = tmpCache2.a[3] = 0.0f;
|
|
124 |
tmpCache2.b[0] = tmpCache2.b[1] = tmpCache2.b[2] = tmpCache2.b[3] = 0.0f;
|
|
125 |
tmpCache2.c[0] = curr.x - next.x;
|
|
126 |
tmpCache2.c[1] = curr.y - next.y;
|
|
127 |
tmpCache2.c[2] = curr.z - next.z;
|
|
128 |
tmpCache2.c[3] = curr.w - next.w;
|
|
129 |
tmpCache2.d[0] = next.x;
|
|
130 |
tmpCache2.d[1] = next.y;
|
|
131 |
tmpCache2.d[2] = next.z;
|
|
132 |
tmpCache2.d[3] = next.w;
|
|
133 | 133 |
} |
134 | 134 |
else |
135 | 135 |
{ |
... | ... | |
141 | 141 |
{ |
142 | 142 |
n = i<numPoints-1 ? i+1:0; |
143 | 143 |
|
144 |
tmp1= vc.elementAt(i);
|
|
145 |
tmp2= vc.elementAt(n);
|
|
144 |
tmpCache1 = vc.elementAt(i);
|
|
145 |
tmpCache2 = vc.elementAt(n);
|
|
146 | 146 |
curr= vv.elementAt(i); |
147 | 147 |
next= vv.elementAt(n); |
148 | 148 |
|
149 |
tmp1.cached[0] = curr.x; |
|
150 |
tmp1.cached[1] = curr.y; |
|
151 |
tmp1.cached[2] = curr.z; |
|
152 |
tmp1.cached[3] = curr.w; |
|
149 |
tmpCache1.cached[0] = curr.x;
|
|
150 |
tmpCache1.cached[1] = curr.y;
|
|
151 |
tmpCache1.cached[2] = curr.z;
|
|
152 |
tmpCache1.cached[3] = curr.w;
|
|
153 | 153 |
|
154 |
tmp1.a[0] = mConvexity*( 2*curr.x + tmp1.tangent[0] - 2*next.x + tmp2.tangent[0]);
|
|
155 |
tmp1.b[0] = mConvexity*(-3*curr.x - 2*tmp1.tangent[0] + 3*next.x - tmp2.tangent[0]);
|
|
156 |
tmp1.c[0] = mConvexity*(tmp1.tangent[0]) + (1.0f-mConvexity)*(next.x-curr.x);
|
|
157 |
tmp1.d[0] = curr.x; |
|
154 |
tmpCache1.a[0] = mConvexity*( 2*curr.x + tmpCache1.velocity[0] - 2*next.x + tmpCache2.velocity[0]);
|
|
155 |
tmpCache1.b[0] = mConvexity*(-3*curr.x - 2* tmpCache1.velocity[0] + 3*next.x - tmpCache2.velocity[0]);
|
|
156 |
tmpCache1.c[0] = mConvexity*(tmpCache1.velocity[0]) + (1.0f-mConvexity)*(next.x-curr.x);
|
|
157 |
tmpCache1.d[0] = curr.x;
|
|
158 | 158 |
|
159 |
tmp1.a[1] = mConvexity*( 2*curr.y + tmp1.tangent[1] - 2*next.y + tmp2.tangent[1]);
|
|
160 |
tmp1.b[1] = mConvexity*(-3*curr.y - 2*tmp1.tangent[1] + 3*next.y - tmp2.tangent[1]);
|
|
161 |
tmp1.c[1] = mConvexity*(tmp1.tangent[1]) + (1.0f-mConvexity)*(next.y-curr.y);
|
|
162 |
tmp1.d[1] = curr.y; |
|
159 |
tmpCache1.a[1] = mConvexity*( 2*curr.y + tmpCache1.velocity[1] - 2*next.y + tmpCache2.velocity[1]);
|
|
160 |
tmpCache1.b[1] = mConvexity*(-3*curr.y - 2* tmpCache1.velocity[1] + 3*next.y - tmpCache2.velocity[1]);
|
|
161 |
tmpCache1.c[1] = mConvexity*(tmpCache1.velocity[1]) + (1.0f-mConvexity)*(next.y-curr.y);
|
|
162 |
tmpCache1.d[1] = curr.y;
|
|
163 | 163 |
|
164 |
tmp1.a[2] = mConvexity*( 2*curr.z + tmp1.tangent[2] - 2*next.z + tmp2.tangent[2]);
|
|
165 |
tmp1.b[2] = mConvexity*(-3*curr.z - 2*tmp1.tangent[2] + 3*next.z - tmp2.tangent[2]);
|
|
166 |
tmp1.c[2] = mConvexity*(tmp1.tangent[2]) + (1.0f-mConvexity)*(next.z-curr.z);
|
|
167 |
tmp1.d[2] = curr.z; |
|
164 |
tmpCache1.a[2] = mConvexity*( 2*curr.z + tmpCache1.velocity[2] - 2*next.z + tmpCache2.velocity[2]);
|
|
165 |
tmpCache1.b[2] = mConvexity*(-3*curr.z - 2* tmpCache1.velocity[2] + 3*next.z - tmpCache2.velocity[2]);
|
|
166 |
tmpCache1.c[2] = mConvexity*(tmpCache1.velocity[2]) + (1.0f-mConvexity)*(next.z-curr.z);
|
|
167 |
tmpCache1.d[2] = curr.z;
|
|
168 | 168 |
|
169 |
tmp1.a[3] = mConvexity*( 2*curr.w + tmp1.tangent[3] - 2*next.w + tmp2.tangent[3]); |
|
170 |
tmp1.b[3] = mConvexity*(-3*curr.w - 2*tmp1.tangent[3] + 3*next.w - tmp2.tangent[3]); |
|
171 |
tmp1.c[3] = mConvexity*(tmp1.tangent[3]) + (1.0f-mConvexity)*(next.w-curr.w); |
|
172 |
tmp1.d[3] = curr.w; |
|
169 |
tmpCache1.a[3] = mConvexity*( 2*curr.w + tmpCache1.velocity[3] - 2*next.w + tmpCache2.velocity[3]); |
|
170 |
tmpCache1.b[3] = mConvexity*(-3*curr.w - 2* tmpCache1.velocity[3] + 3*next.w - tmpCache2.velocity[3]); |
|
171 |
tmpCache1.c[3] = mConvexity*(tmpCache1.velocity[3]) + (1.0f-mConvexity)*(next.w-curr.w); |
|
172 |
tmpCache1.d[3] = curr.w; |
|
173 |
|
|
174 |
if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) smoothOutSegment(tmpCache1); |
|
173 | 175 |
} |
174 | 176 |
} |
175 | 177 |
|
... | ... | |
522 | 524 |
{ |
523 | 525 |
int vecNext = getNext(vecCurr,t); |
524 | 526 |
next = vv.elementAt(vecNext); |
525 |
tmp2 = vc.elementAt(vecNext); |
|
527 |
tmpCache2 = vc.elementAt(vecNext);
|
|
526 | 528 |
|
527 |
if( tmp2.cached[0]!=next.x || tmp2.cached[1]!=next.y || tmp2.cached[2]!=next.z || tmp2.cached[3]!=next.w ) recomputeCache();
|
|
529 |
if( tmpCache2.cached[0]!=next.x || tmpCache2.cached[1]!=next.y || tmpCache2.cached[2]!=next.z || tmpCache2.cached[3]!=next.w ) recomputeCache();
|
|
528 | 530 |
} |
529 | 531 |
|
530 | 532 |
if( mSegment!= segment && vn!=null ) vn.elementAt(vecCurr).computeNoise(); |
531 | 533 |
|
532 | 534 |
mSegment = segment; |
533 |
|
|
534 | 535 |
time = time-vecCurr; |
535 |
|
|
536 |
tmp1 = vc.elementAt(vecCurr);
|
|
537 |
|
|
536 |
tmpCache1 = vc.elementAt(vecCurr); |
|
537 |
if( mSpeedMode==SPEED_MODE_SEGMENT_CONSTANT ) time = smoothSpeed(time, tmpCache1);
|
|
538 |
|
|
538 | 539 |
if( vn!=null ) |
539 | 540 |
{ |
540 | 541 |
time = noise(time,vecCurr); |
541 | 542 |
|
542 |
computeOrthonormalBaseMore(time,tmp1);
|
|
543 |
computeOrthonormalBaseMore(time, tmpCache1);
|
|
543 | 544 |
|
544 |
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]);
|
|
545 |
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]);
|
|
546 |
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]);
|
|
547 |
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]);
|
|
545 |
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]);
|
|
546 |
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]);
|
|
547 |
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]);
|
|
548 |
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]);
|
|
548 | 549 |
} |
549 | 550 |
else |
550 | 551 |
{ |
551 |
buffer[offset ]= ((tmp1.a[0]*time+tmp1.b[0])*time+tmp1.c[0])*time+tmp1.d[0];
|
|
552 |
buffer[offset+1]= ((tmp1.a[1]*time+tmp1.b[1])*time+tmp1.c[1])*time+tmp1.d[1];
|
|
553 |
buffer[offset+2]= ((tmp1.a[2]*time+tmp1.b[2])*time+tmp1.c[2])*time+tmp1.d[2];
|
|
554 |
buffer[offset+3]= ((tmp1.a[3]*time+tmp1.b[3])*time+tmp1.c[3])*time+tmp1.d[3];
|
|
552 |
buffer[offset ]= ((tmpCache1.a[0]*time+ tmpCache1.b[0])*time+ tmpCache1.c[0])*time+ tmpCache1.d[0];
|
|
553 |
buffer[offset+1]= ((tmpCache1.a[1]*time+ tmpCache1.b[1])*time+ tmpCache1.c[1])*time+ tmpCache1.d[1];
|
|
554 |
buffer[offset+2]= ((tmpCache1.a[2]*time+ tmpCache1.b[2])*time+ tmpCache1.c[2])*time+ tmpCache1.d[2];
|
|
555 |
buffer[offset+3]= ((tmpCache1.a[3]*time+ tmpCache1.b[3])*time+ tmpCache1.c[3])*time+ tmpCache1.d[3];
|
|
555 | 556 |
} |
556 | 557 |
|
557 | 558 |
break; |
Also available in: Unified diff
Dynamics: introduce two speed modes - smooth and segment_constant.
Prepare the third mode - globally_constant.