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/vector.h> 00012 #include <wfmath/axisbox.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 = 0x0000; 00059 static const unsigned int SHADED = 0x0001; 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; 00067 00069 Pointstore m_basePoints; 00071 Segmentstore m_segments; 00073 Shaderstore m_shaders; 00074 00076 Effectorstore m_effectors; 00077 00078 void addSurfaces(Segment &); 00079 void shadeSurfaces(Segment &); 00080 00081 void addEffector(const Effector * effector); 00082 00089 Rect updateEffector(const Effector * effector); 00090 void removeEffector(const Effector * effector); 00091 00095 bool isShaded() const { 00096 return ((m_options & SHADED) == SHADED); 00097 } 00098 public: 00100 static const float defaultLevel; 00101 00102 explicit Terrain(unsigned int options = DEFAULT, 00103 unsigned int resolution = defaultResolution); 00104 ~Terrain(); 00105 00106 float get(float x, float y) const; 00107 bool getHeightAndNormal(float x, float y, float&, WFMath::Vector<3>&) const; 00108 00109 bool getBasePoint(int x, int y, BasePoint& z) const; 00110 void setBasePoint(int x, int y, const BasePoint& z); 00111 00113 void setBasePoint(int x, int y, float z) { 00114 BasePoint bp(z); 00115 setBasePoint(x, y, bp); 00116 } 00117 00122 Segment * getSegment(float x, float y) const { 00123 int ix = (int)floor(x / m_res); 00124 int iy = (int)floor(y / m_res); 00125 return getSegment(ix, iy); 00126 } 00127 00128 Segment * getSegment(int x, int y) const; 00129 00131 const int getResolution() const { 00132 return m_res; 00133 } 00134 00136 const Segmentstore & getTerrain() const { 00137 return m_segments; 00138 } 00139 00141 const Pointstore & getPoints() const { 00142 return m_basePoints; 00143 } 00144 00146 const Shaderstore & getShaders() const { 00147 return m_shaders; 00148 } 00149 00151 void addShader(const Shader * t, int id); 00152 void removeShader(const Shader * t, int id); 00153 00154 void addMod(const TerrainMod * mod); 00155 00162 Rect updateMod(const TerrainMod * mod); 00163 void removeMod(const TerrainMod * mod); 00164 00165 void addArea(const Area* a); 00166 00173 Rect updateArea(const Area* a); 00174 void removeArea(const Area* a); 00175 }; 00176 00177 } // namespace Mercator 00178 00179 #endif // MERCATOR_TERRAIN_H