mercator  0.4.0
A terrain generation library for the Worldforge system.
TerrainMod.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU General Public License (See COPYING for details).
3 // Copyright (C) 2003 Damien McGinnes, Alistair Riddoch
4 
5 #ifndef MERCATOR_TERRAIN_MOD_H
6 #define MERCATOR_TERRAIN_MOD_H
7 
8 #include "Effector.h"
9 
10 #include <wfmath/intersect.h>
11 #include <wfmath/ball.h>
12 
13 namespace Mercator {
14 
15 class Segment;
16 
20 class TerrainMod : public Effector
21 {
22 protected:
29  effector_func m_function;
30 public:
31  TerrainMod();
32 
33  ~TerrainMod() override;
34 
36  void setFunction(effector_func f) {
37  m_function = f;
38  }
39 
44  virtual void apply(float &point, int x, int z) const = 0;
45 };
46 
51 template <template <int> class Shape>
53 {
54 public:
58  explicit ShapeTerrainMod(const Shape<2> &s);
59 
60  ~ShapeTerrainMod() override;
61 
62  bool checkIntersects(const Segment& s) const override;
63 
64  void setShape(const Shape<2> & s);
65 protected:
67  Shape<2> m_shape;
68 };
69 
70 
74 template <template <int> class Shape>
75 class LevelTerrainMod : public ShapeTerrainMod<Shape>
76 {
77 public:
82  LevelTerrainMod(float level, const Shape<2> &s)
83  : ShapeTerrainMod<Shape>(s), m_level(level) {}
84 
87 
88  virtual ~LevelTerrainMod();
89 
90  virtual void apply(float &point, int x, int z) const;
91 
92  void setShape(float level, const Shape<2> & s);
93 
94 protected:
96  float m_level;
97 };
98 
103 template <template <int> class Shape>
104 class AdjustTerrainMod : public ShapeTerrainMod<Shape>
105 {
106 public:
107 
112  AdjustTerrainMod(float dist, const Shape<2> &s)
113  : ShapeTerrainMod<Shape>(s), m_dist(dist) {}
114 
117 
118  virtual ~AdjustTerrainMod();
119 
120  virtual void apply(float &point, int x, int z) const;
121 
122  void setShape(float dist, const Shape<2> & s);
123 
124 protected:
126  float m_dist;
127 };
128 
133 template <template <int> class Shape>
134 class SlopeTerrainMod : public ShapeTerrainMod<Shape>
135 {
136 public:
137 
144  SlopeTerrainMod(float level, float dx, float dz, const Shape<2> &s)
145  : ShapeTerrainMod<Shape>(s), m_level(level), m_dx(dx), m_dz(dz) {}
146 
149 
150  virtual ~SlopeTerrainMod();
151 
152  virtual void apply(float &point, int x, int z) const;
153 
154  void setShape(float level, float dx, float dz, const Shape<2> & s);
155 
156 protected:
158  float m_level;
160  float m_dx;
162  float m_dz;
163 };
164 
169 template <template <int> class Shape>
170 class CraterTerrainMod : public ShapeTerrainMod<Shape>
171 {
172 public:
176  CraterTerrainMod(float level, const Shape<2> &s)
177  : ShapeTerrainMod<Shape>(s), m_level(level) {}
178 
181 
182  virtual ~CraterTerrainMod();
183 
184  virtual void apply(float &point, int x, int z) const;
185 
186  void setShape(float level, const Shape<2> & s);
187 
188 protected:
190  float m_level;
191 };
192 
193 } //namespace Mercator
194 
195 #endif // MERCATOR_TERRAIN_MOD_H
Terrain modifier that defines an area of adjusted height.
Definition: TerrainMod.h:105
float m_dist
Adjustment to the height of all points affected.
Definition: TerrainMod.h:126
AdjustTerrainMod(float dist, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:112
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
AdjustTerrainMod(AdjustTerrainMod &)=delete
Copy constructor.
Terrain modifier that defines a crater.
Definition: TerrainMod.h:171
CraterTerrainMod(float level, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:176
CraterTerrainMod(CraterTerrainMod &)=delete
Copy constructor.
float m_level
The height level of the crater center.
Definition: TerrainMod.h:190
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Device which effects a change in the terrain.
Definition: Effector.h:26
Terrain modifier that defines an area of fixed height.
Definition: TerrainMod.h:76
LevelTerrainMod(LevelTerrainMod &)=delete
Copy constructor.
float m_level
The height level of all points affected.
Definition: TerrainMod.h:96
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
LevelTerrainMod(float level, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:82
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:37
Terrain modifier which is defined by a shape variable.
Definition: TerrainMod.h:53
ShapeTerrainMod(const Shape< 2 > &s)
Constructor.
Shape< 2 > m_shape
Shape of the modifier.
Definition: TerrainMod.h:67
Terrain modifier that defines an area of sloped height.
Definition: TerrainMod.h:135
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
SlopeTerrainMod(float level, float dx, float dz, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:144
float m_dx
The rate of change of the height along X.
Definition: TerrainMod.h:160
SlopeTerrainMod(SlopeTerrainMod &)=delete
Copy constructor.
float m_dz
The rate of change of the height along Z.
Definition: TerrainMod.h:162
float m_level
The height of the centre point.
Definition: TerrainMod.h:158
Base class for modifiers to the procedurally generated terrain.
Definition: TerrainMod.h:21
void setFunction(effector_func f)
Change the function used to apply this mod to existing points.
Definition: TerrainMod.h:36
effector_func m_function
Function used to apply this mod to existing points.
Definition: TerrainMod.h:29
virtual void apply(float &point, int x, int z) const =0
Apply this modifier on a terrain segment.