[7f9531]: asteroids3D.h Maximize Restore History

Download this file

asteroids3D.h    460 lines (375 with data), 13.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/* Asteroids3D - a first person game of blowing up asteroids
* Copyright (C) 2000 Stuart Mark Pomerantz <smp [at] psc edu>
* Copyright Š Jan Engelhardt <jengelh [at] linux01 gwdg de>, 2003 - 2005
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Stuart Pomerantz
* 3935 Stonecliffe drive
* Monroeville, PA 15146
*/
#ifndef AS3D_H
#define AS3D_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
// for Frustum perspective projection (main.c, display.c)
#define FRUSTUM_LEFT -1
#define FRUSTUM_TOP 1
/*
* Asteroid generation parameters
*/
/*
* generate asteroids within a cubic space which is
* no further than this distance from the origin
*/
#define AGB 50.0 /* That's asteroid generation boundary */
#define MAX_ARD 180.0 /* max asteroid rotation delta (per unit time)*/
#define MAX_APD 20.0 /* max asteroid position delta length (per unit time)*/
#define ABOUND 90 /* asteroid torus wrapping boundary */
#define NUM_AST_TYPES 6 /* number of different kinds of asteroids/display lists */
#define MIN_AST_MASS 5.0
#define AST_MASS_K 10.0
/* Torpedos are the "bullets" in the game.
* You can only fire a few at a time
*/
#define MAX_TORPS 5
#define TORP_TTL 1.8
#define TORP_DELTA 25.0
#define TORP_RADIUS 0.5
#define TORP_RADIUS_DELTA 0.2
#define TORP_BB_ZROT 5 /* the number of degrees to rotate the torp billboard about the z axis */
/* torpedoes leave trails behind them */
#define MAX_TORP_TRAILS (MAX_TORPS*3)
#define TORP_TRAIL_LEN 25
/* number of dust particles */
#define NUM_DUST_PART 50
#define NUM_CHILD_DUST_PART 10
#define CHILD_DUST_PART_DELTA 20 /* maximum number of units a child can be from the parent dust particle */
/* for explosions */
#define MAX_BLASTS (MAX_TORPS+10)
#define BLAST_TTL 5
#define BLAST_ER 2.0 /* blast expansion rate */
#define NUM_BLAST_TYPES 5
/* initial shield/max shield strength, and shield recharge rate per second */
#define MAX_SHIELD 4000
#define SHIELD_REGEN_PS 10
/* When you run through an explosion the particles smack up
* against your "windshield" pretty much just a little eye candy
* anyway you could potentially ( though unlikely ) run through
* MAX_BLASTS explosions. And I need to also set about how many
* particles you impact per blast which is:
*/
#define NUM_WP_PER_BLAST 10
/* define the types of sounds that play_sound() recognizes */
#define SOUND_ASTEROID_HIT 0
#define SOUND_TARGET_AQUIRED 1
#define SOUND_COLLISION_WARN 2
#define SOUND_COLLISION 4
#define SOUND_TORP_FIRED 5
/* standard hud colors */
#define HUD_R 0.3
#define HUD_G 1.0
#define HUD_B 0.3
#define HUD_A 0.7
// Number of nebula billboard textures
#define NUM_NEBULA_TEX 4
#define NUM_ASTEROIDS 100 /* initial number of asteroids 150 is good */
/* these are keyboard rotation scaling factors notice that if you multiply
* KEYB_BASE_ROT_SCALE by KEYB_MAX_ROT_SCALE you get 1
*/
#define KEYB_BASE_ROT_SCALE 0.05
#define KEYB_MAX_ROT_SCALE 20
#define KEYB_SCALE_DECAY 2
/*
* structures / typedefs
*/
typedef struct vector {
double x, y, z, w;
} Vector;
typedef struct asteroid {
double mass; /* BASED ON TYPE */
int type; /* which asteroid display list to use */
double radius; /* radius to use for collisions -- BASED ON TYPE */
Vector pos; /* current position */
Vector velocity; /* vector along which asteroid moves */
int rot ; /* current degrees of rotation */
int rot_delta ; /* degress to rotate per unit time */
Vector rot_axis; /* axis asteroid rotates around */
} Asteroid;
typedef struct torpedo {
int in_flight_flag ;
int is_tracer ;
int trail_num ;
double ttl; // time to live
Vector pos;
Vector pos_delta;
int bb_zrot ; /* the number of degrees to rotate the torp billboard about the z axis */
} Torpedo;
typedef struct torpedo_trail {
int is_running_flag ;
int is_ending_flag ;
int trail_start ;
int trail_end ;
Vector pos[TORP_TRAIL_LEN];
} TorpedoTrail;
typedef struct node {
Asteroid rock;
struct node *next;
} Node;
typedef struct blast {
int is_active ;
double ttl;
Vector pos;
float scalar ;
int type; // which explosion display list to use
} Blast;
typedef struct wind_part {
Vector pos; // position on windshield glass
double size; // size of impact circle
double t_start; // time to start
double t_end; // time to end
} WindPart;
typedef struct keyboard_map {
/* primary control keys */
char end_game ;
char pause ;
/* movement keys */
char slide_forward ;
char slide_backward ;
char slide_left ;
char slide_right ;
char slide_up ;
char slide_down ;
char stop ;
char rot_aboutx_cw ;
char rot_aboutx_ccw ;
char rot_abouty_cw ;
char rot_abouty_ccw ;
char rot_aboutz_cw ;
char rot_aboutz_ccw ;
char headlight_toggle ;
char target_asteroid ;
char auto_target_asteroid ;
char fire_torp ;
/* feature toggles */
char crosshair_toggle ;
char draw_tracer_toggle ;
char draw_shield_toggle ;
char draw_dust_toggle ;
char draw_torp_lensflare_toggle ;
char asteroid_texture_toggle ;
char nebula_texture_toggle ;
char torp_texture_toggle ;
char axes_toggle ;
char play_sound_toggle ;
char reverse_mouse_x_toggle ;
char reverse_mouse_y_toggle ;
} KeyboardMap;
typedef struct user_options_map {
/* Flags for user preferences 0=off 1=on */
int antialias_flag; // smoothen out lines
int axes_flag ; /* turn on and off the absolute x,y,z axes. I use this for debugging. */
int crosshair_flag ; /* turn the blue crosshair on or off */
int draw_tracer_flag ; /* should the torpedo tracer light be drawn */
int draw_shield_flag ; /* should the green alpha-blended shield effect be used */
int draw_dust_flag ; /* should the dust particles be drawn */
int texture_flag ; /* should the asteroids be textured */
int nebula_texture_flag ; /* should the nebula textures be used */
int play_sound_flag ; /* should sound be used */
int torp_texture_flag ; /* should the torps be textured */
int draw_torp_lensflare_flag ; /* should the torp lens flares be drawn */
/* more user preferences */
double mouse_xdir; /* 1 = mouse movement turns the normal direction, -1 = mouse movement turns opposite direction (should be -1 or 1 only) */
double mouse_ydir; /* 1 = mouse movement turns the normal direction, -1 = mouse movement turns opposite direction (should be -1 or 1 only) */
int num_asteroids ; /* number of asteroids, set by #define or command line */
int windowx ; /* window x size, changed in reshape(). set by #define or on command line */
int windowy ; /* window y size, changed in reshape(). set by #define or on command line */
int window_xpos ; /* window left corner x offset */
int window_ypos ; /* window left corner y offset */
} UserOptionsMap;
/*
*
* FUNCTION AND EXTERNAL VARIABLE DECLARATIONS
*
*/
/* defined in main.c */
extern int mouse_rotx_flag, mouse_roty_flag, mouse_x, mouse_y;
extern double mouse_xprop, mouse_yprop;
extern int game_end_flag;
extern unsigned long ticks;
extern double dt, tps;
extern sem_t run_yield;
extern void mouse_handler(int, int, int, int);
extern void passive_mouse_handler(int, int);
extern void end_game(void);
/* defined in oglutils.c */
extern void draw_axes(void);
extern void apply_v2m(Vector *, const double *);
extern int gen_rand_int(int, int);
extern void gen_rand_vec(Vector *);
extern double gen_rand_float(double, double);
extern void draw_rectangle(void);
extern void find_rotation_angles(const Vector *, double *, double *);
extern void find_rotation_mat(double, const Vector *, double *);
/* view.c */
extern Vector xaxis, yaxis, zaxis, pos;
extern void reset_view(void);
extern void rotate_view_aboutx(double);
extern void rotate_view_abouty(double);
extern void rotate_view_aboutz(double);
/* move.c */
extern Vector rotation;
extern void slide_alongx(double);
extern void slide_alongy(double);
extern void slide_alongz(double);
extern void turn_aboutx(double);
extern void turn_abouty(double);
extern void turn_aboutz(double);
/* display.c */
extern void display(void);
/* light.c */
extern float l0_pos[], l1_pos[], l1_dir[];
extern void gl_init_light(void);
extern void toggle_headlight(void);
extern void update_headlight(void);
extern void gl_init_headlight(void);
/* thrust.c */
extern Vector thrust, velocity;
extern void init_thrust(void) ;
extern void process_motion(int);
extern void apply_thrust(int);
extern void stop(void) ;
/* asteroid.c */
extern Node *al_head, *al_tail, *delete_next_ast[];
extern int ast_dl[], num_asteroids_on_scanner;
extern unsigned int ast_tex[];
extern void process_asteroid_motion(int);
extern void init_asteroids(void);
extern Node *add_node(void);
/* torpedo.c */
extern Torpedo torp[], sorted_torp[];
extern int torp_dl, torp_billboard_dl, torps_in_flight_flag, tracer_light_flag;
extern unsigned int torp_tex;
extern TorpedoTrail torp_trail[];
extern void init_torpedo(void);
extern void fire_torpedo(void);
extern void process_torpedo_motion(int);
extern void init_torps(void);
extern void init_torpedo_trails(void);
extern void process_torpedo_trails(void);
extern void calc_torp_billboard_rot(const Vector *, double *, double *);
extern void draw_torp_plasma(void);
/* collision.c */
extern void check_collision(Node *);
extern void apply_collision_v(Vector *, int);
extern void correct_positions(Vector *, Vector *, double);
extern void process_deleted_ast(void);
/* shield.c */
extern int shield_dl, shield_ttl, shield_activated_flag;
extern float shield_strength;
extern void init_shield(void);
extern void process_shield(void);
/* hud.c */
extern double flicker_hud_ttl;
extern int cwg_rear, cwg_above, cwg_below, cwg_left, cwg_right;
extern void draw_crosshair(void);
extern void draw_text_in_color(double, double, const char *, double, double, double, double);
extern void draw_shield_gauge(void);
extern void init_hud(void);
extern void draw_collision_warning_gauge(void);
extern void scan_for_collision_warning(Asteroid *);
extern int draw_gauge(void);
extern void draw_torp_gauge(void);
/* sun.c */
extern int sun_dl;
extern void init_sun(void);
extern void init_nebula_billboards(void);
extern void init_lens_flares(void);
extern void draw_sun_lensflares(void);
extern void draw_torp_lensflares(void);
/* explosion.c */
extern Blast explosion[];
extern int expl_dl[], expl_winshield_particle_dl,
expl_winshield_particle_count, explosions_active_flag;
extern void activate_explosion(const Vector *);
extern void init_explosions(void);
extern void process_explosion(void);
/* calc_frame.c */
extern void *calculate_frame(void *);
extern void capture_passive_mouse_input(void);
/* dust.c */
extern Vector dust_part[][NUM_CHILD_DUST_PART];
extern void init_dust(void);
extern void process_dust(void);
/* target.c */
extern Node *currently_targeted_asteroid;
extern void target_asteroid(void);
extern void init_target_dls(void);
extern void draw_lcs(const Asteroid *);
extern void draw_steering_cue(const Asteroid *);
extern int is_targeted(const Asteroid *);
extern void drop_target(void);
extern void draw_target_vector(const Asteroid *);
extern void draw_target_box(const Asteroid *);
extern void auto_target_asteroid(void);
/* split.c */
extern void add_new_asteroids(const Vector *, int);
/* texture.c */
extern int nebula_dl[];
extern unsigned int nebula_tex[];
extern void init_textures(void);
/* wind_part.c */
extern WindPart winshield_particle[];
extern void init_wind_parts(void);
extern void gen_rand_wind_part(WindPart *, double);
/* pause.c */
extern int paused_flag;
extern int paused(void);
extern void start_pause(void);
extern void paused_display(void);
/* score.c */
extern unsigned int score;
extern double difficulty_multiplier;
extern void add_rock_to_score(const Asteroid *);
extern void init_score_display(void);
/* sound.c */
extern void init_sound(void);
extern void play_sound(int, int);
extern void process_sound(void);
/* rcfile.c */
extern UserOptionsMap optmap;
extern char *rcfile;
extern void read_rcfile(void) ;
extern void write_rcfile_to_terminal(int);
extern char *key_char2str(char, char *, size_t);
extern char *strip_nl(char *);
/* keyb.c */
extern KeyboardMap keymap, keymap_old;
extern int keyb_rotx_scalar, keyb_roty_scalar, keyb_rotz_scalar;
extern void keyboard_handler(unsigned char, int, int);
extern void decay_keyb_rotx_scalar(void);
extern void decay_keyb_roty_scalar(void);
extern void decay_keyb_rotz_scalar(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // AS3D_H
//=============================================================================