]> git.jsancho.org Git - lugaru.git/blob - Source/Environment/Terrain.hpp
f6525c4b0d286777f6d00ab1c5bd4a77b3cf340c
[lugaru.git] / Source / Environment / Terrain.hpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _TERRAIN_HPP_
22 #define _TERRAIN_HPP_
23
24 #include "Environment/Lights.hpp"
25 #include "Graphic/gamegl.hpp"
26 #include "Graphic/Texture.hpp"
27 #include "Math/Frustum.hpp"
28 #include "Math/Quaternions.hpp"
29 #include "Utils/ImageIO.hpp"
30
31 #define max_terrain_size        256
32 #define curr_terrain_size       size
33 #define subdivision             64
34 #define max_patch_elements      (max_terrain_size/subdivision)*(max_terrain_size/subdivision)*54
35
36 #define allfirst 0
37 #define mixed 1
38 #define allsecond 2
39
40 #define max_decals 1000
41
42 #define shadowdecal 0
43 #define footprintdecal 1
44 #define blooddecal 2
45 #define blooddecalfast 3
46 #define shadowdecalpermanent 4
47 #define breakdecal 5
48 #define blooddecalslow 6
49 #define bodyprintdecal 7
50
51 #define snowyenvironment 0
52 #define grassyenvironment 1
53 #define desertenvironment 2
54 //
55 // Model Structures
56 //
57
58 class Terrain
59 {
60 public:
61     Texture bloodtexture;
62     Texture bloodtexture2;
63     Texture shadowtexture;
64     Texture footprinttexture;
65     Texture bodyprinttexture;
66     Texture breaktexture;
67     Texture terraintexture;
68     short size;
69
70     int patchobjectnum[subdivision][subdivision];
71     unsigned int patchobjects[subdivision][subdivision][300];
72
73     float scale;
74     int type;
75     float heightmap[max_terrain_size + 1][max_terrain_size + 1];
76     XYZ normals[max_terrain_size][max_terrain_size];
77     XYZ facenormals[max_terrain_size][max_terrain_size];
78     XYZ triangles[(max_terrain_size - 1) * (max_terrain_size - 1) * 2][3];
79     float colors[max_terrain_size][max_terrain_size][4];
80     float opacityother[max_terrain_size][max_terrain_size];
81     float texoffsetx[max_terrain_size][max_terrain_size];
82     float texoffsety[max_terrain_size][max_terrain_size];
83     int numtris[subdivision][subdivision];
84     int textureness[subdivision][subdivision];
85
86     GLfloat vArray[(max_patch_elements)*subdivision*subdivision];
87
88     bool visible[subdivision][subdivision];
89     float avgypatch[subdivision][subdivision];
90     float maxypatch[subdivision][subdivision];
91     float minypatch[subdivision][subdivision];
92     float heightypatch[subdivision][subdivision];
93
94     int patch_elements;
95
96     float decaltexcoords[max_decals][3][2];
97     XYZ decalvertex[max_decals][3];
98     int decaltype[max_decals];
99     float decalopacity[max_decals];
100     float decalrotation[max_decals];
101     float decalalivetime[max_decals];
102     float decalbrightness[max_decals];
103     XYZ decalposition[max_decals];
104     int numdecals;
105
106     void AddObject(XYZ where, float radius, int id);
107     void DeleteDecal(int which);
108     void MakeDecal(int type, XYZ where, float size, float opacity, float rotation);
109     void MakeDecalLock(int type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation);
110     int lineTerrain(XYZ p1, XYZ p2, XYZ *p);
111     float getHeight(float pointx, float pointz);
112     float getOpacity(float pointx, float pointz);
113     XYZ getLighting(float pointx, float pointz);
114     XYZ getNormal(float pointx, float pointz);
115     void UpdateVertexArray(int whichx, int whichy);
116     bool load(const std::string& fileName);
117     void CalculateNormals();
118     void drawdecals();
119     void draw(int layer);
120     void DoShadows();
121
122     Terrain();
123
124 private:
125     void drawpatch(int whichx, int whichy, float opacity);
126     void drawpatchother(int whichx, int whichy, float opacity);
127     void drawpatchotherother(int whichx, int whichy);
128     void UpdateTransparency(int whichx, int whichy);
129     void UpdateTransparencyother(int whichx, int whichy);
130     void UpdateTransparencyotherother(int whichx, int whichy);
131 };
132
133 #endif