1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D 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 along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(AFX_HEIGHTMAP_H__F4CB4CAD_C592_4183_AFB2_016FC66C144A__INCLUDED_)
22 #define AFX_HEIGHTMAP_H__F4CB4CAD_C592_4183_AFB2_016FC66C144A__INCLUDED_
23 
24 #include <stdlib.h>
25 #include <common/ProgressCounter.h>
26 #include <common/FixedVector.h>
27 #include <common/Vector.h>
28 
29 class Line;
30 class GraphicalHeightMap;
31 class HeightMap
32 {
33 public:
34 	HeightMap();
35 	virtual ~HeightMap();
36 
37 	void create(int width, int height, bool invertedNormals);
38 	void reset();
39 
40 	// Height map size fns
getMapWidth()41 	int getMapWidth() { return width_; }
getMapHeight()42 	int getMapHeight() { return height_; }
43 
44 	// Get height fns (z values)
getHeight(int w,int h)45 	inline fixed getHeight(int w, int h) {
46 		if (w >= 0 && h >= 0 && w<=width_ && h<=height_)
47 			return heightData_[(width_+1) * h + w].position[2];
48 		return fixed(0); }
49 	fixed getInterpHeight(fixed w, fixed h);
50 
51 	// Get normal functions
52 	FixedVector &getNormal(int w, int h);
53 	void getInterpNormal(fixed w, fixed h, FixedVector &normal);
54 
55 	bool getIntersect(Line &direction, Vector &intersect);
56 
57 	// Alters the actual internal HeightMap points
58 	void setHeight(int w, int h, fixed height);
59 
getGraphicalMap()60 	GraphicalHeightMap *getGraphicalMap() { return graphicalMap_; }
setGraphicalMap(GraphicalHeightMap * map)61 	void setGraphicalMap(GraphicalHeightMap *map) { graphicalMap_ = map; }
62 
63 protected:
64 	struct HeightData
65 	{
66 		FixedVector position;
67 		FixedVector normal;
68 	};
69 
70 	bool invertedNormals_;
71 	int width_, height_;
72 	HeightData *heightData_;
73 	GraphicalHeightMap *graphicalMap_;
74 
75 	bool getVector(FixedVector &vec, int x, int y);
76 	void getVectorPos(int pos, int &x, int &y, int dist=1);
77 };
78 
79 #endif // !defined(AFX_HEIGHTMAP_H__F4CB4CAD_C592_4183_AFB2_016FC66C144A__INCLUDED_)
80 
81