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