Mercator
|
00001 // This file may be redistributed and modified only under the terms of 00002 // the GNU General Public License (See COPYING for details). 00003 // Copyright (C) 2003 Damien McGinnes, Alistair Riddoch 00004 00005 #ifndef MERCATOR_TERRAIN_MOD_H 00006 #define MERCATOR_TERRAIN_MOD_H 00007 00008 #include <Mercator/Effector.h> 00009 00010 #include <wfmath/intersect.h> 00011 #include <wfmath/ball.h> 00012 00013 namespace Mercator { 00014 00015 class Segment; 00016 00020 class TerrainMod : public Effector 00021 { 00022 protected: 00029 effector_func m_function; 00030 public: 00031 TerrainMod(); 00032 00033 virtual ~TerrainMod(); 00034 00035 int addToSegment(Segment &) const; 00036 void updateToSegment(Segment &) const; 00037 void removeFromSegment(Segment &) const; 00038 00040 void setFunction(effector_func f) { 00041 m_function = f; 00042 } 00043 00048 virtual void apply(float &point, int x, int y) const = 0; 00049 }; 00050 00055 template <template <int> class Shape> 00056 class ShapeTerrainMod : public TerrainMod 00057 { 00058 public: 00062 ShapeTerrainMod(const Shape<2> &s); 00063 virtual ~ShapeTerrainMod(); // {} 00064 00065 virtual bool checkIntersects(const Segment& s) const; 00066 00067 void setShape(const Shape<2> & s); 00068 protected: 00070 Shape<2> m_shape; 00071 }; 00072 00073 00077 template <template <int> class Shape> 00078 class LevelTerrainMod : public ShapeTerrainMod<Shape> 00079 { 00080 public: 00085 LevelTerrainMod(float level, const Shape<2> &s) 00086 : ShapeTerrainMod<Shape>(s), m_level(level) {} 00087 00088 virtual ~LevelTerrainMod(); 00089 00090 virtual void apply(float &point, int x, int y) const; 00091 00092 void setShape(float level, const Shape<2> & s); 00093 private: 00095 LevelTerrainMod(LevelTerrainMod&); // {} 00096 00097 protected: 00099 float m_level; 00100 }; 00101 00106 template <template <int> class Shape> 00107 class AdjustTerrainMod : public ShapeTerrainMod<Shape> 00108 { 00109 public: 00110 00115 AdjustTerrainMod(float dist, const Shape<2> &s) 00116 : ShapeTerrainMod<Shape>(s), m_dist(dist) {} 00117 00118 virtual ~AdjustTerrainMod(); 00119 00120 virtual void apply(float &point, int x, int y) const; 00121 00122 void setShape(float dist, const Shape<2> & s); 00123 private: 00125 AdjustTerrainMod(AdjustTerrainMod&); // {} 00126 00127 protected: 00129 float m_dist; 00130 }; 00131 00136 template <template <int> class Shape> 00137 class SlopeTerrainMod : public ShapeTerrainMod<Shape> 00138 { 00139 public: 00140 00147 SlopeTerrainMod(float level, float dx, float dy, const Shape<2> &s) 00148 : ShapeTerrainMod<Shape>(s), m_level(level), m_dx(dx), m_dy(dy) {} 00149 00150 virtual ~SlopeTerrainMod(); 00151 00152 virtual void apply(float &point, int x, int y) const; 00153 00154 void setShape(float level, float dx, float dy, const Shape<2> & s); 00155 private: 00157 SlopeTerrainMod(SlopeTerrainMod&); // {} 00158 00159 protected: 00161 float m_level; 00163 float m_dx; 00165 float m_dy; 00166 }; 00167 00172 template <template <int> class Shape> 00173 class CraterTerrainMod : public ShapeTerrainMod<Shape> 00174 { 00175 public: 00179 CraterTerrainMod(float level, const Shape<2> &s) 00180 : ShapeTerrainMod<Shape>(s), m_level(level) {} 00181 00182 virtual ~CraterTerrainMod(); 00183 00184 virtual void apply(float &point, int x, int y) const; 00185 00186 void setShape(float level, const Shape<2> & s); 00187 private: 00189 CraterTerrainMod(CraterTerrainMod&); // {} 00190 00191 protected: 00193 float m_level; 00194 }; 00195 00196 } //namespace Mercator 00197 00198 #endif // MERCATOR_TERRAIN_MOD_H