TerrainMod.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_H
00006 #define MERCATOR_TERRAIN_MOD_H
00007 
00008 #include <wfmath/intersect.h>
00009 #include <wfmath/axisbox.h>
00010 #include <wfmath/ball.h>
00011 
00012 namespace Mercator {
00013 
00014 class TerrainMod
00015 {
00016 public:
00017     virtual ~TerrainMod();
00018     //apply this modifier on a terrain segment at x,y in local coordinates
00019     //output is placed into point
00020     virtual void apply(float &point, int x, int y) const = 0;
00021 
00022     //get the boundingbox of the modifier
00023     virtual WFMath::AxisBox<2> bbox() const = 0;
00024 
00025     virtual TerrainMod *clone() const = 0;
00026 };
00027 
00028 template <typename Shape>
00029 class ShapeTerrainMod : public TerrainMod
00030 {
00031 public:
00032     ShapeTerrainMod(const Shape &s) : m_shape(s) {}
00033     virtual ~ShapeTerrainMod(); // {}
00034     
00035     virtual WFMath::AxisBox<2> bbox() const; // { return m_shape.boundingBox(); }
00036     
00037 protected:
00038     Shape m_shape;
00039 };
00040 
00041 
00042 //this modifier sets all points inside the shape to the same altitude
00043 template <typename Shape>
00044 class LevelTerrainMod : public ShapeTerrainMod<Shape>
00045 {
00046 public:
00047 
00048     LevelTerrainMod(float level, const Shape &s) 
00049         : ShapeTerrainMod<Shape>(s), m_level(level) {}
00050     
00051     virtual ~LevelTerrainMod();
00052     
00053     virtual void apply(float &point, int x, int y) const;
00054     virtual TerrainMod *clone() const;
00055 
00056 private:
00057     LevelTerrainMod(LevelTerrainMod&); // {}
00058     
00059 protected:
00060     float m_level;
00061 };
00062 
00063 //this modifier changes the altitude of all points inside the shape
00064 //by the same amount
00065 template <typename Shape>
00066 class AdjustTerrainMod : public ShapeTerrainMod<Shape>
00067 {
00068 public:
00069 
00070     AdjustTerrainMod(float dist, const Shape &s) 
00071         : ShapeTerrainMod<Shape>(s), m_dist(dist) {}
00072     
00073     virtual ~AdjustTerrainMod();
00074     
00075     virtual void apply(float &point, int x, int y) const;
00076     virtual TerrainMod *clone() const;
00077 
00078 private:
00079     AdjustTerrainMod(AdjustTerrainMod&) {}
00080 
00081 protected:
00082     float m_dist;
00083 };
00084 
00085 //this modifier creates a sloped area. The center point is
00086 //set to a level and all other points are set based on specified gradients
00087 template <typename Shape>
00088 class SlopeTerrainMod : public ShapeTerrainMod<Shape>
00089 {
00090 public:
00091 
00092     SlopeTerrainMod(float level, float dx, float dy, const Shape &s) 
00093         : ShapeTerrainMod<Shape>(s), m_level(level), m_dx(dx), m_dy(dy) {}
00094     
00095     virtual ~SlopeTerrainMod();
00096     
00097     virtual void apply(float &point, int x, int y) const;
00098     virtual TerrainMod *clone() const;
00099 
00100 private:
00101     SlopeTerrainMod(SlopeTerrainMod&) {}
00102 
00103 protected:
00104     float m_level, m_dx, m_dy;
00105 };
00106             
00107 class CraterTerrainMod : public TerrainMod
00108 {
00109 public:
00110 
00111     CraterTerrainMod(const WFMath::Ball<3> &s) : m_shape(s) {
00112         WFMath::AxisBox<3> bb=m_shape.boundingBox();
00113         ab = WFMath::AxisBox<2> (
00114                     WFMath::Point<2>(bb.lowerBound(0), bb.lowerBound(1)),
00115                     WFMath::Point<2>(bb.upperBound(0), bb.upperBound(1))
00116                );
00117     }
00118     
00119     virtual ~CraterTerrainMod(); // {}
00120     
00121     virtual WFMath::AxisBox<2> bbox() const;
00122     virtual void apply(float &point, int x, int y) const; 
00123     virtual TerrainMod *clone() const;
00124 
00125 private:
00126     CraterTerrainMod(CraterTerrainMod&) {}
00127 
00128     WFMath::Ball<3> m_shape;
00129     WFMath::AxisBox<2> ab;
00130 
00131 };
00132  
00133 } //namespace Mercator
00134 
00135 #endif // MERCATOR_TERRAIN_MOD_H

Generated on Mon Aug 20 15:31:10 2007 for Mercator by  doxygen 1.5.2