Heightmap.hpp   Heightmap.hpp 
skipping to change at line 24 skipping to change at line 24
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef HEIGHTMAP_HPP #ifndef HEIGHTMAP_HPP
#define HEIGHTMAP_HPP #define HEIGHTMAP_HPP
#include "OBJ.hpp" #include "StelOBJ.hpp"
//! This represents a heightmap for viewer-ground collision //! This represents a heightmap for viewer-ground collision
class Heightmap class Heightmap
{ {
public: public:
typedef QVector<unsigned int> IdxList;
typedef QVector<Vec3f> PosList;
//! Construct a heightmap from a loaded OBJ mesh. //! Construct a heightmap from a loaded OBJ mesh.
//! The mesh is stored as reference and used for calculations. //! The mesh is stored as reference and used for calculations.
//! @param obj Mesh for building the heightmap. //! @param obj Mesh for building the heightmap.
Heightmap(OBJ *obj); Heightmap();
virtual ~Heightmap(); virtual ~Heightmap();
//! Sets the mesh data to use. If the bbox is given, min/max calcula
tion is skipped and its values are taken.
void setMeshData(const IdxList& indexList, const PosList& posList, c
onst AABBox *bbox = Q_NULLPTR);
//! Get z Value at (x,y) coordinates. //! Get z Value at (x,y) coordinates.
//! In case of ambiguities always returns the maximum height. //! In case of ambiguities always returns the maximum height.
//! @param x x-value //! @param x x-value
//! @param y y-value //! @param y y-value
//! @return z-Value at position given by x and y //! @return z-Value at position given by x and y
float getHeight(const float x, const float y) const; float getHeight(const float x, const float y) const;
//! set/retrieve default height //! set/retrieve default height
void setNullHeight(float h){nullHeight=h;} void setNullHeight(float h){nullHeight=h;}
float getNullHeight() const {return nullHeight;} float getNullHeight() const {return nullHeight;}
private: private:
IdxList indexList;
PosList posList;
static const int GRID_LENGTH = 60; // # of grid spaces is GRID_LENG TH^2 static const int GRID_LENGTH = 60; // # of grid spaces is GRID_LENG TH^2
typedef std::vector<int> FaceVector; typedef QVector<const unsigned int*> FaceVector; //points to first i
ndex in Index list for a face
struct QuadTreeNode
{
//! Constructs a root node
QuadTreeNode(const Vec2f& min, const Vec2f& max);
//deletes all child nodes
~QuadTreeNode();
//indexes the child nodes, INVALID means outside the current
node
enum Quadrant { MinMin, MinMax, MaxMin, MaxMax, INVALID };
//Stores the index of the given triangle in the QuadTree
void putTriangle(const unsigned int* pTriangle, const PosLis
t& posList, int maxLevel = 7);
float getHeightAtPoint(const Vec2f& point, const PosList &po
sList) const;
//Recursively retrieves all triangles which *potentially* li
e at the given point
FaceVector getTriangleCandidatesAtPoint(const Vec2f& point)
const;
private:
//! Constructs a child node
QuadTreeNode();
void init(QuadTreeNode* parent, const Vec2f& min, const Vec2
f& max);
//turns this node from a leaf node into a normal node by add
ing 4 children
void subdivide();
//gets the subquadrant in which the specified point lies
Quadrant getQuadrantForPoint(const Vec2f& point) const;
//the parent node in case of a non-root node
QuadTreeNode* parent;
//either Q_NULLPTR in case of a leaf, or array of size 4
QuadTreeNode* children;
//! The level of this node, starting with 0 for the root nod
e
int level;
//! The total depth of this sub-tree, starting with 1 for th
e root node without children
int depth;
//! The total nodecount of this sub-tree, including this nod
e
int nodecount;
//contains faces which do not fit wholly in a subnode
FaceVector faces;
Vec2f min, max, mid;
} *rootNode;
struct GridSpace { struct GridSpace {
FaceVector faces; FaceVector faces;
float getHeight(const OBJ& obj, const float x, const float y float getHeight(const PosList &posList, const float x, const
) const; float y) const;
//static float face_height_at(const OBJ& obj, const OBJ::Fa
ce* face, float x, float y);
static float face_height_at(const OBJ& obj, const unsigned i
nt *pTriangle, const float x, const float y);
}; };
OBJ* obj;
GridSpace* grid; GridSpace* grid;
float xMin, yMin; Vec2f min, max, range;
float xMax, yMax;
float nullHeight; // return value for areas outside grid float nullHeight; // return value for areas outside grid
void initQuadtree();
void initGrid(); void initGrid();
GridSpace* getSpace(const float x, const float y) const ; GridSpace* getSpace(const float x, const float y) const ;
bool face_in_area(const OBJ& obj, const unsigned int* pTriangle, con static bool triangle_intersects_bbox(const Vec2f &t1, const Vec2f &t
st float xmin, const float ymin, const float xmax, const float ymax) const; 2, const Vec2f &t3, const Vec2f &rMin, const Vec2f &rMax);
//! Check whether points p and q lie on the same side of line ab, he
lper for line_intersects_triangle
inline static bool sameSide(const Vec2f& p, const Vec2f& q, const Ve
c2f& a, const Vec2f& b);
static bool line_intersects_triangle(const Vec2f &t1, const Vec2f &t
2, const Vec2f &t3, const Vec2f &p0, const Vec2f &p1);
//! Computes the barycentric coordinates of p inside the triangle t1
,t2,t3
static void cartesian_to_barycentric(const Vec2f& t1, const Vec2f& t
2, const Vec2f& t3, const Vec2f& p, float* l1, float* l2, float* l3);
static float face_height_at(const PosList &obj, const unsigned int *
pTriangle, const float x, const float y);
}; };
#endif // HEIGHTMAP_HPP #endif // HEIGHTMAP_HPP
 End of changes. 11 change blocks. 
16 lines changed or deleted 87 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/