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 public:
23  TerrainMod();
24 
25  virtual ~TerrainMod();
26 
27  int addToSegment(Segment &) const;
28  void updateToSegment(Segment &) const;
29  void removeFromSegment(Segment &) const;
30 
35  virtual void apply(float &point, int x, int y) const = 0;
36 
38  virtual TerrainMod *clone() const = 0;
39 };
40 
45 template <template <int> class Shape>
47 {
48 public:
52  ShapeTerrainMod(const Shape<2> &s);
53  virtual ~ShapeTerrainMod(); // {}
54 
55  virtual bool checkIntersects(const Segment& s) const;
56 
57  void setShape(const Shape<2> & s);
58 protected:
60  Shape<2> m_shape;
61 };
62 
63 
67 template <template <int> class Shape>
68 class LevelTerrainMod : public ShapeTerrainMod<Shape>
69 {
70 public:
75  LevelTerrainMod(float level, const Shape<2> &s)
76  : ShapeTerrainMod<Shape>(s), m_level(level) {}
77 
78  virtual ~LevelTerrainMod();
79 
80  virtual void apply(float &point, int x, int y) const;
81  virtual TerrainMod *clone() const;
82 
83  void setShape(float level, const Shape<2> & s);
84 private:
87 
88 protected:
90  float m_level;
91 };
92 
97 template <template <int> class Shape>
98 class AdjustTerrainMod : public ShapeTerrainMod<Shape>
99 {
100 public:
101 
106  AdjustTerrainMod(float dist, const Shape<2> &s)
107  : ShapeTerrainMod<Shape>(s), m_dist(dist) {}
108 
109  virtual ~AdjustTerrainMod();
110 
111  virtual void apply(float &point, int x, int y) const;
112  virtual TerrainMod *clone() const;
113 
114  void setShape(float dist, const Shape<2> & s);
115 private:
118 
119 protected:
121  float m_dist;
122 };
123 
128 template <template <int> class Shape>
129 class SlopeTerrainMod : public ShapeTerrainMod<Shape>
130 {
131 public:
132 
139  SlopeTerrainMod(float level, float dx, float dy, const Shape<2> &s)
140  : ShapeTerrainMod<Shape>(s), m_level(level), m_dx(dx), m_dy(dy) {}
141 
142  virtual ~SlopeTerrainMod();
143 
144  virtual void apply(float &point, int x, int y) const;
145  virtual TerrainMod *clone() const;
146 
147  void setShape(float level, float dx, float dy, const Shape<2> & s);
148 private:
151 
152 protected:
154  float m_level;
156  float m_dx;
158  float m_dy;
159 };
160 
165 template <template <int> class Shape>
166 class CraterTerrainMod : public ShapeTerrainMod<Shape>
167 {
168 public:
172  CraterTerrainMod(float level, const Shape<2> &s)
173  : ShapeTerrainMod<Shape>(s), m_level(level) {}
174 
175  virtual ~CraterTerrainMod();
176 
177  virtual void apply(float &point, int x, int y) const;
178  virtual TerrainMod *clone() const;
179 
180  void setShape(float level, const Shape<2> & s);
181 private:
184 
185 protected:
187  float m_level;
188 };
189 
190 } //namespace Mercator
191 
192 #endif // MERCATOR_TERRAIN_MOD_H