mercator  0.4.0
A terrain generation library for the Worldforge system.
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 "TerrainMod.h"
9 
10 #include "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() = default;
22 
23 template <template <int> class Shape>
25 {
26  return WFMath::Intersect(m_shape, s.getRect(), false) ||
27  WFMath::Contains(s.getRect(), m_shape.getCorner(0), false);
28 }
29 
30 template <template <int> class Shape>
31 void ShapeTerrainMod<Shape>::setShape(const Shape<2> & s)
32 {
33  m_shape = s;
34  m_box = m_shape.boundingBox();
35 }
36 
37 template <template <int> class Shape> LevelTerrainMod<Shape>::~LevelTerrainMod() = default;
38 
39 template <template <int> class Shape>
40 void LevelTerrainMod<Shape>::apply(float &point, int x, int z) const
41 {
42  if (Contains(this->m_shape,WFMath::Point<2>(x,z),true)) {
43  point = this->m_function(point, m_level);
44  }
45 }
46 
47 template <template <int> class Shape>
48 void LevelTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
49 {
51  m_level = level;
52 }
53 
54 template <template <int> class Shape> AdjustTerrainMod<Shape>::~AdjustTerrainMod() = default;
55 
56 template <template <int> class Shape>
57 void AdjustTerrainMod<Shape>::apply(float &point, int x, int z) const
58 {
59  if (Contains(this->m_shape,WFMath::Point<2>(x,z),true)) {
60  point += m_dist;
61  }
62 }
63 
64 template <template <int> class Shape>
65 void AdjustTerrainMod<Shape>::setShape(float dist, const Shape<2> & s)
66 {
68  m_dist = dist;
69 }
70 
71 template <template <int> class Shape> SlopeTerrainMod<Shape>::~SlopeTerrainMod() = default;
72 
73 template <template <int> class Shape>
74 void SlopeTerrainMod<Shape>::apply(float &point, int x, int z) const
75 {
76  if (Contains(this->m_shape,WFMath::Point<2>(x,z),true)) {
77  float level = m_level + (this->m_shape.getCenter()[0] - x) * m_dx
78  + (this->m_shape.getCenter()[1] - z) * m_dz;
79  point = this->m_function(point, level);
80  }
81 }
82 
83 template <template <int> class Shape>
84 void SlopeTerrainMod<Shape>::setShape(float level, float dx, float dz, const Shape<2> & s)
85 {
87  m_level = level;
88  m_dx = dx;
89  m_dz = dz;
90 }
91 
92 
93 template <template <int> class Shape> CraterTerrainMod<Shape>::~CraterTerrainMod() = default;
94 
95 template <template <int> class Shape>
96 void CraterTerrainMod<Shape>::apply(float &point, int x, int z) const
97 {
98  if (Contains(this->m_shape,WFMath::Point<2>(x,z),true)) {
99  point += m_level;
100  }
101 }
102 
103 template <template <int> class Shape>
104 void CraterTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
105 {
107  m_level = level;
108 }
109 
110 
111 } //namespace Mercator
112 
113 #endif // MERCATOR_TERRAIN_MOD_IMPL_H
Terrain modifier that defines an area of sloped height.
Definition: TerrainMod.h:134
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:37
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Shape< 2 > m_shape
Shape of the modifier.
Definition: TerrainMod.h:67
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
ShapeTerrainMod(const Shape< 2 > &s)
Constructor.
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Terrain modifier that defines a crater.
Definition: TerrainMod.h:170
WFMath::AxisBox< 2 > m_box
The bounding box of the geometric shape.
Definition: Effector.h:57
Terrain modifier that defines an area of adjusted height.
Definition: TerrainMod.h:104
Terrain modifier that defines an area of fixed height.
Definition: TerrainMod.h:75
Terrain modifier which is defined by a shape variable.
Definition: TerrainMod.h:52
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
WFMath::AxisBox< 2 > getRect() const
The 2d area covered by this segment.
Definition: Segment.cpp:337