48#include "SDL_thread.h"
60#define SIMPLEX_SCALE 0.5f
67 unsigned char map[256];
70#define SWAP(a, b, t) (t) = (a); (a) = (b); (b) = (t)
71#define FLOOR(a) ((int)(a) - ((a) < 0 && (a) != (int)(a)))
83 pdata = calloc(
sizeof(perlin_data_t),1);
87 pdata->map[i] = (
unsigned char)i;
91 SWAP(pdata->map[i], pdata->map[j], tmp);
97#define NOISE_SIMPLEX_GRADIENT_1D(n,h,x) { float grad; h &= 0xF; grad=1.0f+(h & 7); if ( h & 8 ) grad = -grad; n = grad * x; }
107 int i0 = (int)
FLOOR( f[0]*SIMPLEX_SCALE );
109 float x0 = f[0]*SIMPLEX_SCALE - i0;
110 float x1 = x0 - 1.0f;
111 float t0 = 1.0f - x0*x0;
112 float t1 = 1.0f - x1*x1;
117 i0 = pdata->map[i0&0xFF];
118 NOISE_SIMPLEX_GRADIENT_1D( n0, i0, x0 );
120 i1 = pdata->map[i1&0xFF];
121 NOISE_SIMPLEX_GRADIENT_1D( n1, i1, x1 );
124 return 0.25f * (n0+n1);
Header file with generic functions and naev-specifics.
perlin_data_t * noise_new(void)
Creates a new perlin noise generator.
void noise_delete(perlin_data_t *pdata)
Frees some noise data.
float noise_simplex1(perlin_data_t *pdata, float f[1])
Gets 1D simplex noise for a position.
Structure used for generating noise.