]> git.jsancho.org Git - lugaru.git/blob - Source/Environment/Terrain.hpp
884829c9409b90b57c2de1f76911eff573693c6a
[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/Decal.hpp"
26 #include "Graphic/gamegl.hpp"
27 #include "Graphic/Texture.hpp"
28 #include "Math/Frustum.hpp"
29 #include "Math/XYZ.hpp"
30 #include "Utils/ImageIO.hpp"
31
32 #define max_terrain_size        256
33 #define curr_terrain_size       size
34 #define subdivision             64
35 #define max_patch_elements      (max_terrain_size/subdivision)*(max_terrain_size/subdivision)*54
36
37 #define allfirst 0
38 #define mixed 1
39 #define allsecond 2
40
41 #define max_decals 1000
42
43 #define snowyenvironment 0
44 #define grassyenvironment 1
45 #define desertenvironment 2
46 //
47 // Model Structures
48 //
49
50 class Terrain
51 {
52 public:
53     Texture bloodtexture;
54     Texture bloodtexture2;
55     Texture shadowtexture;
56     Texture footprinttexture;
57     Texture bodyprinttexture;
58     Texture breaktexture;
59     Texture terraintexture;
60     short size;
61
62     int patchobjectnum[subdivision][subdivision];
63     unsigned int patchobjects[subdivision][subdivision][300];
64
65     float scale;
66     int type;
67     float heightmap[max_terrain_size + 1][max_terrain_size + 1];
68     XYZ normals[max_terrain_size][max_terrain_size];
69     XYZ facenormals[max_terrain_size][max_terrain_size];
70     XYZ triangles[(max_terrain_size - 1) * (max_terrain_size - 1) * 2][3];
71     float colors[max_terrain_size][max_terrain_size][4];
72     float opacityother[max_terrain_size][max_terrain_size];
73     float texoffsetx[max_terrain_size][max_terrain_size];
74     float texoffsety[max_terrain_size][max_terrain_size];
75     int numtris[subdivision][subdivision];
76     int textureness[subdivision][subdivision];
77
78     GLfloat vArray[(max_patch_elements)*subdivision*subdivision];
79
80     bool visible[subdivision][subdivision];
81     float avgypatch[subdivision][subdivision];
82     float maxypatch[subdivision][subdivision];
83     float minypatch[subdivision][subdivision];
84     float heightypatch[subdivision][subdivision];
85
86     int patch_elements;
87
88     std::vector<Decal> decals;
89
90     void AddObject(XYZ where, float radius, int id);
91     void DeleteDecal(int which);
92     void MakeDecal(decal_type type, XYZ where, float size, float opacity, float rotation);
93     void MakeDecalLock(decal_type type, XYZ where, int whichx, int whichy, float size, float opacity, float rotation);
94     int lineTerrain(XYZ p1, XYZ p2, XYZ *p);
95     float getHeight(float pointx, float pointz);
96     float getOpacity(float pointx, float pointz);
97     XYZ getLighting(float pointx, float pointz);
98     XYZ getNormal(float pointx, float pointz);
99     void UpdateVertexArray(int whichx, int whichy);
100     bool load(const std::string& fileName);
101     void CalculateNormals();
102     void drawdecals();
103     void draw(int layer);
104     void DoShadows();
105     void deleteDeadDecals();
106
107     Terrain();
108
109 private:
110     void drawpatch(int whichx, int whichy, float opacity);
111     void drawpatchother(int whichx, int whichy, float opacity);
112     void drawpatchotherother(int whichx, int whichy);
113     void UpdateTransparency(int whichx, int whichy);
114     void UpdateTransparencyother(int whichx, int whichy);
115     void UpdateTransparencyotherother(int whichx, int whichy);
116 };
117
118 #endif