vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Terrain2D.h
Go to the documentation of this file.
1 
11 #ifndef VRECKO_NATURE_TERRAIN_TERRAIN2D_H
12 #define VRECKO_NATURE_TERRAIN_TERRAIN2D_H
13 
14 #include <osg/Geode>
15 #include <osg/PositionAttitudeTransform>
16 #include <osg/ShapeDrawable>
17 
18 #include "Terrain2DSegment.h"
19 
20 namespace APNature
21 {
26  class Terrain2D
27  {
28  private:
29  Terrain2DSegment *_terrainSegments; // Two-dimensional array of terrain segments from which the terrain blocks
30  // which is mapped into one dimension for higher clarity
31  osg::ref_ptr<osg::Group> _terrainGroup; // Group node containing PAT group node.
32  osg::ref_ptr<osg::PositionAttitudeTransform> _PATGroup; // Group node in which the whole terrain block is located.
33 
34  public:
40  Terrain2D(void);
41 
45  ~Terrain2D(void);
46 
51  osg::ref_ptr<osg::Group> GetTerrainGroup() const { return _terrainGroup; }
52 
59  const osg::Vec3f& GetPoint(int x, int y) const;
60 
67  void SetPoint(int x, int y, const osg::Vec3f& point);
68 
75  float GetPointHeight(int x, int y) const;
76 
83  void SetPointHeight(int x, int y, float height);
84 
90  bool ImportFromHeightMap(const std::string& path);
91 
98  void GenerateByRandomFaultsAlgorithm(int iterations, float faultValueMin, float faultValueMax);
99 
106  void GenerateByMidpointDisplacementAlgorithm(float cornerValueFrom, float cornerValueTo);
107 
113  void GenerateByPerlinNoiseAlgorithm(float persistence, int octaveCount);
114 
119  void Flatten(float height);
120 
125  void Export(FileTypeExport fileType);
126 
131  void Preprocessing();
132 
136  void Postprocessing();
137 
138  private:
139 
143  void AllocateSegments();
144 
148  void AllocateSegmentPoints();
149 
153  void Release();
154 
158  void InitializeNeighbours();
159 
165  void InitializeSegmentPositions();
166 
170  void ComputeNormals();
171 
175  void AddSegmentGeodesToTerrainGroup();
176 
183  static inline unsigned int SegmentIndex(int x, int y) { return y * TerrainProperties::ResolutionX() + x;}
184  };
185 }
186 
187 #endif