Graphics Reference
In-Depth Information
{
float *table
¼
valueTab;
int i;
srand(seed);
for (i
¼
0; i
<
TABSIZE; i
þþ
)
*(table
þþ
)
¼
1.0 -2.0*RANDNBR;
}
/*
¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼
*/
/* LATTICE function */
/* returns a value corresponding to the lattice point */
float lattice(int ix, int iy, int iz)
{
return valueTab[INDEX(ix,iy,iz)];
}
/*
¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼
*/
/* NOISE function */
float noise(float x, float y, float z)
{
int ix,iy,iz;
int i,j,k;
float fx,fy,fz;
float xknots[4],yknots[4],zknots[4];
static int initialized
¼
0;
if (!initialized) {
valueTableInit(665);
initialized
¼
1;
}
ix
¼
FLOOR(x);
fx
¼
x - ix;
iy
¼
FLOOR(y);
fy
¼
y - iy;
iz
¼
FLOOR(z);
fz
¼
z-iz;
for (k
¼
-1; k
<¼
2; k
þþ
){
for (j
¼
-1; j
<¼
2; j
þþ
){
for (i
¼
-1; i
<¼
2; i
þþ
)[i
þ
1]
¼
lattice(ix
þ
i,iy
þ
j,iz
þ
k);
yknots[j
þ
1]
¼
spline(fx,xknots);
}
zknots[k
þ
1]
¼
spline(fy,yknots);
}
return spline(fz,zknots);
}
#define FP00 -0.5
#define FP01 1.5
#define FP02 -1.5
#define FP03 0.5
#define FP10 1.0
Search WWH ::
Custom Search