1 /*
2  * CRRCsim - the Charles River Radio Control Club Flight Simulator Project
3  *
4  * Copyright (C) 2009 Jan Reucker (original author)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #ifndef HD_TILINGTERRAIN_H
23 #define HD_TILINGTERRAIN_H
24 
25 #include "heightdata.h"
26 #include <plib/ssg.h>
27 
28 #define SIZE_GRID_PLANES      150
29 #define SIZE_CELL_GRID_PLANES 20
30 
31 typedef struct
32 {
33   float x;
34   float y;
35 } myPoint2D;
36 
37 
38 class HD_TilingTerrain : public HeightData
39 {
40   public:
41     HD_TilingTerrain(ssgRoot* SceneGraph);
42 
43     ~HD_TilingTerrain();
44 
45     /**
46      *  Get the height at a distinct point, in local coordinates, unit is ft
47      *
48      *  \param x_north  x coordinate (x positive == north)
49      *  \param y_east   y coordinate (y positive == east)
50      *
51      *  \return terrain height at this point in ft
52      */
53     float getHeight(float x_north, float y_east);
54 
55     /**
56      *  Get height and plane equation at x|y, in local coordinates, unit is ft
57      *
58      *  \param x_north  x coordinate (x positive == north)
59      *  \param y_east   y coordinate (y positive == east)
60      *  \param tplane this is where the plane equation will be stored
61      *  \return terrain height at this point in ft
62      */
63     float getHeightAndPlane(float x_north, float y_east, float tplane[4]);
64 
65   private:
66     void tiling_terrain(ssgEntity * e, sgMat4 xform);
67 
68     // test si point x,y, dans la projection du trianle p1, p2,p3
69     // sur plan horizontal
70     int on_triangle(float x, float y, float *p1,float *p2, float *p3);
71 
72     float Isleft(myPoint2D p1, myPoint2D p2, myPoint2D p);
73 
74     ssgVertexArray* tile_table[SIZE_GRID_PLANES][SIZE_GRID_PLANES];
75 };
76 
77 #endif // HD_TILINGTERRAIN_H
78