707dcf520bff26aecd8769e420e6dc525c791071
[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_SHADOWED (M_OPAQUE | M_REFLECTIVE | M_ENVIRONMENT)
89
90 /* Billboard types. */
91
92 #define B_EDGE     1
93 #define B_FLAT     2
94 #define B_ADDITIVE 4
95
96 /* Lump flags. */
97
98 #define L_DETAIL   1
99
100 /* Item types. */
101
102 #define ITEM_NONE       0
103 #define ITEM_COIN       1
104 #define ITEM_GROW       2
105 #define ITEM_SHRINK     3
106
107 /*---------------------------------------------------------------------------*/
108
109 struct s_mtrl
110 {
111     float a[4];                                /* ambient color              */
112     float d[4];                                /* diffuse color              */
113     float s[4];                                /* specular color             */
114     float e[4];                                /* emission color             */
115     float h[1];                                /* specular exponent          */
116
117     int fl;                                    /* material flags             */
118
119     GLuint o;                                  /* OpenGL texture object      */
120     char   f[PATHMAX];                         /* texture file name          */
121 };
122
123 struct s_vert
124 {
125     float p[3];                                /* vertex position            */
126 };
127
128 struct s_edge
129 {
130     int vi;
131     int vj;
132 };
133
134 struct s_side
135 {
136     float n[3];                                /* plane normal vector        */
137     float d;                                   /* distance from origin       */
138 };
139
140 struct s_texc
141 {
142     float u[2];                                /* texture coordinate         */
143 };
144
145 struct s_geom
146 {
147     int mi;
148     int ti, si, vi;
149     int tj, sj, vj;
150     int tk, sk, vk;
151 };
152
153 struct s_lump
154 {
155     int fl;                                    /* lump flags                 */
156     int v0, vc;
157     int e0, ec;
158     int g0, gc;
159     int s0, sc;
160 };
161
162 struct s_node
163 {
164     int si;
165     int ni;
166     int nj;
167     int l0;
168     int lc;
169 };
170
171 struct s_path
172 {
173     float p[3];                                /* starting position          */
174     float t;                                   /* travel time                */
175
176     int pi;
177     int f;                                     /* enable flag                */
178 };
179
180 struct s_body
181 {
182     float t;                                   /* time on current path       */
183
184     GLuint ol;                                 /* opaque geometry list       */
185     GLuint tl;                                 /* transparent geometry list  */
186     GLuint rl;                                 /* reflective geometry list   */
187     GLuint sl;                                 /* shadowed geometry list     */
188
189     int pi;
190     int ni;
191     int l0;
192     int lc;
193     int g0;
194     int gc;
195 };
196
197 struct s_item
198 {
199     float p[3];                                /* position                   */
200     int   t;                                   /* type                       */
201     int   n;                                   /* value                      */
202 };
203
204 struct s_goal
205 {
206     float p[3];                                /* position                   */
207     float r;                                   /* radius                     */
208 };
209
210 struct s_swch
211 {
212     float p[3];                                /* position                   */
213     float r;                                   /* radius                     */
214     int  pi;                                   /* the linked path            */
215
216     float t0;                                  /* default timer              */
217     float t;                                   /* current timer              */
218     int   f0;                                  /* default state              */
219     int   f;                                   /* current state              */
220     int   i;                                   /* is invisible?              */
221     int   e;                                   /* is a ball inside it?       */
222 };
223
224 struct s_bill
225 {
226     int  fl;
227     int  mi;
228     float t;                                   /* repeat time interval       */
229     float d;                                   /* distance                   */
230
231     float w[3];                                /* width coefficients         */
232     float h[3];                                /* height coefficients        */
233
234     float rx[3];                               /* X rotation coefficients    */
235     float ry[3];                               /* Y rotation coefficients    */
236     float rz[3];                               /* Z rotation coefficients    */
237 };
238
239 struct s_jump
240 {
241     float p[3];                                /* position                   */
242     float q[3];                                /* target position            */
243     float r;                                   /* radius                     */
244 };
245
246 struct s_ball
247 {
248     float e[3][3];                             /* basis of orientation       */
249     float p[3];                                /* position vector            */
250     float v[3];                                /* velocity vector            */
251     float w[3];                                /* angular velocity vector    */
252     float r;                                   /* radius                     */
253 };
254
255 struct s_view
256 {
257     float p[3];
258     float q[3];
259 };
260
261 struct s_dict
262 {
263     int ai;
264     int aj;
265 };
266
267 struct s_file
268 {
269     int ac;
270     int mc;
271     int vc;
272     int ec;
273     int sc;
274     int tc;
275     int gc;
276     int lc;
277     int nc;
278     int pc;
279     int bc;
280     int hc;
281     int zc;
282     int jc;
283     int xc;
284     int rc;
285     int uc;
286     int wc;
287     int dc;
288     int ic;
289
290     char          *av;
291     struct s_mtrl *mv;
292     struct s_vert *vv;
293     struct s_edge *ev;
294     struct s_side *sv;
295     struct s_texc *tv;
296     struct s_geom *gv;
297     struct s_lump *lv;
298     struct s_node *nv;
299     struct s_path *pv;
300     struct s_body *bv;
301     struct s_item *hv;
302     struct s_goal *zv;
303     struct s_jump *jv;
304     struct s_swch *xv;
305     struct s_bill *rv;
306     struct s_ball *uv;
307     struct s_view *wv;
308     struct s_dict *dv;
309     int           *iv;
310 };
311
312 /*---------------------------------------------------------------------------*/
313
314 void sol_body_p(float p[3], const struct s_file *, const struct s_body *);
315
316 /*---------------------------------------------------------------------------*/
317
318 int   sol_load_only_file(struct s_file *, const char *);
319 int   sol_load_only_head(struct s_file *, const char *);
320 int   sol_stor(struct s_file *, const char *);
321 void  sol_free(struct s_file *);
322
323 float sol_step(struct s_file *, const float *, float, int, int *);
324
325 int   sol_jump_test(struct s_file *, float *, int);
326 int   sol_swch_test(struct s_file *, int);
327
328 struct s_goal *sol_goal_test(struct s_file *, float *, int);
329 struct s_item *sol_item_test(struct s_file *, float *, float);
330
331 /*---------------------------------------------------------------------------*/
332
333 void put_file_state(FILE *, struct s_file *);
334 void get_file_state(FILE *, struct s_file *);
335
336 /*---------------------------------------------------------------------------*/
337
338 #endif