Mercator
TerrainMod_impl.h
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 = this->m_function(point, m_level);
00048     }
00049 }
00050 
00051 template <template <int> class Shape>
00052 void LevelTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
00053 {
00054     ShapeTerrainMod<Shape>::setShape(s);
00055     m_level = level;
00056 }
00057 
00058 template <template <int> class Shape> AdjustTerrainMod<Shape>::~AdjustTerrainMod()
00059 {
00060 }
00061     
00062 template <template <int> class Shape>
00063 void AdjustTerrainMod<Shape>::apply(float &point, int x, int y) const
00064 {
00065     if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
00066         point += m_dist;
00067     }
00068 }
00069     
00070 template <template <int> class Shape>
00071 void AdjustTerrainMod<Shape>::setShape(float dist, const Shape<2> & s)
00072 {
00073     ShapeTerrainMod<Shape>::setShape(s);
00074     m_dist = dist;
00075 }
00076 
00077 template <template <int> class Shape> SlopeTerrainMod<Shape>::~SlopeTerrainMod()
00078 {
00079 }
00080     
00081 template <template <int> class Shape>
00082 void SlopeTerrainMod<Shape>::apply(float &point, int x, int y) const
00083 {
00084     if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
00085         float level = m_level + (this->m_shape.getCenter()[0] - x) * m_dx 
00086                               + (this->m_shape.getCenter()[1] - y) * m_dy;
00087         point = this->m_function(point, level);
00088     }
00089 }
00090     
00091 template <template <int> class Shape>
00092 void SlopeTerrainMod<Shape>::setShape(float level, float dx, float dy, const Shape<2> & s)
00093 {
00094     ShapeTerrainMod<Shape>::setShape(s);
00095     m_level = level;
00096     m_dx = dx;
00097     m_dy = dy;
00098 }
00099 
00100 
00101 template <template <int> class Shape> CraterTerrainMod<Shape>::~CraterTerrainMod()
00102 {
00103 }
00104     
00105 template <template <int> class Shape>
00106 void CraterTerrainMod<Shape>::apply(float &point, int x, int y) const
00107 {
00108     if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
00109         point += m_level;
00110     }
00111 }
00112     
00113 template <template <int> class Shape>
00114 void CraterTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
00115 {
00116     ShapeTerrainMod<Shape>::setShape(s);
00117     m_level = level;
00118 }
00119 
00120 
00121 } //namespace Mercator
00122 
00123 #endif // MERCATOR_TERRAIN_MOD_IMPL_H