summaryrefslogtreecommitdiffstats
path: root/src/Noise/RidgedNoise.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-11-20 09:26:05 +0100
committerMattes D <github@xoft.cz>2014-11-20 09:26:05 +0100
commitf1bddc607c2e68cd9ef940c47403bb2948aad46d (patch)
tree9782ecbd191d4c8d9d082b23c2043adb2ac6a7d8 /src/Noise/RidgedNoise.h
parentMerge pull request #1598 from mc-server/SignEditor (diff)
parentcInterpolNoise: Implemented optimized 2D generating. (diff)
downloadcuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.gz
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.bz2
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.lz
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.xz
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.zst
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.zip
Diffstat (limited to 'src/Noise/RidgedNoise.h')
-rw-r--r--src/Noise/RidgedNoise.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/Noise/RidgedNoise.h b/src/Noise/RidgedNoise.h
new file mode 100644
index 000000000..69b480f60
--- /dev/null
+++ b/src/Noise/RidgedNoise.h
@@ -0,0 +1,91 @@
+
+// RidgedNoise.h
+
+// Implements the cRidgedNoise template class that generates ridged noise based on another noise provider.
+
+
+
+
+
+#pragma once
+
+
+
+
+
+template <typename N>
+class cRidgedNoise
+{
+public:
+ /** Creates a new instance with the seed set to 0. */
+ cRidgedNoise(void):
+ m_Noise(0)
+ {
+ }
+
+
+ /** Creates a new instance with the specified seed. */
+ cRidgedNoise(int a_Seed):
+ m_Noise(a_Seed)
+ {
+ }
+
+
+ /** Sets the seed for the underlying noise. */
+ void SetSeed(int a_Seed)
+ {
+ m_Noise.SetSeed(a_Seed);
+ }
+
+
+ /** Fills a 2D array with the values of the noise. */
+ void Generate2D(
+ NOISE_DATATYPE * a_Array, ///< Array to generate into [x + a_SizeX * y]
+ int a_SizeX, int a_SizeY, ///< Count of the array, in each direction
+ NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, ///< Noise-space coords of the array in the X direction
+ NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY ///< Noise-space coords of the array in the Y direction
+ ) const
+ {
+ int ArrayCount = a_SizeX * a_SizeY;
+ m_Noise.Generate2D(
+ a_Array, a_SizeX, a_SizeY,
+ a_StartX, a_EndX,
+ a_StartY, a_EndY
+ );
+ for (int i = 0; i < ArrayCount; i++)
+ {
+ a_Array[i] = fabs(a_Array[i]);
+ }
+ }
+
+
+ /** Fills a 3D array with the values of the noise. */
+ void Generate3D(
+ NOISE_DATATYPE * a_Array, ///< Array to generate into [x + a_SizeX * y + a_SizeX * a_SizeY * z]
+ int a_SizeX, int a_SizeY, int a_SizeZ, ///< Count of the array, in each direction
+ NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, ///< Noise-space coords of the array in the X direction
+ NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY, ///< Noise-space coords of the array in the Y direction
+ NOISE_DATATYPE a_StartZ, NOISE_DATATYPE a_EndZ ///< Noise-space coords of the array in the Z direction
+ ) const
+ {
+ int ArrayCount = a_SizeX * a_SizeY * a_SizeZ;
+ m_Noise.Generate2D(
+ a_Array, a_SizeX, a_SizeY, a_SizeZ,
+ a_StartX, a_EndX,
+ a_StartY, a_EndY,
+ a_StartZ, a_EndZ
+ );
+ for (int i = 0; i < ArrayCount; i++)
+ {
+ a_Array[i] = fabs(a_Array[i]);
+ }
+ }
+
+protected:
+ N m_Noise;
+} ;
+
+
+
+
+