3f3172fde3389dab9ef723466d6cf8a8f23f698f
[neverball] / share / solid.h
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #ifndef SOL_H
16 #define SOL_H
17
18 #include "glext.h"
19 #include "base_config.h"
20
21 /*
22  * Some might  be taken  aback at  the terseness of  the names  of the
23  * structure  members and  the variables  used by  the  functions that
24  * access them.  Yes, yes, I know:  readability.  I  contend that once
25  * the naming  convention is embraced, the names  become more readable
26  * than any  verbose alternative, and their brevity  and uniformity do
27  * more to augment readability than longVariableNames ever could.
28  *
29  * Members  and variables  are named  XY.   X determines  the type  of
30  * structure to which the variable  refers.  Y determines the usage of
31  * the variable.
32  *
33  * The Xs are as documented by struct s_file:
34  *
35  *     f  File          (struct s_file)
36  *     m  Material      (struct s_mtrl)
37  *     v  Vertex        (struct s_vert)
38  *     e  Edge          (struct s_edge)
39  *     s  Side          (struct s_side)
40  *     t  Texture coord (struct s_texc)
41  *     g  Geometry      (struct s_geom)
42  *     l  Lump          (struct s_lump)
43  *     n  Node          (struct s_node)
44  *     p  Path          (struct s_path)
45  *     b  Body          (struct s_body)
46  *     h  Item          (struct s_item)
47  *     z  Goal          (struct s_goal)
48  *     j  Jump          (struct s_jump)
49  *     x  Switch        (struct s_swch)
50  *     r  Billboard     (struct s_bill)
51  *     u  User          (struct s_ball)
52  *     w  Viewpoint     (struct s_view)
53  *     d  Dictionary    (struct s_dict)
54  *     i  Index         (int)
55  *     a  Text          (char)
56  *
57  * The Ys are as follows:
58  *
59  *     c  Counter
60  *     p  Pointer
61  *     v  Vector (array)
62  *     0  Index of the first
63  *     i  Index
64  *     j  Subindex
65  *     k  Subsubindex
66  *
67  * Thus "up" is a pointer to  a user structure.  "lc" is the number of
68  * lumps.  "ei" and "ej" are  edge indices into some "ev" edge vector.
69  * An edge is  defined by two vertices, so  an edge structure consists
70  * of "vi" and "vj".  And so on.
71  *
72  * Those members that do not conform to this convention are explicitly
73  * documented with a comment.
74  *
75  * These prefixes are still available: c k o q y.
76  */
77
78 /*---------------------------------------------------------------------------*/
79
80 /* Material type flags */
81
82 #define M_OPAQUE       1
83 #define M_TRANSPARENT  2
84 #define M_REFLECTIVE   4
85 #define M_ENVIRONMENT  8
86 #define M_ADDITIVE    16
87 #define M_CLAMPED     32
88 #define M_DECAL       64
89 #define M_SHADOWED (M_OPAQUE | M_REFLECTIVE)
90
91 /* Billboard types. */
92
93 #define B_EDGE     1
94 #define B_FLAT     2
95 #define B_ADDITIVE 4
96
97 /* Lump flags. */
98
99 #define L_DETAIL   1
100
101 /* Item types. */
102
103 #define ITEM_NONE       0
104 #define ITEM_COIN       1
105 #define ITEM_GROW       2
106 #define ITEM_SHRINK     3
107
108 /*---------------------------------------------------------------------------*/
109
110 struct s_mtrl
111 {
112     float a[4];                                /* ambient color              */
113     float d[4];                                /* diffuse color              */
114     float s[4];                                /* specular color             */
115     float e[4];                                /* emission color             */
116     float h[1];                                /* specular exponent          */
117     float angle;
118
119     int fl;                                    /* material flags             */
120
121     GLuint o;                                  /* OpenGL texture object      */
122     char   f[PATHMAX];                         /* texture file name          */
123 };
124
125 struct s_vert
126 {
127     float p[3];                                /* vertex position            */
128 };
129
130 struct s_edge
131 {
132     int vi;
133     int vj;
134 };
135
136 struct s_side
137 {
138     float n[3];                                /* plane normal vector        */
139     float d;                                   /* distance from origin       */
140 };
141
142 struct s_texc
143 {
144     float u[2];                                /* texture coordinate         */
145 };
146
147 struct s_geom
148 {
149     int mi;
150     int ti, si, vi;
151     int tj, sj, vj;
152     int tk, sk, vk;
153 };
154
155 struct s_lump
156 {
157     int fl;                                    /* lump flags                 */
158     int v0, vc;
159     int e0, ec;
160     int g0, gc;
161     int s0, sc;
162 };
163
164 struct s_node
165 {
166     int si;
167     int ni;
168     int nj;
169     int l0;
170     int lc;
171 };
172
173 struct s_path
174 {
175     float p[3];                                /* starting position          */
176     float t;                                   /* travel time                */
177
178     int pi;
179     int f;                                     /* enable flag                */
180     int s;                                     /* smooth flag                */
181 };
182
183 struct s_body
184 {
185     float t;                                   /* time on current path       */
186
187     GLuint ol;                                 /* opaque geometry list       */
188     GLuint tl;                                 /* transparent geometry list  */
189     GLuint rl;                                 /* reflective geometry list   */
190     GLuint sl;                                 /* shadowed geometry list     */
191
192     int pi;
193     int ni;
194     int l0;
195     int lc;
196     int g0;
197     int gc;
198 };
199
200 struct s_item
201 {
202     float p[3];                                /* position                   */
203     int   t;                                   /* type                       */
204     int   n;                                   /* value                      */
205 };
206
207 struct s_goal
208 {
209     float p[3];                                /* position                   */
210     float r;                                   /* radius                     */
211 };
212
213 struct s_swch
214 {
215     float p[3];                                /* position                   */
216     float r;                                   /* radius                     */
217     int  pi;                                   /* the linked path            */
218
219     float t0;                                  /* default timer              */
220     float t;                                   /* current timer              */
221     int   f0;                                  /* default state              */
222     int   f;                                   /* current state              */
223     int   i;                                   /* is invisible?              */
224     int   e;                                   /* is a ball inside it?       */
225 };
226
227 struct s_bill
228 {
229     int  fl;
230     int  mi;
231     float t;                                   /* repeat time interval       */
232     float d;                                   /* distance                   */
233
234     float w[3];                                /* width coefficients         */
235     float h[3];                                /* height coefficients        */
236
237     float rx[3];                               /* X rotation coefficients    */
238     float ry[3];                               /* Y rotation coefficients    */
239     float rz[3];                               /* Z rotation coefficients    */
240 };
241
242 struct s_jump
243 {
244     float p[3];                                /* position                   */
245     float q[3];                                /* target position            */
246     float r;                                   /* radius                     */
247 };
248
249 struct s_ball
250 {
251     float e[3][3];                             /* basis of orientation       */
252     float p[3];                                /* position vector            */
253     float v[3];                                /* velocity vector            */
254     float w[3];                                /* angular velocity vector    */
255     float r;                                   /* radius                     */
256 };
257
258 struct s_view
259 {
260     float p[3];
261     float q[3];
262 };
263
264 struct s_dict
265 {
266     int ai;
267     int aj;
268 };
269
270 struct s_file
271 {
272     int ac;
273     int mc;
274     int vc;
275     int ec;
276     int sc;
277     int tc;
278     int gc;
279     int lc;
280     int nc;
281     int pc;
282     int bc;
283     int hc;
284     int zc;
285     int jc;
286     int xc;
287     int rc;
288     int uc;
289     int wc;
290     int dc;
291     int ic;
292
293     char          *av;
294     struct s_mtrl *mv;
295     struct s_vert *vv;
296     struct s_edge *ev;
297     struct s_side *sv;
298     struct s_texc *tv;
299     struct s_geom *gv;
300     struct s_lump *lv;
301     struct s_node *nv;
302     struct s_path *pv;
303     struct s_body *bv;
304     struct s_item *hv;
305     struct s_goal *zv;
306     struct s_jump *jv;
307     struct s_swch *xv;
308     struct s_bill *rv;
309     struct s_ball *uv;
310     struct s_view *wv;
311     struct s_dict *dv;
312     int           *iv;
313 };
314
315 /*---------------------------------------------------------------------------*/
316
317 void sol_body_p(float p[3], const struct s_file *, const struct s_body *);
318
319 /*---------------------------------------------------------------------------*/
320
321 int   sol_load_only_file(struct s_file *, const char *);
322 int   sol_load_only_head(struct s_file *, const char *);
323 int   sol_stor(struct s_file *, const char *);
324 void  sol_free(struct s_file *);
325
326 float sol_step(struct s_file *, const float *, float, int, int *);
327
328 int   sol_jump_test(struct s_file *, float *, int);
329 int   sol_swch_test(struct s_file *, int);
330
331 struct s_goal *sol_goal_test(struct s_file *, float *, int);
332 struct s_item *sol_item_test(struct s_file *, float *, float);
333
334 /*---------------------------------------------------------------------------*/
335
336 void put_file_state(FILE *, struct s_file *);
337 void get_file_state(FILE *, struct s_file *);
338
339 /*---------------------------------------------------------------------------*/
340
341 #endif