6 #define FAST_FLOOR(x) (((x) < 0) ? ((static_cast<int>(x)) - 1) : (static_cast<int>(x)))
16 static class cImprovedPerlinNoiseTest
19 cImprovedPerlinNoiseTest(
void)
21 printf(
"Performing Improved Perlin Noise tests...\n");
25 printf(
"Improved Perlin Noise tests complete.\n");
32 static const int SIZE_X = 256;
33 static const int SIZE_Y = 256;
34 static const int SIZE_Z = 16;
37 std::unique_ptr<NOISE_DATATYPE[]> arr(
new NOISE_DATATYPE[SIZE_X * SIZE_Y * SIZE_Z]);
38 noise.
Generate3D(arr.get(), SIZE_X, SIZE_Y, SIZE_Z, 0, 14, 0, 14, 0, 14);
39 Debug3DNoise(arr.get(), SIZE_X, SIZE_Y, SIZE_Z,
"ImprovedPerlinNoiseTest3D", 128);
40 noise.
Generate2D(arr.get(), SIZE_X, SIZE_Y, 0, 14, 15, 28);
41 Debug2DNoise(arr.get(), SIZE_X, SIZE_Y,
"ImprovedPerlinNoiseTest2D", 128);
54 long long start = timer.GetNowTime();
55 for (
int i = 0; i < 100000000; i++)
59 long long finish = timer.GetNowTime();
60 printf(
"cImprovedNoise took %.2f seconds; total is %f.\n",
static_cast<float>(finish - start) / 1000.0f, sum);
64 start = timer.GetNowTime();
65 for (
int i = 0; i < 100000000; i++)
69 finish = timer.GetNowTime();
70 printf(
"cCubicNoise took %.2f seconds; total is %f.\n",
static_cast<float>(finish - start) / 1000.0f, sum);
75 void TestSpeedArr(
void)
77 static const int SIZE_X = 256;
78 static const int SIZE_Y = 256;
79 static const int SIZE_Z = 16;
81 std::unique_ptr<NOISE_DATATYPE[]> arr(
new NOISE_DATATYPE[SIZE_X * SIZE_Y * SIZE_Z]);
87 long long start = timer.GetNowTime();
88 for (
int i = 0; i < 40; i++)
90 improvedNoise.
Generate3D(arr.get(), SIZE_X, SIZE_Y, SIZE_Z, 0, 14, 0, 14, 0, 14);
92 long long finish = timer.GetNowTime();
93 printf(
"cImprovedNoise(arr) took %.2f seconds.\n",
static_cast<float>(finish - start) / 1000.0f);
96 start = timer.GetNowTime();
97 for (
int i = 0; i < 40; i++)
99 cubicNoise.
Generate3D(arr.get(), SIZE_X, SIZE_Y, SIZE_Z, 0, 14, 0, 14, 0, 14);
101 finish = timer.GetNowTime();
102 printf(
"cCubicNoise(arr) took %.2f seconds.\n",
static_cast<float>(finish - start) / 1000.0f);
117 const int BUF_SIZE = 512;
118 ASSERT(a_SizeX <= BUF_SIZE);
122 if (f1.
Open(fmt::format(FMT_STRING(
"{}_XY ({}).grab"), a_FileNameBase, a_SizeX),
cFile::fmWrite))
124 for (
size_t z = 0; z < a_SizeZ; z++)
126 for (
size_t y = 0; y < a_SizeY; y++)
128 size_t idx = y * a_SizeX + z * a_SizeX * a_SizeY;
129 unsigned char buf[BUF_SIZE];
130 for (
size_t x = 0; x < a_SizeX; x++)
132 buf[x] =
static_cast<unsigned char>(
Clamp(
static_cast<int>(128 + a_Coeff * a_Noise[idx++]), 0, 255));
134 f1.
Write(buf, a_SizeX);
136 unsigned char buf[BUF_SIZE];
137 memset(buf, 0, a_SizeX);
138 f1.
Write(buf, a_SizeX);
143 if (f2.
Open(fmt::format(FMT_STRING(
"{}_XZ ({}).grab"), a_FileNameBase, a_SizeX),
cFile::fmWrite))
145 for (
size_t y = 0; y < a_SizeY; y++)
147 for (
size_t z = 0; z < a_SizeZ; z++)
149 size_t idx = y * a_SizeX + z * a_SizeX * a_SizeY;
150 unsigned char buf[BUF_SIZE];
151 for (
size_t x = 0; x < a_SizeX; x++)
153 buf[x] =
static_cast<unsigned char>(
Clamp(
static_cast<int>(128 + a_Coeff * a_Noise[idx++]), 0, 255));
155 f2.
Write(buf, a_SizeX);
157 unsigned char buf[BUF_SIZE];
158 memset(buf, 0, a_SizeX);
159 f2.
Write(buf, a_SizeX);
170 const int BUF_SIZE = 512;
171 ASSERT(a_SizeX <= BUF_SIZE);
174 if (f1.
Open(fmt::format(FMT_STRING(
"{} ({}).grab"), a_FileNameBase, a_SizeX),
cFile::fmWrite))
176 for (
size_t y = 0; y < a_SizeY; y++)
178 size_t idx = y * a_SizeX;
179 unsigned char buf[BUF_SIZE];
180 for (
size_t x = 0; x < a_SizeX; x++)
182 buf[x] =
static_cast<unsigned char>(
Clamp(
static_cast<int>(128 + a_Coeff * a_Noise[idx++]), 0, 255));
184 f1.
Write(buf, a_SizeX);
202 int a_SizeX,
int a_SizeY,
209 int a_FromX,
int a_ToX,
210 int a_FromY,
int a_ToY
217 void Move(
int a_NewFloorX,
int a_NewFloorY);
243 int a_SizeX,
int a_SizeY,
248 m_WorkRnds(&m_Workspace1),
264 int a_FromX,
int a_ToX,
265 int a_FromY,
int a_ToY
268 for (
int y = a_FromY; y < a_ToY; y++)
276 int idx = y *
m_SizeX + a_FromX;
277 for (
int x = a_FromX; x < a_ToX; x++)
292 for (
int x = 0; x < 4; x++)
294 int cx = a_FloorX + x - 1;
295 for (
int y = 0; y < 4; y++)
297 int cy = a_FloorY + y - 1;
316 int DiffX = OldFloorX - a_NewFloorX;
317 int DiffY = OldFloorY - a_NewFloorY;
318 for (
int x = 0; x < 4; x++)
320 int cx = a_NewFloorX + x - 1;
321 int OldX = x - DiffX;
322 for (
int y = 0; y < 4; y++)
324 int cy = a_NewFloorY + y - 1;
325 int OldY = y - DiffY;
326 if ((OldX >= 0) && (OldX < 4) && (OldY >= 0) && (OldY < 4))
328 (*m_WorkRnds)[x][y] = (*OldWorkRnds)[OldX][OldY];
353 int a_SizeX,
int a_SizeY,
int a_SizeZ,
361 int a_FromX,
int a_ToX,
362 int a_FromY,
int a_ToY,
363 int a_FromZ,
int a_ToZ
367 void InitWorkRnds(
int a_FloorX,
int a_FloorY,
int a_FloorZ);
370 void Move(
int a_NewFloorX,
int a_NewFloorY,
int a_NewFloorZ);
398 int a_SizeX,
int a_SizeY,
int a_SizeZ,
404 m_WorkRnds(&m_Workspace1),
423 int a_FromX,
int a_ToX,
424 int a_FromY,
int a_ToY,
425 int a_FromZ,
int a_ToZ
428 for (
int z = a_FromZ; z < a_ToZ; z++)
433 for (
int x = 0; x < 4; x++)
435 for (
int y = 0; y < 4; y++)
440 for (
int y = a_FromY; y < a_ToY; y++)
448 int idx = idxZ + y *
m_SizeX + a_FromX;
449 for (
int x = a_FromX; x < a_ToX; x++)
466 for (
int x = 0; x < 4; x++)
468 int cx = a_FloorX + x - 1;
469 for (
int y = 0; y < 4; y++)
471 int cy = a_FloorY + y - 1;
472 for (
int z = 0; z < 4; z++)
474 int cz = a_FloorZ + z - 1;
495 int DiffX = OldFloorX - a_NewFloorX;
496 int DiffY = OldFloorY - a_NewFloorY;
497 int DiffZ = OldFloorZ - a_NewFloorZ;
498 for (
int x = 0; x < 4; x++)
500 int cx = a_NewFloorX + x - 1;
501 int OldX = x - DiffX;
502 for (
int y = 0; y < 4; y++)
504 int cy = a_NewFloorY + y - 1;
505 int OldY = y - DiffY;
506 for (
int z = 0; z < 4; z++)
508 int cz = a_NewFloorZ + z - 1;
509 int OldZ = z - DiffZ;
510 if ((OldX >= 0) && (OldX < 4) && (OldY >= 0) && (OldY < 4) && (OldZ >= 0) && (OldZ < 4))
512 (*m_WorkRnds)[x][y][z] = (*OldWorkRnds)[OldX][OldY][OldZ];
543 m_Seed(a_Noise.m_Seed)
629 {
IntNoise3D(BaseX - 1, BaseY - 1, BaseZ - 1),
IntNoise3D(BaseX, BaseY - 1, BaseZ - 1),
IntNoise3D(BaseX + 1, BaseY - 1, BaseZ - 1),
IntNoise3D(BaseX + 2, BaseY - 1, BaseZ - 1), },
630 {
IntNoise3D(BaseX - 1, BaseY, BaseZ - 1),
IntNoise3D(BaseX, BaseY, BaseZ - 1),
IntNoise3D(BaseX + 1, BaseY, BaseZ - 1),
IntNoise3D(BaseX + 2, BaseY, BaseZ - 1), },
631 {
IntNoise3D(BaseX - 1, BaseY + 1, BaseZ - 1),
IntNoise3D(BaseX, BaseY + 1, BaseZ - 1),
IntNoise3D(BaseX + 1, BaseY + 1, BaseZ - 1),
IntNoise3D(BaseX + 2, BaseY + 1, BaseZ - 1), },
632 {
IntNoise3D(BaseX - 1, BaseY + 2, BaseZ - 1),
IntNoise3D(BaseX, BaseY + 2, BaseZ - 1),
IntNoise3D(BaseX + 1, BaseY + 2, BaseZ - 1),
IntNoise3D(BaseX + 2, BaseY + 2, BaseZ - 1), },
643 {
IntNoise3D(BaseX - 1, BaseY - 1, BaseZ),
IntNoise3D(BaseX, BaseY - 1, BaseZ),
IntNoise3D(BaseX + 1, BaseY - 1, BaseZ),
IntNoise3D(BaseX + 2, BaseY - 1, BaseZ), },
644 {
IntNoise3D(BaseX - 1, BaseY, BaseZ),
IntNoise3D(BaseX, BaseY, BaseZ),
IntNoise3D(BaseX + 1, BaseY, BaseZ),
IntNoise3D(BaseX + 2, BaseY, BaseZ), },
645 {
IntNoise3D(BaseX - 1, BaseY + 1, BaseZ),
IntNoise3D(BaseX, BaseY + 1, BaseZ),
IntNoise3D(BaseX + 1, BaseY + 1, BaseZ),
IntNoise3D(BaseX + 2, BaseY + 1, BaseZ), },
646 {
IntNoise3D(BaseX - 1, BaseY + 2, BaseZ),
IntNoise3D(BaseX, BaseY + 2, BaseZ),
IntNoise3D(BaseX + 1, BaseY + 2, BaseZ),
IntNoise3D(BaseX + 2, BaseY + 2, BaseZ), },
656 {
IntNoise3D(BaseX - 1, BaseY - 1, BaseZ + 1),
IntNoise3D(BaseX, BaseY - 1, BaseZ + 1),
IntNoise3D(BaseX + 1, BaseY - 1, BaseZ + 1),
IntNoise3D(BaseX + 2, BaseY - 1, BaseZ + 1), },
657 {
IntNoise3D(BaseX - 1, BaseY, BaseZ + 1),
IntNoise3D(BaseX, BaseY, BaseZ + 1),
IntNoise3D(BaseX + 1, BaseY, BaseZ + 1),
IntNoise3D(BaseX + 2, BaseY, BaseZ + 1), },
658 {
IntNoise3D(BaseX - 1, BaseY + 1, BaseZ + 1),
IntNoise3D(BaseX, BaseY + 1, BaseZ + 1),
IntNoise3D(BaseX + 1, BaseY + 1, BaseZ + 1),
IntNoise3D(BaseX + 2, BaseY + 1, BaseZ + 1), },
659 {
IntNoise3D(BaseX - 1, BaseY + 2, BaseZ + 1),
IntNoise3D(BaseX, BaseY + 2, BaseZ + 1),
IntNoise3D(BaseX + 1, BaseY + 2, BaseZ + 1),
IntNoise3D(BaseX + 2, BaseY + 2, BaseZ + 1), },
669 {
IntNoise3D(BaseX - 1, BaseY - 1, BaseZ + 2),
IntNoise3D(BaseX, BaseY - 1, BaseZ + 2),
IntNoise3D(BaseX + 1, BaseY - 1, BaseZ + 2),
IntNoise3D(BaseX + 2, BaseY - 1, BaseZ + 2), },
670 {
IntNoise3D(BaseX - 1, BaseY, BaseZ + 2),
IntNoise3D(BaseX, BaseY, BaseZ + 2),
IntNoise3D(BaseX + 1, BaseY, BaseZ + 2),
IntNoise3D(BaseX + 2, BaseY, BaseZ + 2), },
671 {
IntNoise3D(BaseX - 1, BaseY + 1, BaseZ + 2),
IntNoise3D(BaseX, BaseY + 1, BaseZ + 2),
IntNoise3D(BaseX + 1, BaseY + 1, BaseZ + 2),
IntNoise3D(BaseX + 2, BaseY + 1, BaseZ + 2), },
672 {
IntNoise3D(BaseX - 1, BaseY + 2, BaseZ + 2),
IntNoise3D(BaseX, BaseY + 2, BaseZ + 2),
IntNoise3D(BaseX + 1, BaseY + 2, BaseZ + 2),
IntNoise3D(BaseX + 2, BaseY + 2, BaseZ + 2), },
708 int a_SizeX,
int a_SizeY,
717 ASSERT(a_StartX < a_EndX);
718 ASSERT(a_StartY < a_EndY);
727 int NumSameX, NumSameY;
728 CalcFloorFrac(a_SizeX, a_StartX, a_EndX, FloorX, FracX, SameX, NumSameX);
729 CalcFloorFrac(a_SizeY, a_StartY, a_EndY, FloorY, FracY, SameY, NumSameY);
737 for (
int y = 0; y < NumSameY; y++)
739 int ToY = FromY + SameY[y];
741 int CurFloorY = FloorY[FromY];
742 for (
int x = 0; x < NumSameX; x++)
744 int ToX = FromX + SameX[x];
745 Cell.
Generate(FromX, ToX, FromY, ToY);
746 Cell.
Move(FloorX[ToX], CurFloorY);
749 Cell.
Move(FloorX[0], FloorY[ToY]);
760 int a_SizeX,
int a_SizeY,
int a_SizeZ,
769 ASSERT(a_StartX < a_EndX);
770 ASSERT(a_StartY < a_EndY);
771 ASSERT(a_StartZ < a_EndZ);
783 int NumSameX, NumSameY, NumSameZ;
784 CalcFloorFrac(a_SizeX, a_StartX, a_EndX, FloorX, FracX, SameX, NumSameX);
785 CalcFloorFrac(a_SizeY, a_StartY, a_EndY, FloorY, FracY, SameY, NumSameY);
786 CalcFloorFrac(a_SizeZ, a_StartZ, a_EndZ, FloorZ, FracZ, SameZ, NumSameZ);
790 a_SizeX, a_SizeY, a_SizeZ,
798 for (
int z = 0; z < NumSameZ; z++)
800 int ToZ = FromZ + SameZ[z];
801 int CurFloorZ = FloorZ[FromZ];
803 for (
int y = 0; y < NumSameY; y++)
805 int ToY = FromY + SameY[y];
806 int CurFloorY = FloorY[FromY];
808 for (
int x = 0; x < NumSameX; x++)
810 int ToX = FromX + SameX[x];
811 Cell.
Generate(FromX, ToX, FromY, ToY, FromZ, ToZ);
812 Cell.
Move(FloorX[ToX], CurFloorY, CurFloorZ);
815 Cell.
Move(FloorX[0], FloorY[ToY], CurFloorZ);
818 Cell.
Move(FloorX[0], FloorY[0], FloorZ[ToZ]);
831 int * a_Same,
int & a_NumSame
838 for (
int i = 0; i < a_Size; i++)
841 a_Frac[i] = val - a_Floor[i];
846 int CurFloor = a_Floor[0];
849 for (
int i = 1; i < a_Size; i++)
851 if (a_Floor[i] != CurFloor)
853 a_Same[a_NumSame] = i - LastSame;
856 CurFloor = a_Floor[i];
859 if (LastSame < a_Size)
861 a_Same[a_NumSame] = a_Size - LastSame;
876 for (
int i = 0; i < 256; i++)
883 for (
int i = 0; i < 256; i++)
890 for (
int i = 0; i < 256; i++)
902 int a_SizeX,
int a_SizeY,
908 for (
int y = 0; y < a_SizeY; y++)
913 int yCoord = noiseYInt & 255;
916 for (
int x = 0; x < a_SizeX; x++)
921 int xCoord = noiseXInt & 255;
926 int A =
m_Perm[xCoord] + yCoord;
929 int B =
m_Perm[xCoord + 1] + yCoord;
934 a_Array[idx++] =
Lerp(
949 int a_SizeX,
int a_SizeY,
int a_SizeZ,
956 for (
int z = 0; z < a_SizeZ; z++)
961 int zCoord = noiseZInt & 255;
964 for (
int y = 0; y < a_SizeY; y++)
969 int yCoord = noiseYInt & 255;
972 for (
int x = 0; x < a_SizeX; x++)
977 int xCoord = noiseXInt & 255;
982 int A =
m_Perm[xCoord] + yCoord;
983 int AA =
m_Perm[A] + zCoord;
984 int AB =
m_Perm[A + 1] + zCoord;
985 int B =
m_Perm[xCoord + 1] + yCoord;
986 int BA =
m_Perm[B] + zCoord;
987 int BB =
m_Perm[B + 1] + zCoord;
991 a_Array[idx++] =
Lerp(
993 Lerp(
Grad(
m_Perm[AA], noiseXFrac, noiseYFrac, noiseZFrac),
Grad(
m_Perm[BA], noiseXFrac - 1, noiseYFrac, noiseZFrac), fadeX),
994 Lerp(
Grad(
m_Perm[AB], noiseXFrac, noiseYFrac - 1, noiseZFrac),
Grad(
m_Perm[BB], noiseXFrac - 1, noiseYFrac - 1, noiseZFrac), fadeX),
998 Lerp(
Grad(
m_Perm[AA + 1], noiseXFrac, noiseYFrac, noiseZFrac - 1),
Grad(
m_Perm[BA + 1], noiseXFrac - 1, noiseYFrac, noiseZFrac - 1), fadeX),
999 Lerp(
Grad(
m_Perm[AB + 1], noiseXFrac, noiseYFrac - 1, noiseZFrac - 1),
Grad(
m_Perm[BB + 1], noiseXFrac - 1, noiseYFrac - 1, noiseZFrac - 1), fadeX),
1019 int A =
m_Perm[a_X] + a_Y;
1020 int AA =
m_Perm[A] + a_Z;
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
void Debug2DNoise(const NOISE_DATATYPE *a_Noise, size_t a_SizeX, size_t a_SizeY, const AString &a_FileNameBase, NOISE_DATATYPE a_Coeff)
Exports the noise array into a file.
void Debug3DNoise(const NOISE_DATATYPE *a_Noise, size_t a_SizeX, size_t a_SizeY, size_t a_SizeZ, const AString &a_FileNameBase, NOISE_DATATYPE a_Coeff)
Exports the noise array into a set of files, ordered by XY and XZ.
NOISE_DATATYPE Lerp(NOISE_DATATYPE a_Val1, NOISE_DATATYPE a_Val2, NOISE_DATATYPE a_Ratio)
Linearly interpolates between two values.
float NOISE_DATATYPE
The datatype used by all the noise generators.
void InitWorkRnds(int a_FloorX, int a_FloorY)
Initializes m_WorkRnds[] with the specified Floor values.
NOISE_DATATYPE Workspace[4][4]
const NOISE_DATATYPE * m_FracY
Workspace m_Workspace2
Buffer 2 for workspace doublebuffering, used in Move()
void Generate(int a_FromX, int a_ToX, int a_FromY, int a_ToY)
Uses current m_WorkRnds[] to generate part of the array.
cCubicCell2D(const cNoise &a_Noise, NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, const NOISE_DATATYPE *a_FracX, const NOISE_DATATYPE *a_FracY)
Workspace m_Workspace1
Buffer 1 for workspace doublebuffering, used in Move()
void Move(int a_NewFloorX, int a_NewFloorY)
Updates m_WorkRnds[] for the new Floor values.
const NOISE_DATATYPE * m_FracX
Workspace * m_WorkRnds
The current random values; points to either m_Workspace1 or m_Workspace2 (doublebuffering)
Workspace * m_WorkRnds
The current random values; points to either m_Workspace1 or m_Workspace2 (doublebuffering)
void Move(int a_NewFloorX, int a_NewFloorY, int a_NewFloorZ)
Updates m_WorkRnds[] for the new Floor values.
const NOISE_DATATYPE * m_FracX
Workspace m_Workspace2
Buffer 2 for workspace doublebuffering, used in Move()
cCubicCell3D(const cNoise &a_Noise, NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, const NOISE_DATATYPE *a_FracX, const NOISE_DATATYPE *a_FracY, const NOISE_DATATYPE *a_FracZ)
Workspace m_Workspace1
Buffer 1 for workspace doublebuffering, used in Move()
void InitWorkRnds(int a_FloorX, int a_FloorY, int a_FloorZ)
Initializes m_WorkRnds[] with the specified Floor values.
const NOISE_DATATYPE * m_FracY
NOISE_DATATYPE Workspace[4][4][4]
const NOISE_DATATYPE * m_FracZ
void Generate(int a_FromX, int a_ToX, int a_FromY, int a_ToY, int a_FromZ, int a_ToZ)
Uses current m_WorkRnds[] to generate part of the array.
static NOISE_DATATYPE CubicInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_C, NOISE_DATATYPE a_D, NOISE_DATATYPE a_Pct)
int IntNoise1DInt(int a_X) const
static NOISE_DATATYPE CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct)
NOISE_DATATYPE CosineNoise1D(NOISE_DATATYPE a_X) const
NOISE_DATATYPE CubicNoise2D(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y) const
NOISE_DATATYPE IntNoise2D(int a_X, int a_Y) const
NOISE_DATATYPE CubicNoise3D(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const
NOISE_DATATYPE SmoothNoise1D(int a_X) const
static NOISE_DATATYPE LinearInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct)
NOISE_DATATYPE LinearNoise1D(NOISE_DATATYPE a_X) const
NOISE_DATATYPE IntNoise3D(int a_X, int a_Y, int a_Z) const
NOISE_DATATYPE IntNoise1D(int a_X) const
NOISE_DATATYPE CubicNoise1D(NOISE_DATATYPE a_X) const
void Generate3D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY, NOISE_DATATYPE a_StartZ, NOISE_DATATYPE a_EndZ) const
Fills a 3D array with the values of the noise.
cNoise m_Noise
Noise used for integral random values.
cCubicNoise(int a_Seed)
Creates a new instance with the specified seed.
void CalcFloorFrac(int a_Size, NOISE_DATATYPE a_Start, NOISE_DATATYPE a_End, int *a_Floor, NOISE_DATATYPE *a_Frac, int *a_Same, int &a_NumSame) const
Calculates the integral and fractional parts along one axis.
void Generate2D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY) const
Fills a 2D array with the values of the noise.
static const int MAX_SIZE
Maximum size of each dimension of the query arrays.
Improved noise, as described by Ken Perlin: https://mrl.nyu.edu/~perlin/paper445.pdf Implementation a...
void Generate3D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY, NOISE_DATATYPE a_StartZ, NOISE_DATATYPE a_EndZ) const
Fills a 3D array with the values of the noise.
cImprovedNoise(int a_Seed)
Constructs a new instance of the noise obbject.
NOISE_DATATYPE GetValueAt(int a_X, int a_Y, int a_Z)
Returns the value at the specified integral coords.
static NOISE_DATATYPE Fade(NOISE_DATATYPE a_T)
Calculates the fade curve, 6 * t^5 - 15 * t^4 + 10 * t^3.
int m_Perm[512]
The permutation table used by the noise function.
void Generate2D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY) const
Fills a 2D array with the values of the noise.
static NOISE_DATATYPE Grad(int a_Hash, NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z)
Returns the gradient value based on the hash.
bool Open(const AString &iFileName, eMode iMode)
int Write(const void *a_Buffer, size_t a_NumBytes)
Writes up to a_NumBytes bytes from a_Buffer, returns the number of bytes actually written,...