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 Alistair Riddoch, Damien McGinnes 00004 00005 #ifndef MERCATOR_TERRAIN_H 00006 #define MERCATOR_TERRAIN_H 00007 00008 #include <Mercator/Mercator.h> 00009 #include <Mercator/BasePoint.h> 00010 00011 #include <wfmath/axisbox.h> 00012 #include <wfmath/point.h> 00013 00014 #include <map> 00015 #include <set> 00016 #include <list> 00017 #include <cmath> 00018 00019 namespace Mercator { 00020 00021 class Segment; 00022 class Shader; 00023 class TerrainMod; 00024 class Area; 00025 class Effector; 00026 00035 class Terrain { 00036 public: 00038 typedef WFMath::AxisBox<2> Rect; 00039 00041 typedef std::map<int, BasePoint> Pointcolumn; 00043 typedef std::map<int, Segment *> Segmentcolumn; 00044 00046 typedef std::map<int, Pointcolumn > Pointstore; 00048 typedef std::map<int, Segmentcolumn > Segmentstore; 00049 00051 typedef std::map<int, const Shader *> Shaderstore; 00052 00054 typedef std::map<const Effector *, Rect> Effectorstore; 00055 00057 static const unsigned int DEFAULT; 00059 static const unsigned int SHADED; 00060 // More options go here as bit flags, and below should be a private 00061 // test function 00062 private: 00064 const unsigned int m_options; 00066 const int m_res; 00068 const float m_spacing; 00069 00071 Pointstore m_basePoints; 00073 Segmentstore m_segments; 00075 Shaderstore m_shaders; 00076 00078 Effectorstore m_effectors; 00079 00080 void addSurfaces(Segment &); 00081 void shadeSurfaces(Segment &); 00082 00083 void addEffector(const Effector * effector); 00084 00091 Rect updateEffector(const Effector * effector); 00092 void removeEffector(const Effector * effector); 00093 00097 bool isShaded() const { 00098 return ((m_options & SHADED) == SHADED); 00099 } 00100 public: 00102 static const float defaultLevel; 00103 00104 explicit Terrain(unsigned int options = DEFAULT, 00105 unsigned int resolution = defaultResolution); 00106 ~Terrain(); 00107 00108 float get(float x, float y) const; 00109 bool getHeightAndNormal(float x, float y, float&, WFMath::Vector<3>&) const; 00110 00111 bool getBasePoint(int x, int y, BasePoint& z) const; 00112 void setBasePoint(int x, int y, const BasePoint& z); 00113 00115 void setBasePoint(int x, int y, float z) { 00116 BasePoint bp(z); 00117 setBasePoint(x, y, bp); 00118 } 00119 00124 Segment * getSegment(float x, float y) const { 00125 int ix = (int)floor(x / m_spacing); 00126 int iy = (int)floor(y / m_spacing); 00127 return getSegment(ix, iy); 00128 } 00129 00130 Segment * getSegment(int x, int y) const; 00131 00133 int getResolution() const { 00134 return m_res; 00135 } 00136 00138 float getSpacing() const { 00139 return m_spacing; 00140 } 00141 00143 const Segmentstore & getTerrain() const { 00144 return m_segments; 00145 } 00146 00148 const Pointstore & getPoints() const { 00149 return m_basePoints; 00150 } 00151 00153 const Shaderstore & getShaders() const { 00154 return m_shaders; 00155 } 00156 00158 void addShader(const Shader * t, int id); 00159 void removeShader(const Shader * t, int id); 00160 00161 void addMod(const TerrainMod * mod); 00162 00169 Rect updateMod(const TerrainMod * mod); 00170 void removeMod(const TerrainMod * mod); 00171 00172 void addArea(const Area* a); 00173 00180 Rect updateArea(const Area* a); 00181 void removeArea(const Area* a); 00182 }; 00183 00184 } // namespace Mercator 00185 00186 #endif // MERCATOR_TERRAIN_H