2015-06-01 17:21:51 +10:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2015 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __UTIL_NOISE_FRACTAL_FBM_IPP
|
|
|
|
#error
|
|
|
|
#endif
|
|
|
|
#define __UTIL_NOISE_FRACTAL_FBM_IPP
|
|
|
|
|
|
|
|
#include "../../debug.hpp"
|
|
|
|
|
|
|
|
namespace util { namespace noise { namespace fractal {
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T, typename B>
|
|
|
|
fbm<T,B>::fbm (unsigned _octaves,
|
2015-06-02 00:15:02 +10:00
|
|
|
T _H,
|
2015-06-01 17:21:51 +10:00
|
|
|
T _frequency,
|
|
|
|
T _lacunarity,
|
|
|
|
T _amplitude,
|
|
|
|
T _gain,
|
|
|
|
seed_t _seed):
|
|
|
|
seed (_seed),
|
|
|
|
octaves (_octaves),
|
2015-06-02 00:15:02 +10:00
|
|
|
H (_H),
|
2015-06-01 17:21:51 +10:00
|
|
|
frequency (_frequency),
|
|
|
|
lacunarity (_lacunarity),
|
|
|
|
amplitude (_amplitude),
|
|
|
|
gain (_gain),
|
2015-06-02 00:15:02 +10:00
|
|
|
basis (_seed),
|
|
|
|
invAH (std::pow (amplitude, -H)),
|
|
|
|
invGH (std::pow (gain, H))
|
2015-06-01 17:21:51 +10:00
|
|
|
{
|
|
|
|
CHECK_NEQ (octaves, 0);
|
|
|
|
CHECK_NEQ (frequency, 0);
|
|
|
|
CHECK_NEQ (amplitude, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename T, typename B>
|
|
|
|
fbm<T,B>::fbm ():
|
|
|
|
fbm<T,B> (DEFAULT_OCTAVES,
|
2015-06-02 00:15:02 +10:00
|
|
|
DEFAULT_H,
|
2015-06-01 17:21:51 +10:00
|
|
|
DEFAULT_FREQUENCY,
|
|
|
|
DEFAULT_LACUNARITY,
|
|
|
|
DEFAULT_AMPLITUDE,
|
|
|
|
DEFAULT_GAIN,
|
|
|
|
rand ())
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename T, typename B>
|
2015-06-01 18:45:47 +10:00
|
|
|
constexpr T
|
2015-06-01 17:21:51 +10:00
|
|
|
fbm<T,B>::operator() (util::point<2,T> p) const
|
|
|
|
{
|
|
|
|
T total = 0;
|
|
|
|
T f = frequency;
|
2015-06-02 00:15:02 +10:00
|
|
|
T a = invAH;
|
2015-06-01 17:21:51 +10:00
|
|
|
|
|
|
|
for (size_t i = 0; i < octaves; ++i) {
|
|
|
|
total += basis (p * f) * a;
|
|
|
|
|
|
|
|
f *= lacunarity;
|
2015-06-02 00:15:02 +10:00
|
|
|
a *= invGH;
|
2015-06-01 17:21:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
} } }
|