Changes

Jump to: navigation, search

TeamDS

216 bytes added, 23:43, 4 April 2017
The code
=== The code ===
{| class="wikitable mw-collapsible mw-collapsed"
! NBody Hot FunctionsSDF Generator Code
|-
|
<syntaxhighlight lang="cpp">
void doworkGenerate(double tconst float src[], float dst[], int width, int height, int spread){ int numtimesspreadSize =spread * spread; intsize = width * height; for (int i = 0; i < size; i++) { Vector2 localVec(i - (abs(ti /dtwidth) * width), i / width); dt float shortestDist =t/double(numtimes+1)MAX_FLOAT_VALUE; numtimes float pixelVal =numtimes+1src[i]; if (pixelVal > 0) // It's an inside pixel { // Find closest outside pixel for (int ij =0;ij <numtimessize;ij++) { CRO_step float pixelVal2 = src[j]; if (pixelVal2 == 0)// Outside pixel { // Calculate distance Vector2 targetVec(j - ((dtj / width) * width),aj / width); } float dist = localVec.CalcDistance(targetVec); if (dist < shortestDist) shortestDist = dist; }
void CRO_step(register double mydt,void (*a)()){
long double macr_a[4] = {0.5153528374311229364, -0.085782019412973646,0.4415830236164665242, 0.1288461583653841854};
long double macr_b[4] = {0.1344961992774310892, -0.2248198030794208058, 0.7563200005156682911, 0.3340036032863214255};
for (int i=0;i<4;i++){
a();
for (int j=0;j<ncobjects;j++){
cobjects[j]->v += cobjects[j]->a * mydt*macr_b[i];
cobjects[j]->pos += cobjects[j]->v * mydt*macr_a[i];
}
} //We should really expand the loop for efficiency
}
void calculate_a float spread01 = (shortestDist / spread){; for if (int j1spread01 > 1) spread01 =01;j1<ncobjects;j1++){// clamp it cobjects dst[j1i]->a=vect(spread01 * .5f) + 0,0,0).5f; } else // It's an outisde pixel { // Find closest inside pixel for (int j1j =0; j1j <ncobjectssize;j1j++) { for (int j2 float pixelVal2 =j1+1src[j];j2<ncobjects;j2++ if (pixelVal2 > 0)// Inside pixel { double m1=cobjects[j1] // Calculate distance Vector2 targetVec(j ->m((j / width) * width), j / width); double m2 float dist =cobjects[j2]->mlocalVec.CalcDistance(targetVec); vect if (dist< shortestDist) shortestDist =cobjects[j1]->pos-cobjects[j2]->posdist; } double magd}  float spread01 =dist.mag(shortestDist / spread); vect base=dist*if (spread01 > 1.0/(magd*magd*magd))spread01 = 1;// clamp it cobjectsdst[j1i]->a+=base*(1 -m2spread01); cobjects[j2]->a+=base*m1.5f;
}
}
116
edits

Navigation menu