diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-11 23:06:03 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-11 23:06:03 +0200 |
commit | 8d0b607feb2f03bab504b74347510247963b3ff9 (patch) | |
tree | f75cf09b3a52371b3db9ae52e61c693f827385e9 /source/Noise.cpp | |
parent | ProtoProxy: updated the protocol support help text. (diff) | |
download | cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.tar cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.tar.gz cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.tar.bz2 cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.tar.lz cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.tar.xz cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.tar.zst cuberite-8d0b607feb2f03bab504b74347510247963b3ff9.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Noise.cpp | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/source/Noise.cpp b/source/Noise.cpp index ff90fd2a7..fb369c6a0 100644 --- a/source/Noise.cpp +++ b/source/Noise.cpp @@ -722,7 +722,7 @@ void cCubicNoise::CalcFloorFrac( ) const { NOISE_DATATYPE val = a_Start; - NOISE_DATATYPE dif = (a_End - a_Start) / a_Size; + NOISE_DATATYPE dif = (a_End - a_Start) / (a_Size - 1); for (int i = 0; i < a_Size; i++) { a_Floor[i] = FAST_FLOOR(val); @@ -853,3 +853,66 @@ void cPerlinNoise::Generate2D( + +void cPerlinNoise::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 + NOISE_DATATYPE * a_Workspace ///< Workspace that this function can use and trash +) const +{ + if (m_Octaves.empty()) + { + // No work to be done + return; + } + + bool ShouldFreeWorkspace = (a_Workspace == NULL); + int ArrayCount = a_SizeX * a_SizeY * a_SizeZ; + if (ShouldFreeWorkspace) + { + a_Workspace = new NOISE_DATATYPE[ArrayCount]; + } + + // Generate the first octave directly into array: + m_Octaves.front().m_Noise.Generate3D( + a_Workspace, a_SizeX, a_SizeY, a_SizeZ, + a_StartX * m_Octaves.front().m_Frequency, a_EndX * m_Octaves.front().m_Frequency, + a_StartY * m_Octaves.front().m_Frequency, a_EndY * m_Octaves.front().m_Frequency, + a_StartZ * m_Octaves.front().m_Frequency, a_EndZ * m_Octaves.front().m_Frequency + ); + NOISE_DATATYPE Amplitude = m_Octaves.front().m_Amplitude; + for (int i = 0; i < ArrayCount; i++) + { + a_Array[i] = a_Workspace[i] * Amplitude; + } + + // Add each octave: + for (cOctaves::const_iterator itr = m_Octaves.begin() + 1, end = m_Octaves.end(); itr != end; ++itr) + { + // Generate cubic noise for the octave: + itr->m_Noise.Generate3D( + a_Workspace, a_SizeX, a_SizeY, a_SizeZ, + a_StartX * itr->m_Frequency, a_EndX * itr->m_Frequency, + a_StartY * itr->m_Frequency, a_EndY * itr->m_Frequency, + a_StartZ * itr->m_Frequency, a_EndZ * itr->m_Frequency + ); + // Add the cubic noise into the output: + NOISE_DATATYPE Amplitude = itr->m_Amplitude; + for (int i = 0; i < ArrayCount; i++) + { + a_Array[i] += a_Workspace[i] * Amplitude; + } + } + + if (ShouldFreeWorkspace) + { + delete[] a_Workspace; + } +} + + + + |