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 
148  SlopeTerrainMod(SlopeTerrainMod&) = delete;
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
Mercator::LevelTerrainMod::apply
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:40
Mercator::AdjustTerrainMod::apply
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:57
Mercator::SlopeTerrainMod
Terrain modifier that defines an area of sloped height.
Definition: TerrainMod.h:134
Mercator::TerrainMod::apply
virtual void apply(float &point, int x, int z) const =0
Apply this modifier on a terrain segment.
Mercator::ShapeTerrainMod::ShapeTerrainMod
ShapeTerrainMod(const Shape< 2 > &s)
Constructor.
Definition: TerrainMod_impl.h:15
Mercator::Segment
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:37
Mercator::SlopeTerrainMod::m_dz
float m_dz
The rate of change of the height along Z.
Definition: TerrainMod.h:162
Mercator::ShapeTerrainMod::m_shape
Shape< 2 > m_shape
Shape of the modifier.
Definition: TerrainMod.h:67
Mercator::CraterTerrainMod::apply
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:96
Mercator::TerrainMod::setFunction
void setFunction(effector_func f)
Change the function used to apply this mod to existing points.
Definition: TerrainMod.h:36
Mercator::CraterTerrainMod::m_level
float m_level
The height level of the crater center.
Definition: TerrainMod.h:190
Mercator::SlopeTerrainMod::SlopeTerrainMod
SlopeTerrainMod(float level, float dx, float dz, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:144
Mercator::LevelTerrainMod
Terrain modifier that defines an area of fixed height.
Definition: TerrainMod.h:75
Mercator::SlopeTerrainMod::m_level
float m_level
The height of the centre point.
Definition: TerrainMod.h:158
Mercator::Effector
Device which effects a change in the terrain.
Definition: Effector.h:25
Mercator::SlopeTerrainMod::apply
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:74
Mercator::AdjustTerrainMod
Terrain modifier that defines an area of adjusted height.
Definition: TerrainMod.h:104
Mercator::AdjustTerrainMod::m_dist
float m_dist
Adjustment to the height of all points affected.
Definition: TerrainMod.h:126
Mercator::LevelTerrainMod::LevelTerrainMod
LevelTerrainMod(float level, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:82
Mercator::CraterTerrainMod::CraterTerrainMod
CraterTerrainMod(float level, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:176
Mercator::CraterTerrainMod
Terrain modifier that defines a crater.
Definition: TerrainMod.h:170
Mercator::LevelTerrainMod::m_level
float m_level
The height level of all points affected.
Definition: TerrainMod.h:96
Mercator::AdjustTerrainMod::AdjustTerrainMod
AdjustTerrainMod(float dist, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:112
Mercator::ShapeTerrainMod
Terrain modifier which is defined by a shape variable.
Definition: TerrainMod.h:52
Mercator::TerrainMod
Base class for modifiers to the procedurally generated terrain.
Definition: TerrainMod.h:20
Mercator::SlopeTerrainMod::m_dx
float m_dx
The rate of change of the height along X.
Definition: TerrainMod.h:160
Mercator::TerrainMod::m_function
effector_func m_function
Function used to apply this mod to existing points.
Definition: TerrainMod.h:29