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_IMPL_H 00006 #define MERCATOR_TERRAIN_MOD_IMPL_H 00007 00008 #include <Mercator/TerrainMod.h> 00009 00010 #include <Mercator/Segment.h> 00011 00012 namespace Mercator { 00013 00014 template <template <int> class Shape> 00015 ShapeTerrainMod<Shape>::ShapeTerrainMod(const Shape<2> &s) : m_shape(s) 00016 { 00017 m_box = m_shape.boundingBox(); 00018 } 00019 00020 00021 template <template <int> class Shape> ShapeTerrainMod<Shape>::~ShapeTerrainMod() 00022 { 00023 } 00024 00025 template <template <int> class Shape> 00026 bool ShapeTerrainMod<Shape>::checkIntersects(const Segment& s) const 00027 { 00028 return WFMath::Intersect(m_shape, s.getRect(), false) || 00029 WFMath::Contains(s.getRect(), m_shape.getCorner(0), false); 00030 } 00031 00032 template <template <int> class Shape> 00033 void ShapeTerrainMod<Shape>::setShape(const Shape<2> & s) 00034 { 00035 m_shape = s; 00036 m_box = m_shape.boundingBox(); 00037 } 00038 00039 template <template <int> class Shape> LevelTerrainMod<Shape>::~LevelTerrainMod() 00040 { 00041 } 00042 00043 template <template <int> class Shape> 00044 void LevelTerrainMod<Shape>::apply(float &point, int x, int y) const 00045 { 00046 if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) { 00047 point = m_level; 00048 } 00049 } 00050 00051 template <template <int> class Shape> 00052 TerrainMod * LevelTerrainMod<Shape>::clone() const 00053 { 00054 return new LevelTerrainMod<Shape>(m_level, this->m_shape); 00055 } 00056 00057 template <template <int> class Shape> 00058 void LevelTerrainMod<Shape>::setShape(float level, const Shape<2> & s) 00059 { 00060 ShapeTerrainMod<Shape>::setShape(s); 00061 m_level = level; 00062 } 00063 00064 template <template <int> class Shape> AdjustTerrainMod<Shape>::~AdjustTerrainMod() 00065 { 00066 } 00067 00068 template <template <int> class Shape> 00069 void AdjustTerrainMod<Shape>::apply(float &point, int x, int y) const 00070 { 00071 if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) { 00072 point += m_dist; 00073 } 00074 } 00075 00076 template <template <int> class Shape> 00077 TerrainMod * AdjustTerrainMod<Shape>::clone() const 00078 { 00079 return new AdjustTerrainMod<Shape>(m_dist, this->m_shape); 00080 } 00081 00082 template <template <int> class Shape> 00083 void AdjustTerrainMod<Shape>::setShape(float dist, const Shape<2> & s) 00084 { 00085 ShapeTerrainMod<Shape>::setShape(s); 00086 m_dist = dist; 00087 } 00088 00089 template <template <int> class Shape> SlopeTerrainMod<Shape>::~SlopeTerrainMod() 00090 { 00091 } 00092 00093 template <template <int> class Shape> 00094 void SlopeTerrainMod<Shape>::apply(float &point, int x, int y) const 00095 { 00096 if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) { 00097 point = m_level + (this->m_shape.getCenter()[0] - x) * m_dx 00098 + (this->m_shape.getCenter()[1] - y) * m_dy; 00099 } 00100 } 00101 00102 template <template <int> class Shape> 00103 TerrainMod * SlopeTerrainMod<Shape>::clone() const 00104 { 00105 return new SlopeTerrainMod<Shape>(m_level, m_dx, m_dy, this->m_shape); 00106 } 00107 00108 template <template <int> class Shape> 00109 void SlopeTerrainMod<Shape>::setShape(float level, float dx, float dy, const Shape<2> & s) 00110 { 00111 ShapeTerrainMod<Shape>::setShape(s); 00112 m_level = level; 00113 m_dx = dx; 00114 m_dy = dy; 00115 } 00116 00117 00118 template <template <int> class Shape> CraterTerrainMod<Shape>::~CraterTerrainMod() 00119 { 00120 } 00121 00122 template <template <int> class Shape> 00123 void CraterTerrainMod<Shape>::apply(float &point, int x, int y) const 00124 { 00125 if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) { 00126 point += m_level; 00127 } 00128 } 00129 00130 template <template <int> class Shape> 00131 TerrainMod * CraterTerrainMod<Shape>::clone() const 00132 { 00133 return new CraterTerrainMod<Shape>(m_level, this->m_shape); 00134 } 00135 00136 template <template <int> class Shape> 00137 void CraterTerrainMod<Shape>::setShape(float level, const Shape<2> & s) 00138 { 00139 ShapeTerrainMod<Shape>::setShape(s); 00140 m_level = level; 00141 } 00142 00143 00144 } //namespace Mercator 00145 00146 #endif // MERCATOR_TERRAIN_MOD_IMPL_H