Beispiel #1
0
void BLI_jitter_init(float (*jitarr)[2], int num)
{
	float (*jit2)[2];
	float num_fl, num_fl_sqrt;
	float x, rad1, rad2, rad3;
	RNG *rng;
	int i;

	if (num == 0) {
		return;
	}

	num_fl = (float)num;
	num_fl_sqrt = sqrtf(num_fl);

	jit2 = MEM_mallocN(12 + (unsigned int)num * sizeof(float[2]), "initjit");
	rad1 = 1.0f        / num_fl_sqrt;
	rad2 = 1.0f        / num_fl;
	rad3 = num_fl_sqrt / num_fl;

	rng = BLI_rng_new(31415926 + (unsigned int)num);

	x = 0;
	for (i = 0; i < num; i++) {
		jitarr[i][0] =                 x + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
		jitarr[i][1] = (float)i / num_fl + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
		x += rad3;
		x -= floorf(x);
	}

	BLI_rng_free(rng);

	for (i = 0; i < 24; i++) {
		BLI_jitterate1(jitarr, jit2, num, rad1);
		BLI_jitterate1(jitarr, jit2, num, rad1);
		BLI_jitterate2(jitarr, jit2, num, rad2);
	}

	MEM_freeN(jit2);
	
	/* finally, move jittertab to be centered around (0, 0) */
	for (i = 0; i < num; i++) {
		jitarr[i][0] -= 0.5f;
		jitarr[i][1] -= 0.5f;
	}
}
/* almost exact copy of BLI_jitter_init */
static void init_mv_jit(float *jit, int num, int seed2, float amount)
{
	RNG *rng;
	float *jit2, x, rad1, rad2, rad3;
	int i, num2;

	if (num==0) return;

	rad1= (float)(1.0f/sqrtf((float)num));
	rad2= (float)(1.0f/((float)num));
	rad3= (float)sqrtf((float)num)/((float)num);

	rng = BLI_rng_new(31415926 + num + seed2);
	x= 0;
	num2 = 2 * num;
	for (i=0; i<num2; i+=2) {

		jit[i] = x + amount*rad1*(0.5f - BLI_rng_get_float(rng));
		jit[i+1] = i/(2.0f*num) + amount*rad1*(0.5f - BLI_rng_get_float(rng));

		jit[i]-= (float)floor(jit[i]);
		jit[i+1]-= (float)floor(jit[i+1]);

		x+= rad3;
		x -= (float)floor(x);
	}

	jit2= MEM_mallocN(12 + 2*sizeof(float)*num, "initjit");

	for (i=0 ; i<4 ; i++) {
		BLI_jitterate1((float (*)[2])jit, (float (*)[2])jit2, num, rad1);
		BLI_jitterate1((float (*)[2])jit, (float (*)[2])jit2, num, rad1);
		BLI_jitterate2((float (*)[2])jit, (float (*)[2])jit2, num, rad2);
	}
	MEM_freeN(jit2);
	BLI_rng_free(rng);
}
Beispiel #3
0
void BLI_jitter_init(float *jitarr, int num)
{
	float *jit2, x, rad1, rad2, rad3;
	int i;

	if (num == 0) return;

	jit2 = MEM_mallocN(12 + 2 * sizeof(float) * num, "initjit");
	rad1 = 1.0f / sqrtf((float)num);
	rad2 = 1.0f / ((float)num);
	rad3 = sqrtf((float)num) / ((float)num);

	BLI_srand(31415926 + num);
	x = 0;
	for (i = 0; i < 2 * num; i += 2) {
		jitarr[i] = x + rad1 * (float)(0.5 - BLI_drand());
		jitarr[i + 1] = ((float)i / 2) / num + rad1 * (float)(0.5 - BLI_drand());
		x += rad3;
		x -= floorf(x);
	}

	for (i = 0; i < 24; i++) {
		BLI_jitterate1(jitarr, jit2, num, rad1);
		BLI_jitterate1(jitarr, jit2, num, rad1);
		BLI_jitterate2(jitarr, jit2, num, rad2);
	}

	MEM_freeN(jit2);
	
	/* finally, move jittertab to be centered around (0,0) */
	for (i = 0; i < 2 * num; i += 2) {
		jitarr[i] -= 0.5f;
		jitarr[i + 1] -= 0.5f;
	}
	
}