00001
00002
00003
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
00013 #include <map>
00014 #include <list>
00015 #include <cmath>
00016
00017 namespace Mercator {
00018
00019 class Segment;
00020 class Shader;
00021 class TerrainMod;
00022 class Area;
00023
00032 class Terrain {
00033 public:
00035 typedef std::map<int, BasePoint> Pointcolumn;
00037 typedef std::map<int, Segment *> Segmentcolumn;
00038
00040 typedef std::map<int, Pointcolumn > Pointstore;
00042 typedef std::map<int, Segmentcolumn > Segmentstore;
00043
00045 typedef std::map<int, Shader *> Shaderstore;
00046
00047 typedef std::multimap<int, Area *> Areastore;
00048
00050 static const unsigned int DEFAULT = 0x0000;
00052 static const unsigned int SHADED = 0x0001;
00053
00054
00055 private:
00057 const unsigned int m_options;
00059 const int m_res;
00060
00062 Pointstore m_basePoints;
00064 Segmentstore m_segments;
00066 Shaderstore m_shaders;
00067
00068 Areastore m_areas;
00069
00070 void addSurfaces(Segment &);
00071 void shadeSurfaces(Segment &);
00072
00076 bool isShaded() const {
00077 return ((m_options & SHADED) == SHADED);
00078 }
00079 public:
00081 static const float defaultLevel;
00082 explicit Terrain(unsigned int options = DEFAULT,
00083 unsigned int resolution = defaultResolution);
00084 ~Terrain();
00085
00086 float get(float x, float y) const;
00087 bool getHeightAndNormal(float x, float y, float&, WFMath::Vector<3>&) const;
00088
00089 bool getBasePoint(int x, int y, BasePoint& z) const;
00090 void setBasePoint(int x, int y, const BasePoint& z);
00091
00093 void setBasePoint(int x, int y, float z) {
00094 BasePoint bp(z);
00095 setBasePoint(x, y, bp);
00096 }
00097
00102 Segment * getSegment(float x, float y) const {
00103 int ix = (int)floor(x / m_res);
00104 int iy = (int)floor(y / m_res);
00105 return getSegment(ix, iy);
00106 }
00107
00108 Segment * getSegment(int x, int y) const;
00109
00111 const int getResolution() const {
00112 return m_res;
00113 }
00114
00116 const Segmentstore & getTerrain() const {
00117 return m_segments;
00118 }
00119
00121 const Pointstore & getPoints() const {
00122 return m_basePoints;
00123 }
00124
00126 const Shaderstore & getShaders() const {
00127 return m_shaders;
00128 }
00129
00131 void addShader(Shader * t, int id);
00132
00133 void addMod(const TerrainMod &t);
00134
00135 void addArea(Area* a);
00136 };
00137
00138 }
00139
00140 #endif // MERCATOR_TERRAIN_H