Mercator
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 <Mercator/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  virtual ~TerrainMod();
34 
35  int addToSegment(Segment &) const;
36  void updateToSegment(Segment &) const;
37  void removeFromSegment(Segment &) const;
38 
40  void setFunction(effector_func f) {
41  m_function = f;
42  }
43 
48  virtual void apply(float &point, int x, int y) const = 0;
49 };
50 
55 template <template <int> class Shape>
57 {
58 public:
62  ShapeTerrainMod(const Shape<2> &s);
63  virtual ~ShapeTerrainMod(); // {}
64 
65  virtual bool checkIntersects(const Segment& s) const;
66 
67  void setShape(const Shape<2> & s);
68 protected:
70  Shape<2> m_shape;
71 };
72 
73 
77 template <template <int> class Shape>
78 class LevelTerrainMod : public ShapeTerrainMod<Shape>
79 {
80 public:
85  LevelTerrainMod(float level, const Shape<2> &s)
86  : ShapeTerrainMod<Shape>(s), m_level(level) {}
87 
88  virtual ~LevelTerrainMod();
89 
90  virtual void apply(float &point, int x, int y) const;
91 
92  void setShape(float level, const Shape<2> & s);
93 private:
96 
97 protected:
99  float m_level;
100 };
101 
106 template <template <int> class Shape>
107 class AdjustTerrainMod : public ShapeTerrainMod<Shape>
108 {
109 public:
110 
115  AdjustTerrainMod(float dist, const Shape<2> &s)
116  : ShapeTerrainMod<Shape>(s), m_dist(dist) {}
117 
118  virtual ~AdjustTerrainMod();
119 
120  virtual void apply(float &point, int x, int y) const;
121 
122  void setShape(float dist, const Shape<2> & s);
123 private:
126 
127 protected:
129  float m_dist;
130 };
131 
136 template <template <int> class Shape>
137 class SlopeTerrainMod : public ShapeTerrainMod<Shape>
138 {
139 public:
140 
147  SlopeTerrainMod(float level, float dx, float dy, const Shape<2> &s)
148  : ShapeTerrainMod<Shape>(s), m_level(level), m_dx(dx), m_dy(dy) {}
149 
150  virtual ~SlopeTerrainMod();
151 
152  virtual void apply(float &point, int x, int y) const;
153 
154  void setShape(float level, float dx, float dy, const Shape<2> & s);
155 private:
158 
159 protected:
161  float m_level;
163  float m_dx;
165  float m_dy;
166 };
167 
172 template <template <int> class Shape>
173 class CraterTerrainMod : public ShapeTerrainMod<Shape>
174 {
175 public:
179  CraterTerrainMod(float level, const Shape<2> &s)
180  : ShapeTerrainMod<Shape>(s), m_level(level) {}
181 
182  virtual ~CraterTerrainMod();
183 
184  virtual void apply(float &point, int x, int y) const;
185 
186  void setShape(float level, const Shape<2> & s);
187 private:
190 
191 protected:
193  float m_level;
194 };
195 
196 } //namespace Mercator
197 
198 #endif // MERCATOR_TERRAIN_MOD_H
CraterTerrainMod(float level, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:179
Device which effects a change in the terrain.
Definition: Effector.h:25
float m_dx
The rate of change of the height along X.
Definition: TerrainMod.h:163
void setFunction(effector_func f)
Change the function used to apply this mod to existing points.
Definition: TerrainMod.h:40
float m_level
The height level of all points affected.
Definition: TerrainMod.h:99
Terrain modifier that defines an area of sloped height.
Definition: TerrainMod.h:137
SlopeTerrainMod(float level, float dx, float dy, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:147
Definition: Area.cpp:20
effector_func m_function
Function used to apply this mod to existing points.
Definition: TerrainMod.h:29
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:36
Shape< 2 > m_shape
Shape of the modifier.
Definition: TerrainMod.h:70
virtual void apply(float &point, int x, int y) const =0
Apply this modifier on a terrain segment.
Terrain modifier that defines a crater.
Definition: TerrainMod.h:173
float m_level
The height level of the crater center.
Definition: TerrainMod.h:193
float m_dist
Adjustment to the height of all points affected.
Definition: TerrainMod.h:129
Terrain modifier that defines an area of adjusted height.
Definition: TerrainMod.h:107
Terrain modifier that defines an area of fixed height.
Definition: TerrainMod.h:78
LevelTerrainMod(float level, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:85
float m_level
The height of the centre point.
Definition: TerrainMod.h:161
float m_dy
The rate of change of the height along Y.
Definition: TerrainMod.h:165
AdjustTerrainMod(float dist, const Shape< 2 > &s)
Constructor.
Definition: TerrainMod.h:115
Base class for modifiers to the procedurally generated terrain.
Definition: TerrainMod.h:20
Terrain modifier which is defined by a shape variable.
Definition: TerrainMod.h:56