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
12namespace Mercator {
13
14template <template <int> class Shape>
15ShapeTerrainMod<Shape>::ShapeTerrainMod(const Shape<2> &s) : m_shape(s)
16{
17 m_box = m_shape.boundingBox();
18}
19
20
21template <template <int> class Shape> ShapeTerrainMod<Shape>::~ShapeTerrainMod() = default;
22
23template <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
30template <template <int> class Shape>
31void ShapeTerrainMod<Shape>::setShape(const Shape<2> & s)
32{
33 m_shape = s;
34 m_box = m_shape.boundingBox();
35}
36
37template <template <int> class Shape> LevelTerrainMod<Shape>::~LevelTerrainMod() = default;
38
39template <template <int> class Shape>
40void 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
47template <template <int> class Shape>
48void LevelTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
49{
51 m_level = level;
52}
53
54template <template <int> class Shape> AdjustTerrainMod<Shape>::~AdjustTerrainMod() = default;
55
56template <template <int> class Shape>
57void 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
64template <template <int> class Shape>
65void AdjustTerrainMod<Shape>::setShape(float dist, const Shape<2> & s)
66{
68 m_dist = dist;
69}
70
71template <template <int> class Shape> SlopeTerrainMod<Shape>::~SlopeTerrainMod() = default;
72
73template <template <int> class Shape>
74void 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
83template <template <int> class Shape>
84void 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
93template <template <int> class Shape> CraterTerrainMod<Shape>::~CraterTerrainMod() = default;
94
95template <template <int> class Shape>
96void 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
103template <template <int> class Shape>
104void 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 adjusted height.
Definition: TerrainMod.h:105
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:171
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
WFMath::AxisBox< 2 > m_box
The bounding box of the geometric shape.
Definition: Effector.h:57
Terrain modifier that defines an area of fixed height.
Definition: TerrainMod.h:76
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.
Class storing heightfield and other data for a single fixed size square area of terrain defined by fo...
Definition: Segment.h:37
WFMath::AxisBox< 2 > getRect() const
The 2d area covered by this segment.
Definition: Segment.cpp:337
Terrain modifier which is defined by a shape variable.
Definition: TerrainMod.h:53
ShapeTerrainMod(const Shape< 2 > &s)
Constructor.
Shape< 2 > m_shape
Shape of the modifier.
Definition: TerrainMod.h:67
Terrain modifier that defines an area of sloped height.
Definition: TerrainMod.h:135
virtual void apply(float &point, int x, int z) const
Apply this modifier on a terrain segment.