]> git.jsancho.org Git - lugaru.git/blob - Source/Models.h
a18854a384f42b559f613c1cad89c5eaaf8d762c
[lugaru.git] / Source / Models.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 _MODELS_H_
23 #define _MODELS_H_
24
25 /**> Model Loading <**/
26 //
27 // Model Maximums
28 //
29 #include "gamegl.h"
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <vector>
34
35 #include "Terrain.h"
36 #include "binio.h"
37 #include "Quaternions.h"
38 #include "Texture.h"
39
40 //
41 // Textures List
42 //
43 typedef struct {
44     long xsz, ysz;
45     GLubyte *txt;
46 } ModelTexture;
47
48 //
49 // Model Structures
50 //
51
52 class TexturedTriangle
53 {
54 public:
55     short vertex[3];
56     float gx[3], gy[3];
57 };
58
59 #define max_model_decals 300
60
61 #define nothing 0
62 #define normaltype 4
63 #define notextype 1
64 #define rawtype 2
65 #define decalstype 3
66
67 class Model
68 {
69 public:
70     short vertexNum, TriangleNum;
71     bool hastexture;
72
73     int type, oldtype;
74
75     int* possible;
76     int* owner;
77     XYZ* vertex;
78     XYZ* normals;
79     XYZ* facenormals;
80     TexturedTriangle* Triangles;
81     GLfloat* vArray;
82
83     /*int possible[max_model_vertex];
84     int owner[max_textured_triangle];
85     XYZ vertex[max_model_vertex];
86     XYZ normals[max_model_vertex];
87     XYZ facenormals[max_textured_triangle];
88     TexturedTriangle Triangles[max_textured_triangle];
89     GLfloat vArray[max_textured_triangle*24];*/
90
91     Texture textureptr;
92     ModelTexture modelTexture;
93     int numpossible;
94     bool color;
95
96     XYZ boundingspherecenter;
97     float boundingsphereradius;
98
99     float*** decaltexcoords;
100     XYZ** decalvertex;
101     int* decaltype;
102     float* decalopacity;
103     float* decalrotation;
104     float* decalalivetime;
105     XYZ* decalposition;
106
107     /*float decaltexcoords[max_model_decals][3][2];
108     XYZ decalvertex[max_model_decals][3];
109     int decaltype[max_model_decals];
110     float decalopacity[max_model_decals];
111     float decalrotation[max_model_decals];
112     float decalalivetime[max_model_decals];
113     XYZ decalposition[max_model_decals];*/
114
115     int numdecals;
116
117     bool flat;
118
119     void DeleteDecal(int which);
120     void MakeDecal(int atype, XYZ *where, float *size, float *opacity, float *rotation);
121     void MakeDecal(int atype, XYZ where, float size, float opacity, float rotation);
122     void drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloodtexture2, Texture breaktexture);
123     int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate);
124     int SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate);
125     int LineCheck(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
126     int LineCheckSlide(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
127     int LineCheckPossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
128     int LineCheckSlidePossible(XYZ *p1, XYZ *p2, XYZ *p, XYZ *move, float *rotate);
129     void UpdateVertexArray();
130     void UpdateVertexArrayNoTex();
131     void UpdateVertexArrayNoTexNoNorm();
132     bool loadnotex(const char *filename);
133     bool loadraw(char *filename);
134     bool load(const char *filename, bool texture);
135     bool loaddecal(const char *filename, bool texture);
136     void Scale(float xscale, float yscale, float zscale);
137     void FlipTexCoords();
138     void UniformTexCoords();
139     void ScaleTexCoords(float howmuch);
140     void ScaleNormals(float xscale, float yscale, float zscale);
141     void Translate(float xtrans, float ytrans, float ztrans);
142     void CalculateNormals(bool facenormalise);
143     void draw();
144     void drawdifftex(GLuint texture);
145     void drawdifftex(Texture texture);
146     void drawimmediate();
147     void drawdiffteximmediate(GLuint texture);
148     void Rotate(float xang, float yang, float zang);
149     ~Model();
150     void deallocate();
151     Model();
152 };
153
154 #endif