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