Pyrogenesis  trunk
Noise.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * 2D and 3D seamless Perlin noise
20  */
21 
22 // Based on http://www.cs.cmu.edu/~mzucker/code/perlin-noise-math-faq.html
23 // and http://mrl.nyu.edu/~perlin/paper445.pdf.
24 // Not optimized for speed yet.
25 
26 #ifndef INCLUDED_NOISE
27 #define INCLUDED_NOISE
28 
29 #include "Vector2D.h"
30 #include "Vector3D.h"
31 #include "MathUtil.h"
32 
33 class Noise2D
34 {
36 
37  /// Frequency in X and Y
38  int freq;
39 
40  /// freq*freq random gradient vectors in the unit cube
42 public:
43  Noise2D(int freq);
44  ~Noise2D();
45 
46  /// Evaluate the noise function at a given point
47  float operator() (float x, float y);
48 };
49 
50 class Noise3D
51 {
53 
54  /// Frequency in X and Y
55  int freq;
56 
57  /// Frequency in Z (vertical frequency)
58  int vfreq;
59 
60  /// freq*freq*vfreq random gradient vectors in the unit cube
62 public:
63  Noise3D(int freq, int vfreq);
64  ~Noise3D();
65 
66  /// Evaluate the noise function at a given point
67  float operator() (float x, float y, float z);
68 };
69 
70 #endif
Definition: Noise.h:33
Definition: Vector3D.h:28
int vfreq
Frequency in Z (vertical frequency)
Definition: Noise.h:58
CVector3D *** grads
freq*freq*vfreq random gradient vectors in the unit cube
Definition: Noise.h:61
Definition: Noise.h:50
CVector2D ** grads
freq*freq random gradient vectors in the unit cube
Definition: Noise.h:41
float operator()(float x, float y)
Evaluate the noise function at a given point.
Definition: Noise.cpp:72
Definition: Vector2D.h:31
NONCOPYABLE(Noise2D)
Noise2D(int freq)
Definition: Noise.cpp:48
~Noise2D()
Definition: Noise.cpp:63
int freq
Frequency in X and Y.
Definition: Noise.h:38
int freq
Frequency in X and Y.
Definition: Noise.h:55