Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
OctaveGenerator.java
1 package org.bukkit.util.noise;
2 
3 /**
4  * Creates noise using unbiased octaves
5  */
6 public abstract class OctaveGenerator {
7  protected final NoiseGenerator[] octaves;
8  protected double xScale = 1;
9  protected double yScale = 1;
10  protected double zScale = 1;
11 
12  protected OctaveGenerator(NoiseGenerator[] octaves) {
13  this.octaves = octaves;
14  }
15 
16  /**
17  * Sets the scale used for all coordinates passed to this generator.
18  * <p>
19  * This is the equivalent to setting each coordinate to the specified
20  * value.
21  *
22  * @param scale New value to scale each coordinate by
23  */
24  public void setScale(double scale) {
25  setXScale(scale);
26  setYScale(scale);
27  setZScale(scale);
28  }
29 
30  /**
31  * Gets the scale used for each X-coordinates passed
32  *
33  * @return X scale
34  */
35  public double getXScale() {
36  return xScale;
37  }
38 
39  /**
40  * Sets the scale used for each X-coordinates passed
41  *
42  * @param scale New X scale
43  */
44  public void setXScale(double scale) {
45  xScale = scale;
46  }
47 
48  /**
49  * Gets the scale used for each Y-coordinates passed
50  *
51  * @return Y scale
52  */
53  public double getYScale() {
54  return yScale;
55  }
56 
57  /**
58  * Sets the scale used for each Y-coordinates passed
59  *
60  * @param scale New Y scale
61  */
62  public void setYScale(double scale) {
63  yScale = scale;
64  }
65 
66  /**
67  * Gets the scale used for each Z-coordinates passed
68  *
69  * @return Z scale
70  */
71  public double getZScale() {
72  return zScale;
73  }
74 
75  /**
76  * Sets the scale used for each Z-coordinates passed
77  *
78  * @param scale New Z scale
79  */
80  public void setZScale(double scale) {
81  zScale = scale;
82  }
83 
84  /**
85  * Gets a clone of the individual octaves used within this generator
86  *
87  * @return Clone of the individual octaves
88  */
90  return octaves.clone();
91  }
92 
93  /**
94  * Generates noise for the 1D coordinates using the specified number of
95  * octaves and parameters
96  *
97  * @param x X-coordinate
98  * @param frequency How much to alter the frequency by each octave
99  * @param amplitude How much to alter the amplitude by each octave
100  * @return Resulting noise
101  */
102  public double noise(double x, double frequency, double amplitude) {
103  return noise(x, 0, 0, frequency, amplitude);
104  }
105 
106  /**
107  * Generates noise for the 1D coordinates using the specified number of
108  * octaves and parameters
109  *
110  * @param x X-coordinate
111  * @param frequency How much to alter the frequency by each octave
112  * @param amplitude How much to alter the amplitude by each octave
113  * @param normalized If true, normalize the value to [-1, 1]
114  * @return Resulting noise
115  */
116  public double noise(double x, double frequency, double amplitude, boolean normalized) {
117  return noise(x, 0, 0, frequency, amplitude, normalized);
118  }
119 
120  /**
121  * Generates noise for the 2D coordinates using the specified number of
122  * octaves and parameters
123  *
124  * @param x X-coordinate
125  * @param y Y-coordinate
126  * @param frequency How much to alter the frequency by each octave
127  * @param amplitude How much to alter the amplitude by each octave
128  * @return Resulting noise
129  */
130  public double noise(double x, double y, double frequency, double amplitude) {
131  return noise(x, y, 0, frequency, amplitude);
132  }
133 
134  /**
135  * Generates noise for the 2D coordinates using the specified number of
136  * octaves and parameters
137  *
138  * @param x X-coordinate
139  * @param y Y-coordinate
140  * @param frequency How much to alter the frequency by each octave
141  * @param amplitude How much to alter the amplitude by each octave
142  * @param normalized If true, normalize the value to [-1, 1]
143  * @return Resulting noise
144  */
145  public double noise(double x, double y, double frequency, double amplitude, boolean normalized) {
146  return noise(x, y, 0, frequency, amplitude, normalized);
147  }
148 
149  /**
150  * Generates noise for the 3D coordinates using the specified number of
151  * octaves and parameters
152  *
153  * @param x X-coordinate
154  * @param y Y-coordinate
155  * @param z Z-coordinate
156  * @param frequency How much to alter the frequency by each octave
157  * @param amplitude How much to alter the amplitude by each octave
158  * @return Resulting noise
159  */
160  public double noise(double x, double y, double z, double frequency, double amplitude) {
161  return noise(x, y, z, frequency, amplitude, false);
162  }
163 
164  /**
165  * Generates noise for the 3D coordinates using the specified number of
166  * octaves and parameters
167  *
168  * @param x X-coordinate
169  * @param y Y-coordinate
170  * @param z Z-coordinate
171  * @param frequency How much to alter the frequency by each octave
172  * @param amplitude How much to alter the amplitude by each octave
173  * @param normalized If true, normalize the value to [-1, 1]
174  * @return Resulting noise
175  */
176  public double noise(double x, double y, double z, double frequency, double amplitude, boolean normalized) {
177  double result = 0;
178  double amp = 1;
179  double freq = 1;
180  double max = 0;
181 
182  x *= xScale;
183  y *= yScale;
184  z *= zScale;
185 
186  for (NoiseGenerator octave : octaves) {
187  result += octave.noise(x * freq, y * freq, z * freq) * amp;
188  max += amp;
189  freq *= frequency;
190  amp *= amplitude;
191  }
192 
193  if (normalized) {
194  result /= max;
195  }
196 
197  return result;
198  }
199 }
double noise(double x, double y, double z, double frequency, double amplitude, boolean normalized)
double noise(double x, double y, double z, double frequency, double amplitude)
double noise(double x, double y, double frequency, double amplitude, boolean normalized)
double noise(double x, double frequency, double amplitude, boolean normalized)
double noise(double x, double y, double frequency, double amplitude)
double noise(double x, double frequency, double amplitude)