Graphics Reference
In-Depth Information
#define FP11 -2.5
#define FP12 2.0
#define FP13 -0.5
#define FP20 -0.5
#define FP21 0.0
#define FP22 0.5
#define FP23 0.0
#define FP30 0.0
#define FP31 1.0
#define FP32 0.0
#define FP33 0.0
/*
¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼
*/
float spline(float u,float *knots)
{
float c3,c2,c1,c0;
c3
¼
FP00*knots[0]
þ
FP01*knots[1]
þ
FP02*knots[2]
þ
FP03*knots[3];
c2
¼
FP10*knots[0]
þ
FP11*knots[1]
þ
FP12*knots[2]
þ
FP13*knots[3];
c1
¼
FP20*knots[0]
þ
FP21*knots[1]
þ
FP22*knots[2]
þ
FP23*knots[3];
c0
¼
FP30*knots[0]
þ
FP31*knots[1]
þ
FP32*knots[2]
þ
FP33*knots[3];
return ((c3*u
þ
c2)*u
þ
c1)*u
þ
c0;
}
B.6.2
Turbulence
Turbulence is a stochastic function with a “fractal” power spectrum [
3
]. The function is a sum of
amplitude-varying frequencies. As frequency increases, the amplitude decreases.
/* TURBULENCE */
float turbulence (float x, float y, float z)
{
float f;
float value
¼
0;
for (f
¼
MINFREQ; f
<
MAXFREQ; f *
¼
2) value
þ¼
fabs(noise(x*f, y*f, z*f))/f;
return value;
}
B.6.3
Random number generator
This random number generator returns a random number in the range 0 to 999999999. An auxiliary
routine would map this number into an arbitrary range of integers.
int r[100]; /* “global” pseudorandom table -- */
/* must be visible to rand and init_rand */
/*
¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼
*/
/* RAND */
/* return a random number in the range 0 to 999999999 */
int rand (void)
{
Search WWH ::
Custom Search