Mercator
TerrainMod_impl.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_IMPL_H
6 #define MERCATOR_TERRAIN_MOD_IMPL_H
7 
8 #include <Mercator/TerrainMod.h>
9 
10 #include <Mercator/Segment.h>
11 
12 namespace Mercator {
13 
14 template <template <int> class Shape>
15 ShapeTerrainMod<Shape>::ShapeTerrainMod(const Shape<2> &s) : m_shape(s)
16 {
17  m_box = m_shape.boundingBox();
18 }
19 
20 
21 template <template <int> class Shape> ShapeTerrainMod<Shape>::~ShapeTerrainMod()
22 {
23 }
24 
25 template <template <int> class Shape>
27 {
28  return WFMath::Intersect(m_shape, s.getRect(), false) ||
29  WFMath::Contains(s.getRect(), m_shape.getCorner(0), false);
30 }
31 
32 template <template <int> class Shape>
33 void ShapeTerrainMod<Shape>::setShape(const Shape<2> & s)
34 {
35  m_shape = s;
36  m_box = m_shape.boundingBox();
37 }
38 
39 template <template <int> class Shape> LevelTerrainMod<Shape>::~LevelTerrainMod()
40 {
41 }
42 
43 template <template <int> class Shape>
44 void LevelTerrainMod<Shape>::apply(float &point, int x, int y) const
45 {
46  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
47  point = this->m_function(point, m_level);
48  }
49 }
50 
51 template <template <int> class Shape>
52 void LevelTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
53 {
55  m_level = level;
56 }
57 
58 template <template <int> class Shape> AdjustTerrainMod<Shape>::~AdjustTerrainMod()
59 {
60 }
61 
62 template <template <int> class Shape>
63 void AdjustTerrainMod<Shape>::apply(float &point, int x, int y) const
64 {
65  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
66  point += m_dist;
67  }
68 }
69 
70 template <template <int> class Shape>
71 void AdjustTerrainMod<Shape>::setShape(float dist, const Shape<2> & s)
72 {
74  m_dist = dist;
75 }
76 
77 template <template <int> class Shape> SlopeTerrainMod<Shape>::~SlopeTerrainMod()
78 {
79 }
80 
81 template <template <int> class Shape>
82 void SlopeTerrainMod<Shape>::apply(float &point, int x, int y) const
83 {
84  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
85  float level = m_level + (this->m_shape.getCenter()[0] - x) * m_dx
86  + (this->m_shape.getCenter()[1] - y) * m_dy;
87  point = this->m_function(point, level);
88  }
89 }
90 
91 template <template <int> class Shape>
92 void SlopeTerrainMod<Shape>::setShape(float level, float dx, float dy, const Shape<2> & s)
93 {
95  m_level = level;
96  m_dx = dx;
97  m_dy = dy;
98 }
99 
100 
101 template <template <int> class Shape> CraterTerrainMod<Shape>::~CraterTerrainMod()
102 {
103 }
104 
105 template <template <int> class Shape>
106 void CraterTerrainMod<Shape>::apply(float &point, int x, int y) const
107 {
108  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
109  point += m_level;
110  }
111 }
112 
113 template <template <int> class Shape>
114 void CraterTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
115 {
117  m_level = level;
118 }
119 
120 
121 } //namespace Mercator
122 
123 #endif // MERCATOR_TERRAIN_MOD_IMPL_H
Terrain modifier that defines an area of sloped height.
Definition: TerrainMod.h:137
Definition: Area.cpp:20
WFMath::AxisBox< 2 > getRect() const
The 2d area covered by this segment.
Definition: Segment.cpp:752
virtual void apply(float &point, int x, int y) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:63
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
ShapeTerrainMod(const Shape< 2 > &s)
Constructor.
Definition: TerrainMod_impl.h:15
Terrain modifier that defines a crater.
Definition: TerrainMod.h:173
virtual void apply(float &point, int x, int y) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:106
WFMath::AxisBox< 2 > m_box
The bounding box of the geometric shape.
Definition: Effector.h:70
virtual void apply(float &point, int x, int y) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:44
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
virtual void apply(float &point, int x, int y) const
Apply this modifier on a terrain segment.
Definition: TerrainMod_impl.h:82
Terrain modifier which is defined by a shape variable.
Definition: TerrainMod.h:56