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