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