Panda3D
Loading...
Searching...
No Matches
stackedPerlinNoise3.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file stackedPerlinNoise3.cxx
10 * @author drose
11 * @date 2005-10-05
12 */
13
14#include "stackedPerlinNoise3.h"
15
16/**
17 * Creates num_levels nested PerlinNoise3 objects. Each stacked Perlin object
18 * will have a scale of 1 scale_factor times the previous object (so that it
19 * is higher-frequency, if scale_factor > 1), and an amplitude of amp_scale
20 * times the previous object (so that it is less important, if amp_scale < 1).
21 */
23StackedPerlinNoise3(double sx, double sy, double sz, int num_levels,
24 double scale_factor, double amp_scale,
25 int table_size, unsigned long seed) {
26 _noises.reserve(num_levels);
27 double amp = 1.0;
28 for (int i = 0; i < num_levels; ++i) {
29 PerlinNoise3 noise(sx, sy, sz, table_size, seed);
30 add_level(noise, amp);
31
32 seed = noise.get_seed();
33 amp *= amp_scale;
34 sx /= scale_factor;
35 sy /= scale_factor;
36 sz /= scale_factor;
37 }
38}
39
40/**
41 * Creates an exact duplicate of the existing StackedPerlinNoise3 object,
42 * including the random seed.
43 */
46 _noises(copy._noises)
47{
48}
49
50/**
51 * Creates an exact duplicate of the existing StackedPerlinNoise3 object,
52 * including the random seed.
53 */
56 _noises = copy._noises;
57}
58
59/**
60 * Adds an arbitrary PerlinNoise3 object, and an associated amplitude, to the
61 * stack.
62 */
64add_level(const PerlinNoise3 &level, double amp) {
65 _noises.push_back(Noise());
66 Noise &n = _noises.back();
67 n._noise = level;
68 n._amp = amp;
69}
70
71/**
72 * Removes all levels from the stack. You must call add_level() again to
73 * restore them.
74 */
76clear() {
77 _noises.clear();
78}
79
80/**
81 * Returns the noise function of the three inputs.
82 */
84noise(const LVecBase3d &value) {
85 double result = 0.0;
86
87 Noises::iterator ni;
88 for (ni = _noises.begin(); ni != _noises.end(); ++ni) {
89 result += (*ni)._noise(value) * (*ni)._amp;
90 }
91
92 return result;
93}
This class provides an implementation of Perlin noise for 3 variables.
Implements a multi-layer PerlinNoise, with one or more high-frequency noise functions added to a lowe...
StackedPerlinNoise3()
Creates a StackedPerlinNoise3 object with no levels.
void clear()
Removes all levels from the stack.
void operator=(const StackedPerlinNoise3 &copy)
Creates an exact duplicate of the existing StackedPerlinNoise3 object, including the random seed.
void add_level(const PerlinNoise3 &level, double amp=1.0)
Adds an arbitrary PerlinNoise3 object, and an associated amplitude, to the stack.
double noise(double x, double y, double z)
Returns the noise function of the three inputs.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.