void def_logo(void) { srnd(); swap_position = rnd( 15 ); def_P(); def_A(); def_D(); }
int main(int argc, char *argv[]) { char *str, flg; int leng = LENG, seed = SEED, i; long next = SEED; double p, mean = MEAN, sdev = SDEV; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) { if (*(str = *++argv) == '-') { flg = *++str; if (*++str == '\0') { str = *++argv; argc--; } switch (flg) { case 'l': leng = atoi(str); break; case 's': seed = atoi(str); break; case 'm': mean = atof(str); break; case 'v': sdev = atof(str); sdev = sqrt(sdev); break; case 'd': sdev = atof(str); break; case 'h': default: usage(); } } else usage(); } if (seed != 1) next = srnd((unsigned int) seed); for (i = 0;; i++) { p = (double) nrandom(&next); p = mean + sdev * p; fwritef(&p, sizeof(p), 1, stdout); if (i == leng - 1) break; } return (0); }
/* ============ TestUntransformJoints ============ */ void TestUntransformJoints() { int i, j; TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD; idTempArray< idJointMat > joints( COUNT+1 ); idTempArray< idJointMat > joints1( COUNT+1 ); idTempArray< idJointMat > joints2( COUNT+1 ); idTempArray< int > parents( COUNT+1 ); const char *result; idRandom srnd( RANDOM_SEED ); for ( i = 0; i <= COUNT; i++ ) { idAngles angles; angles[0] = srnd.CRandomFloat() * 180.0f; angles[1] = srnd.CRandomFloat() * 180.0f; angles[2] = srnd.CRandomFloat() * 180.0f; joints[i].SetRotation( angles.ToMat3() ); idVec3 v; v[0] = srnd.CRandomFloat() * 2.0f; v[1] = srnd.CRandomFloat() * 2.0f; v[2] = srnd.CRandomFloat() * 2.0f; joints[i].SetTranslation( v ); parents[i] = i - 1; } bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { for ( j = 0; j <= COUNT; j++ ) { joints1[j] = joints[j]; } StartRecordTime( start ); p_generic->UntransformJoints( joints1.Ptr(), parents.Ptr(), 1, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->UntransformJoints()", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { for ( j = 0; j <= COUNT; j++ ) { joints2[j] = joints[j]; } StartRecordTime( start ); p_simd->UntransformJoints( joints2.Ptr(), parents.Ptr(), 1, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } for ( i = 1; i <= COUNT; i++ ) { if ( !joints1[i].Compare( joints2[i], 1e-3f ) ) { break; } } result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->UntransformJoints() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); }
wheur5() { int i, j, k; int s, n, d, pto; if(amp[-2]) { i = amp[-3]; pto = board[i]; board[i] = 0; } i = 64; while(i--) control[i] = 0; if(game < 2) { i = 64; while(i--) control[i] =+ center[i]; } if(mantom) { if((flag&03)==0) srnd(wkpos); } else { if((flag&030)==0) srnd(bkpos); } i = 64; s = 0; while(i--) { n = control[i]*100; attack(i); j = 0; while(k = attacv[j++]) { d = (pval+6)[k]; if(d < 0) s =- n/(-d); else s =+ n/d; } } if(amp[-2]) board[amp[-3]] = pto; return(-s); }
/* ============ TestConvertJointMatsToJointQuats ============ */ void TestConvertJointMatsToJointQuats() { int i; TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD; idTempArray< idJointMat > baseJoints( COUNT ); idTempArray< idJointQuat > joints1( COUNT ); idTempArray< idJointQuat > joints2( COUNT ); const char *result; idRandom srnd( RANDOM_SEED ); for ( i = 0; i < COUNT; i++ ) { idAngles angles; angles[0] = srnd.CRandomFloat() * 180.0f; angles[1] = srnd.CRandomFloat() * 180.0f; angles[2] = srnd.CRandomFloat() * 180.0f; baseJoints[i].SetRotation( angles.ToMat3() ); idVec3 v; v[0] = srnd.CRandomFloat() * 10.0f; v[1] = srnd.CRandomFloat() * 10.0f; v[2] = srnd.CRandomFloat() * 10.0f; baseJoints[i].SetTranslation( v ); } bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_generic->ConvertJointMatsToJointQuats( joints1.Ptr(), baseJoints.Ptr(), COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->ConvertJointMatsToJointQuats()", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_simd->ConvertJointMatsToJointQuats( joints2.Ptr(), baseJoints.Ptr(), COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } for ( i = 0; i < COUNT; i++ ) { if ( !joints1[i].q.Compare( joints2[i].q, 1e-4f ) ) { break; } if ( !joints1[i].t.Compare( joints2[i].t, 1e-4f ) ) { break; } } result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->ConvertJointMatsToJointQuats() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); }
/* setup */ static void _setup(void) { int i; Evas_Object *o; srnd(); for (i = 0; i < OBNUM; i++) { int r, g, b, a; o = evas_object_rectangle_add(evas); o_images[i] = o; a = 256 - (1 << ((rnd() % 8) + 1)); if (a < 128) a = 128; r = ((rnd()&0xff) * a) / 255; g = ((rnd()&0xff) * a) / 255; b = ((rnd()&0xff) * a) / 255; evas_object_color_set(o, r, g, b, a); evas_object_show(o); } done = 0; }
void lbg(double *x, const int l, const int tnum, double *icb, int icbsize, double *cb, const int ecbsize, const int iter, const int mintnum, const int seed, const int centup, const double delta, const double end) { int i, j, k, it, maxindex, tnum1, tnum2; static int *cntcb, *tindex, size, sizex, sizecb; unsigned long next = SEED; double d0, d1, dl, err, tmp, rand; static double *cb1 = NULL; double *p, *q, *r; if (cb1 == NULL) { cb1 = dgetmem(ecbsize * l); tindex = (int *) dgetmem(tnum); cntcb = (int *) dgetmem(ecbsize); size = l; sizex = tnum; sizecb = ecbsize; } if (l > size) { free(cb1); cb1 = dgetmem(ecbsize * l); size = l; } if (tnum > sizex) { free(tindex); tindex = (int *) dgetmem(tnum); sizex = tnum; } if (sizecb > ecbsize) { free(cb1); free(cntcb); cb1 = dgetmem(ecbsize * l); cntcb = (int *) dgetmem(ecbsize); } movem(icb, cb, sizeof(*icb), icbsize * l); if (seed != 1) next = srnd((unsigned int) seed); for (; icbsize * 2 <= ecbsize;) { q = cb; r = cb + icbsize * l; for (i = 0; i < icbsize; i++) { for (j = 0; j < l; j++) { dl = delta * nrandom(&next); *r = *q - dl; r++; *q = *q + dl; q++; } } icbsize *= 2; d0 = MAXVALUE; for (it = 1; it <= iter; it++) { fillz((double *) cntcb, sizeof(*cntcb), icbsize); d1 = 0.0; p = x; for (i = 0; i < tnum; i++, p += l) { tindex[i] = vq(p, cb, l, icbsize); cntcb[tindex[i]]++; q = cb + tindex[i] * l; d1 += edist(p, q, l); } d1 /= tnum; err = abs((d0 - d1) / d1); if (err < end) break; d0 = d1; fillz(cb1, sizeof(*cb), icbsize * l); p = x; for (i = 0; i < tnum; i++) { q = cb1 + tindex[i] * l; for (j = 0; j < l; j++) *q++ += *p++; } k = maxindex = 0; for (i = 0; i < icbsize; i++) if (cntcb[i] > k) { k = cntcb[i]; maxindex = i; } q = cb; r = cb1; for (i = 0; i < icbsize; i++, r += l, q += l) if (cntcb[i] >= mintnum) for (j = 0; j < l; j++) q[j] = r[j] / (double) cntcb[i]; else { if (centup == 1) { p = cb + maxindex * l; for (j = 0; j < l; j++) { rand = nrandom(&next); q[j] = p[j] + delta * rand; p[j] = p[j] - delta * rand; } } else if (centup == 2) { if (i < icbsize / 2) { p = q + icbsize / 2 * l; tnum1 = cntcb[i]; tnum2 = cntcb[i + icbsize / 2]; for (j = 0; j < l; j++) { tmp = (tnum2 * q[j] + tnum1 * p[j]) / (tnum1 + tnum2); rand = nrandom(&next); q[j] = tmp + delta * rand; p[j] = tmp - delta * rand; } } else { p = q - icbsize / 2 * l; tnum1 = cntcb[i]; tnum2 = cntcb[i - icbsize / 2]; for (j = 0; j < l; j++) { tmp = (tnum2 * q[j] + tnum1 * p[j]) / (tnum1 + tnum2); rand = nrandom(&next); q[j] = tmp + delta * rand; p[j] = tmp - delta * rand; } } } } } if (icbsize == ecbsize) break; } return; }
void score(long amount, int lvl, int flags, int monst) /*ARGSUSED*/ { struct sc_ent *scp=NULL, *sc2=NULL; int i; char *killer; char buf[1024]; static const char *reason[] = { "killed", "quit", "a winner", "a total winner" }; char *packend; if (flags != WINNER && flags != TOTAL && flags != SCOREIT) { if (flags == CHICKEN) packend = "when you quit"; else packend = "at your untimely demise"; noecho(); nl(); refresh(); showpack(packend); } /* Open file and read list */ if (fd_score == NULL) { printf("No score file opened\n"); return; } for (scp = top_ten; scp < &top_ten[10]; scp++) { scp->sc_lvl = 0L; scp->sc_score = 0L; for (i = 0; i < 76; i++) scp->sc_name[i] = ucrnd(255); scp->sc_gold = 0L; scp->sc_flags = rnd(10); scp->sc_level = rnd(10); scp->sc_monster = srnd(10); scp->sc_artifacts = 0; } if (flags != SCOREIT) { mvaddstr(LINES - 1, 0, retstr); refresh(); fflush(stdout); wait_for('\n'); } fseek(fd_score, 0L, SEEK_SET); fread(top_ten, sizeof(top_ten), 1, fd_score); /* Insert player in list if need be */ if (!waswizard) { for (scp = top_ten; scp < &top_ten[10]; scp++) { if (lvl > scp->sc_lvl) break; if (lvl == scp->sc_lvl && amount > scp->sc_score) break; } if (scp < &top_ten[10]) { if (flags == WINNER) sc2 = &top_ten[9]; /* LAST WINNER ALWAYS MAKES IT */ while (sc2 > scp) { *sc2 = sc2[-1]; sc2--; } scp->sc_lvl = lvl; scp->sc_gold = purse; scp->sc_score = amount; strcpy(scp->sc_name, whoami); strcat(scp->sc_name,", "); strcat(scp->sc_name, which_class(player.t_ctype)); scp->sc_flags = flags; if (flags == WINNER) scp->sc_level = max_level; else scp->sc_level = level; scp->sc_monster = monst; scp->sc_artifacts = has_artifact; sc2 = scp; } } if (flags != SCOREIT) { clear(); refresh(); endwin(); } /* Print the list */ printf("\nTop Ten Adventurers:\n%4s %15s %10s %s\n", "Rank", "Score", "Gold", "Name"); for (scp = top_ten; scp < &top_ten[10]; scp++) { if (scp->sc_score) { char lev[20]; sprintf(lev, "%ld+%ld", scp->sc_lvl, scp->sc_score); printf("%4d %15s %10ld %s:", scp - top_ten + 1, lev, scp->sc_gold, scp->sc_name); if (scp->sc_artifacts) { char thangs[80]; int n; int first = TRUE; thangs[0] = '\0'; for (n = 0; n <= maxartifact; n++) { if (scp->sc_artifacts & (1 << n)) { if (strlen(thangs)) strcat(thangs, ", "); if (first) { strcat(thangs, "retrieved "); first = FALSE; } if (45 - strlen(thangs) < strlen(arts[n].ar_name)) { printf("%s\n%32s", thangs," "); thangs[0] = '\0'; } strcat(thangs, arts[n].ar_name); } } if (strlen(thangs)) printf("%s,", thangs); printf("\n%32s"," "); } printf("%s on level %d",reason[scp->sc_flags],scp->sc_level); if (scp->sc_flags == 0) { printf(" by \n%32s"," "); killer = killname(scp->sc_monster, buf); printf(" %s", killer); } putchar('\n'); } } if (sc2 != NULL) { fseek(fd_score, 0L, SEEK_SET); /* Update the list file */ fwrite(top_ten, sizeof(top_ten), 1, fd_score); } fclose(fd_score); }
int main(int argc, char **argv) { int fprd = FPERIOD, iprd = IPERIOD, i, j, seed = SEED; long next = SEED; FILE *fp = stdin; double x, p1, p2, inc, pc; Boolean gauss = GAUSS; if ((cmnd = strrchr(argv[0], '/')) == NULL) cmnd = argv[0]; else cmnd++; while (--argc) if (**++argv == '-') { switch (*(*argv + 1)) { case 'p': fprd = atoi(*++argv); --argc; break; case 'i': iprd = atoi(*++argv); --argc; break; case 'n': gauss = TR; break; case 's': seed = atoi(*++argv); --argc; break; case 'h': usage(0); default: fprintf(stderr, "%s : Invalid option '%c'!\n", cmnd, *(*argv + 1)); usage(1); } } else fp = getfp(*argv, "rb"); if (gauss & (seed != 1)) next = srnd((unsigned int) seed); if (freadf(&p1, sizeof(p1), 1, fp) != 1) return (1); pc = p1; for (;;) { if (freadf(&p2, sizeof(p2), 1, fp) != 1) return (0); if ((p1 != 0.0) && (p2 != 0.0)) inc = (p2 - p1) * (double) iprd / (double) fprd; else { inc = 0.0; pc = p2; p1 = 0.0; } for (j = fprd, i = (iprd + 1) / 2; j--;) { if (p1 == 0.0) { if (gauss) x = (double) nrandom(&next); else x = mseq(); } else { if ((pc += 1.0) >= p1) { x = sqrt(p1); pc = pc - p1; } else x = 0.0; } fwritef(&x, sizeof(x), 1, stdout); if (!--i) { p1 += inc; i = iprd; } } p1 = p2; } return 0; }
/* ============ TestBlendJoints ============ */ void TestBlendJointsFast() { int i, j; TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD; idTempArray< idJointQuat > baseJoints( COUNT ); idTempArray< idJointQuat > joints1( COUNT ); idTempArray< idJointQuat > joints2( COUNT ); idTempArray< idJointQuat > blendJoints( COUNT ); idTempArray< int > index( COUNT ); float lerp = 0.3f; const char *result; idRandom srnd( RANDOM_SEED ); for ( i = 0; i < COUNT; i++ ) { idAngles angles; angles[0] = srnd.CRandomFloat() * 180.0f; angles[1] = srnd.CRandomFloat() * 180.0f; angles[2] = srnd.CRandomFloat() * 180.0f; baseJoints[i].q = angles.ToQuat(); baseJoints[i].t[0] = srnd.CRandomFloat() * 10.0f; baseJoints[i].t[1] = srnd.CRandomFloat() * 10.0f; baseJoints[i].t[2] = srnd.CRandomFloat() * 10.0f; baseJoints[i].w = 0.0f; angles[0] = srnd.CRandomFloat() * 180.0f; angles[1] = srnd.CRandomFloat() * 180.0f; angles[2] = srnd.CRandomFloat() * 180.0f; blendJoints[i].q = angles.ToQuat(); blendJoints[i].t[0] = srnd.CRandomFloat() * 10.0f; blendJoints[i].t[1] = srnd.CRandomFloat() * 10.0f; blendJoints[i].t[2] = srnd.CRandomFloat() * 10.0f; blendJoints[i].w = 0.0f; index[i] = i; } bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { for ( j = 0; j < COUNT; j++ ) { joints1[j] = baseJoints[j]; } StartRecordTime( start ); p_generic->BlendJointsFast( joints1.Ptr(), blendJoints.Ptr(), lerp, index.Ptr(), COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->BlendJointsFast()", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { for ( j = 0; j < COUNT; j++ ) { joints2[j] = baseJoints[j]; } StartRecordTime( start ); p_simd->BlendJointsFast( joints2.Ptr(), blendJoints.Ptr(), lerp, index.Ptr(), COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } for ( i = 0; i < COUNT; i++ ) { if ( !joints1[i].t.Compare( joints2[i].t, 1e-3f ) ) { break; } if ( !joints1[i].q.Compare( joints2[i].q, 1e-2f ) ) { break; } } result = ( i >= COUNT ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->BlendJointsFast() %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); }
/* ============ TestMinMax ============ */ void TestMinMax() { int i; TIME_TYPE start, end, bestClocksGeneric, bestClocksSIMD; ALIGN16( float fsrc0[COUNT] ); ALIGN16( idVec2 v2src0[COUNT] ); ALIGN16( idVec3 v3src0[COUNT] ); ALIGN16( idDrawVert drawVerts[COUNT] ); ALIGN16( triIndex_t indexes[COUNT] ); float min = 0.0f, max = 0.0f, min2 = 0.0f, max2 = 0.0f; idVec2 v2min, v2max, v2min2, v2max2; idVec3 vmin, vmax, vmin2, vmax2; const char *result; idRandom srnd( RANDOM_SEED ); for ( i = 0; i < COUNT; i++ ) { fsrc0[i] = srnd.CRandomFloat() * 10.0f; v2src0[i][0] = srnd.CRandomFloat() * 10.0f; v2src0[i][1] = srnd.CRandomFloat() * 10.0f; v3src0[i][0] = srnd.CRandomFloat() * 10.0f; v3src0[i][1] = srnd.CRandomFloat() * 10.0f; v3src0[i][2] = srnd.CRandomFloat() * 10.0f; drawVerts[i].xyz = v3src0[i]; indexes[i] = i; } idLib::common->Printf("====================================\n" ); bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { min = idMath::INFINITY; max = -idMath::INFINITY; StartRecordTime( start ); p_generic->MinMax( min, max, fsrc0, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->MinMax( float[] )", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_simd->MinMax( min2, max2, fsrc0, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } result = ( min == min2 && max == max2 ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->MinMax( float[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_generic->MinMax( v2min, v2max, v2src0, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->MinMax( idVec2[] )", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_simd->MinMax( v2min2, v2max2, v2src0, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } result = ( v2min == v2min2 && v2max == v2max2 ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->MinMax( idVec2[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_generic->MinMax( vmin, vmax, v3src0, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->MinMax( idVec3[] )", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_simd->MinMax( vmin2, vmax2, v3src0, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->MinMax( idVec3[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_generic->MinMax( vmin, vmax, drawVerts, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->MinMax( idDrawVert[] )", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_simd->MinMax( vmin2, vmax2, drawVerts, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->MinMax( idDrawVert[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); bestClocksGeneric = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_generic->MinMax( vmin, vmax, drawVerts, indexes, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksGeneric ); } PrintClocks( "generic->MinMax( idDrawVert[], indexes[] )", COUNT, bestClocksGeneric ); bestClocksSIMD = 0; for ( i = 0; i < NUMTESTS; i++ ) { StartRecordTime( start ); p_simd->MinMax( vmin2, vmax2, drawVerts, indexes, COUNT ); StopRecordTime( end ); GetBest( start, end, bestClocksSIMD ); } result = ( vmin == vmin2 && vmax == vmax2 ) ? "ok" : S_COLOR_RED"X"; PrintClocks( va( " simd->MinMax( idDrawVert[], indexes[] ) %s", result ), COUNT, bestClocksSIMD, bestClocksGeneric ); }
void DrawOceanTask::generateWaves() { long seed = 1234567; float min = log(lambdaMin) / log(2.0f); float max = log(lambdaMax) / log(2.0f); vec4f *waves = new vec4f[nbWaves]; sigmaXsq = 0.0; sigmaYsq = 0.0; meanHeight = 0.0; heightVariance = 0.0; amplitudeMax = 0.0; #define nbAngles 5 // impair #define angle(i) (1.5*(((i)%nbAngles)/(float)(nbAngles/2)-1)) #define dangle() (1.5/(float)(nbAngles/2)) float Wa[nbAngles]; // normalised gaussian samples int index[nbAngles]; // to hash angle order float s=0; for (int i=0; i<nbAngles; i++) { index[i]=i; float a = angle(i); // (i/(float)(nbAngle/2)-1)*1.5; s += Wa[i] = exp(-.5*a*a); } for (int i=0; i<nbAngles; i++) { Wa[i] /= s; } const float waveDispersion = 0.9f;//6; const float U0 = 10.0f; const int spectrumType = 2; for (int i = 0; i < nbWaves; ++i) { float x = i / (nbWaves - 1.0f); float lambda = pow(2.0f, (1.0f - x) * min + x * max); float ktheta = grandom(0.0f, 1.0f, &seed) * waveDispersion; float knorm = 2.0f * M_PI_F / lambda; float omega = sqrt(9.81f * knorm); float amplitude; if (spectrumType == 1) { amplitude = heightMax * grandom(0.5f, 0.15f, &seed) / (knorm * lambdaMax / (2.0f * M_PI)); } else if (spectrumType == 2) { float step = (max-min)/(nbWaves-1); // dlambda/di float omega0 = 9.81f / U0; // 100.0; if ((i%(nbAngles))==0) { // scramble angle ordre for (int k=0; k<nbAngles; k++) { // do N swap in indices int n1=lrandom(&seed)%nbAngles, n2=lrandom(&seed)%nbAngles,n; n=index[n1]; index[n1]=index[n2]; index[n2]=n; } } ktheta = waveDispersion*(angle(index[(i)%nbAngles])+.4*srnd()*dangle()); ktheta *= 1/(1+40*pow(omega0/omega,4)); amplitude = (8.1e-3*9.81*9.81) / pow(omega,5) * exp(-0.74*pow(omega0/omega,4)); amplitude *= .5*sqrt(2*3.14*9.81/lambda)*nbAngles*step; // (2/step-step/2); amplitude = 3*heightMax*sqrt(amplitude); } // cull breaking trochoids ( d(x+Acos(kx))=1-Akcos(); must be >0 ) if (amplitude > 1.0f / knorm) { amplitude = 1.0f / knorm; } else if (amplitude < -1.0f / knorm) { amplitude = -1.0f / knorm; } waves[i].x = amplitude; waves[i].y = omega; waves[i].z = knorm * cos(ktheta); waves[i].w = knorm * sin(ktheta); sigmaXsq += pow(cos(ktheta), 2.0f) * (1.0f - sqrt(1.0f - knorm * knorm * amplitude * amplitude)); sigmaYsq += pow(sin(ktheta), 2.0f) * (1.0f - sqrt(1.0f - knorm * knorm * amplitude * amplitude)); meanHeight -= knorm * amplitude * amplitude * 0.5f; heightVariance += amplitude * amplitude * (2.0f - knorm * knorm * amplitude * amplitude) * 0.25f; amplitudeMax += fabs(amplitude); } float var = 4.0f; float h0 = meanHeight - var * sqrt(heightVariance); float h1 = meanHeight + var * sqrt(heightVariance); amplitudeMax = h1 - h0; ptr<Texture1D> wavesTexture = new Texture1D(nbWaves, RGBA32F, RGBA, FLOAT, Texture::Parameters().wrapS(CLAMP_TO_BORDER).min(NEAREST).mag(NEAREST), Buffer::Parameters(), CPUBuffer(waves)); delete[] waves; nbWavesU->set(nbWaves); wavesU->set(wavesTexture); if (brdfShader != NULL) { assert(!brdfShader->getUsers().empty()); Program *prog = *(brdfShader->getUsers().begin()); prog->getUniform1f("seaRoughness")->set(sigmaXsq); prog->getUniform3f("seaColor")->set(seaColor); } }