Stellarium 0.14.3
Heightmap.hpp
1 /*
2  * Stellarium Scenery3d Plug-in
3  *
4  * Copyright (C) 2011-2015 Simon Parzer, Peter Neubauer, Georg Zotti, Andrei Borza, Florian Schaukowitsch
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef HEIGHTMAP_HPP
22 #define HEIGHTMAP_HPP
23 
24 #include "OBJ.hpp"
25 
27 class Heightmap
28 {
29 
30 public:
31 
35  Heightmap(OBJ *obj);
36  virtual ~Heightmap();
37 
43  float getHeight(const float x, const float y) const;
44 
46  void setNullHeight(float h){nullHeight=h;}
47  float getNullHeight() const {return nullHeight;}
48 
49 private:
50 
51  static const int GRID_LENGTH = 60; // # of grid spaces is GRID_LENGTH^2
52 
53  typedef std::vector<int> FaceVector;
54 
55  struct GridSpace {
56  FaceVector faces;
57  float getHeight(const OBJ& obj, const float x, const float y) const;
58 
59  //static float face_height_at(const OBJ& obj, const OBJ::Face* face, float x, float y);
60  static float face_height_at(const OBJ& obj, const unsigned int *pTriangle, const float x, const float y);
61  };
62 
63  OBJ* obj;
64  GridSpace* grid;
65  float xMin, yMin;
66  float xMax, yMax;
67  float nullHeight; // return value for areas outside grid
68 
69  void initGrid();
70  GridSpace* getSpace(const float x, const float y) const ;
71  bool face_in_area(const OBJ& obj, const unsigned int* pTriangle, const float xmin, const float ymin, const float xmax, const float ymax) const;
72 
73 };
74 
75 #endif // HEIGHTMAP_HPP
This represents a heightmap for viewer-ground collision.
Definition: Heightmap.hpp:27
float getHeight(const float x, const float y) const
Get z Value at (x,y) coordinates.
Heightmap(OBJ *obj)
Construct a heightmap from a loaded OBJ mesh.
A basic Wavefront .OBJ format model loader.
Definition: OBJ.hpp:63
void setNullHeight(float h)
set/retrieve default height
Definition: Heightmap.hpp:46