Mercurial > pidgin
comparison plugins/crazychat/glm.h @ 11232:8bcd4d4ccef6
[gaim-migrate @ 13372]
committing crazychat again. hopefully here to stay.
committer: Tailor Script <tailor@pidgin.im>
author | Charlie Stockman <chuckleberry> |
---|---|
date | Thu, 11 Aug 2005 07:56:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11231:64e2c65ef650 | 11232:8bcd4d4ccef6 |
---|---|
1 #ifndef __GLM__H__ | |
2 #define __GLM__H__ | |
3 | |
4 /* | |
5 glm.h | |
6 | |
7 */ | |
8 | |
9 | |
10 #if defined(WIN32) | |
11 #include "glut.h" | |
12 #else | |
13 //#include <GL/glut.h> | |
14 #endif | |
15 | |
16 #include<GL/glu.h> | |
17 | |
18 #ifndef M_PI | |
19 #define M_PI 3.14159265 | |
20 #endif | |
21 | |
22 #define GLM_NONE (0) /* render with only vertices */ | |
23 #define GLM_FLAT (1 << 0) /* render with facet normals */ | |
24 #define GLM_SMOOTH (1 << 1) /* render with vertex normals */ | |
25 #define GLM_TEXTURE (1 << 2) /* render with texture coords */ | |
26 #define GLM_COLOR (1 << 3) /* render with colors */ | |
27 #define GLM_MATERIAL (1 << 4) /* render with materials */ | |
28 | |
29 | |
30 /* GLMmaterial: Structure that defines a material in a model. | |
31 */ | |
32 typedef struct _GLMmaterial | |
33 { | |
34 char* name; /* name of material */ | |
35 GLfloat diffuse[4]; /* diffuse component */ | |
36 GLfloat ambient[4]; /* ambient component */ | |
37 GLfloat specular[4]; /* specular component */ | |
38 GLfloat emmissive[4]; /* emmissive component */ | |
39 GLfloat shininess; /* specular exponent */ | |
40 } GLMmaterial; | |
41 | |
42 typedef struct _GLMmat_str{ | |
43 GLint num_materials; | |
44 GLMmaterial* materials; | |
45 } GLMmat_str; | |
46 | |
47 | |
48 /* GLMtriangle: Structure that defines a triangle in a model. | |
49 */ | |
50 typedef struct _GLMtriangle { | |
51 GLuint vindices[3]; /* array of triangle vertex indices */ | |
52 GLuint nindices[3]; /* array of triangle normal indices */ | |
53 GLuint tindices[3]; /* array of triangle texcoord indices*/ | |
54 GLuint findex; /* index of triangle facet normal */ | |
55 } GLMtriangle; | |
56 | |
57 /* GLMgroup: Structure that defines a group in a model. | |
58 */ | |
59 typedef struct _GLMgroup { | |
60 char* name; /* name of this group */ | |
61 GLuint numtriangles; /* number of triangles in this group */ | |
62 GLuint* triangles; /* array of triangle indices */ | |
63 GLuint material; /* index to material for group */ | |
64 struct _GLMgroup* next; /* pointer to next group in model */ | |
65 } GLMgroup; | |
66 | |
67 /* GLMmodel: Structure that defines a model. | |
68 */ | |
69 typedef struct _GLMmodel { | |
70 char* pathname; /* path to this model */ | |
71 char* mtllibname; /* name of the material library */ | |
72 | |
73 GLuint numvertices; /* number of vertices in model */ | |
74 GLfloat* vertices; /* array of vertices */ | |
75 | |
76 GLuint numnormals; /* number of normals in model */ | |
77 GLfloat* normals; /* array of normals */ | |
78 | |
79 GLuint numtexcoords; /* number of texcoords in model */ | |
80 GLfloat* texcoords; /* array of texture coordinates */ | |
81 | |
82 GLuint numfacetnorms; /* number of facetnorms in model */ | |
83 GLfloat* facetnorms; /* array of facetnorms */ | |
84 | |
85 GLuint numtriangles; /* number of triangles in model */ | |
86 GLMtriangle* triangles; /* array of triangles */ | |
87 | |
88 GLuint nummaterials; /* number of materials in model */ | |
89 GLMmaterial* materials; /* array of materials */ | |
90 | |
91 GLuint numgroups; /* number of groups in model */ | |
92 GLMgroup* groups; /* linked list of groups */ | |
93 | |
94 GLfloat position[3]; /* position of the model */ | |
95 | |
96 } GLMmodel; | |
97 | |
98 # ifdef __cplusplus | |
99 extern "C" { | |
100 # endif /* __cplusplus */ | |
101 | |
102 /* glmUnitize: "unitize" a model by translating it to the origin and | |
103 * scaling it to fit in a unit cube around the origin. Returns the | |
104 * scalefactor used. | |
105 * | |
106 * model - properly initialized GLMmodel structure | |
107 */ | |
108 GLfloat | |
109 glmUnitize(GLMmodel* model); | |
110 | |
111 /* glmDimensions: Calculates the dimensions (width, height, depth) of | |
112 * a model. | |
113 * | |
114 * model - initialized GLMmodel structure | |
115 * dimensions - array of 3 GLfloats (GLfloat dimensions[3]) | |
116 */ | |
117 GLvoid | |
118 glmDimensions(GLMmodel* model, GLfloat* dimensions); | |
119 | |
120 /* glmScale: Scales a model by a given amount. | |
121 * | |
122 * model - properly initialized GLMmodel structure | |
123 * scale - scalefactor (0.5 = half as large, 2.0 = twice as large) | |
124 */ | |
125 GLvoid | |
126 glmScale(GLMmodel* model, GLfloat scale); | |
127 | |
128 /* glmReverseWinding: Reverse the polygon winding for all polygons in | |
129 * this model. Default winding is counter-clockwise. Also changes | |
130 * the direction of the normals. | |
131 * | |
132 * model - properly initialized GLMmodel structure | |
133 */ | |
134 GLvoid | |
135 glmReverseWinding(GLMmodel* model); | |
136 | |
137 /* glmFacetNormals: Generates facet normals for a model (by taking the | |
138 * cross product of the two vectors derived from the sides of each | |
139 * triangle). Assumes a counter-clockwise winding. | |
140 * | |
141 * model - initialized GLMmodel structure | |
142 */ | |
143 GLvoid | |
144 glmFacetNormals(GLMmodel* model); | |
145 | |
146 /* glmVertexNormals: Generates smooth vertex normals for a model. | |
147 * First builds a list of all the triangles each vertex is in. Then | |
148 * loops through each vertex in the the list averaging all the facet | |
149 * normals of the triangles each vertex is in. Finally, sets the | |
150 * normal index in the triangle for the vertex to the generated smooth | |
151 * normal. If the dot product of a facet normal and the facet normal | |
152 * associated with the first triangle in the list of triangles the | |
153 * current vertex is in is greater than the cosine of the angle | |
154 * parameter to the function, that facet normal is not added into the | |
155 * average normal calculation and the corresponding vertex is given | |
156 * the facet normal. This tends to preserve hard edges. The angle to | |
157 * use depends on the model, but 90 degrees is usually a good start. | |
158 * | |
159 * model - initialized GLMmodel structure | |
160 * angle - maximum angle (in degrees) to smooth across | |
161 */ | |
162 GLvoid | |
163 glmVertexNormals(GLMmodel* model, GLfloat angle); | |
164 | |
165 /* glmLinearTexture: Generates texture coordinates according to a | |
166 * linear projection of the texture map. It generates these by | |
167 * linearly mapping the vertices onto a square. | |
168 * | |
169 * model - pointer to initialized GLMmodel structure | |
170 */ | |
171 GLvoid | |
172 glmLinearTexture(GLMmodel* model); | |
173 | |
174 /* glmSpheremapTexture: Generates texture coordinates according to a | |
175 * spherical projection of the texture map. Sometimes referred to as | |
176 * spheremap, or reflection map texture coordinates. It generates | |
177 * these by using the normal to calculate where that vertex would map | |
178 * onto a sphere. Since it is impossible to map something flat | |
179 * perfectly onto something spherical, there is distortion at the | |
180 * poles. This particular implementation causes the poles along the X | |
181 * axis to be distorted. | |
182 * | |
183 * model - pointer to initialized GLMmodel structure | |
184 */ | |
185 GLvoid | |
186 glmSpheremapTexture(GLMmodel* model); | |
187 | |
188 /* glmDelete: Deletes a GLMmodel structure. | |
189 * | |
190 * model - initialized GLMmodel structure | |
191 */ | |
192 GLvoid | |
193 glmDelete(GLMmodel* model); | |
194 | |
195 /* glmReadOBJ: Reads a model description from a Wavefront .OBJ file. | |
196 * Returns a pointer to the created object which should be free'd with | |
197 * glmDelete(). | |
198 * | |
199 * filename - name of the file containing the Wavefront .OBJ format data. | |
200 */ | |
201 GLMmodel* | |
202 glmReadOBJ(char* filename); | |
203 | |
204 /* glmWriteOBJ: Writes a model description in Wavefront .OBJ format to | |
205 * a file. | |
206 * | |
207 * model - initialized GLMmodel structure | |
208 * filename - name of the file to write the Wavefront .OBJ format data to | |
209 * mode - a bitwise or of values describing what is written to the file | |
210 * GLM_NONE - write only vertices | |
211 * GLM_FLAT - write facet normals | |
212 * GLM_SMOOTH - write vertex normals | |
213 * GLM_TEXTURE - write texture coords | |
214 * GLM_FLAT and GLM_SMOOTH should not both be specified. | |
215 */ | |
216 GLvoid | |
217 glmWriteOBJ(GLMmodel* model, char* filename, GLuint mode); | |
218 | |
219 /* glmDraw: Renders the model to the current OpenGL context using the | |
220 * mode specified. | |
221 * | |
222 * model - initialized GLMmodel structure | |
223 * mode - a bitwise OR of values describing what is to be rendered. | |
224 * GLM_NONE - render with only vertices | |
225 * GLM_FLAT - render with facet normals | |
226 * GLM_SMOOTH - render with vertex normals | |
227 * GLM_TEXTURE - render with texture coords | |
228 * GLM_FLAT and GLM_SMOOTH should not both be specified. | |
229 */ | |
230 GLvoid | |
231 glmDraw(GLMmodel* model, GLuint mode); | |
232 | |
233 /* glmList: Generates and returns a display list for the model using | |
234 * the mode specified. | |
235 * | |
236 * model - initialized GLMmodel structure | |
237 * mode - a bitwise OR of values describing what is to be rendered. | |
238 * GLM_NONE - render with only vertices | |
239 * GLM_FLAT - render with facet normals | |
240 * GLM_SMOOTH - render with vertex normals | |
241 * GLM_TEXTURE - render with texture coords | |
242 * GLM_FLAT and GLM_SMOOTH should not both be specified. | |
243 */ | |
244 GLuint | |
245 glmList(GLMmodel* model, GLuint mode); | |
246 | |
247 /* glmWeld: eliminate (weld) vectors that are within an epsilon of | |
248 * each other. | |
249 * | |
250 * model - initialized GLMmodel structure | |
251 * epsilon - maximum difference between vertices | |
252 * ( 0.00001 is a good start for a unitized model) | |
253 * | |
254 */ | |
255 GLvoid | |
256 glmWeld(GLMmodel* model, GLfloat epsilon); | |
257 | |
258 GLMmat_str* | |
259 glmMTL(char* name); | |
260 | |
261 void | |
262 glmSetMat(GLMmat_str* mats, GLint index); | |
263 | |
264 # ifdef __cplusplus | |
265 } | |
266 # endif /* __cplusplus */ | |
267 | |
268 | |
269 #endif |