Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / simulator / core / world.h @ 1040

History | View | Annotate | Download (1.9 KB)

1 1021 bpoole
/**
2
 * @file world.h
3
 * @author Colony Project
4
 *
5 1022 bpoole
 * @brief THE WHOLE WIDE WORLD
6 1021 bpoole
 *
7
 * Contains structures and function prototypes used
8 1022 bpoole
 * for managing the world.
9 1021 bpoole
 **/
10
11
#ifndef __WORLD_H__
12
#define __WORLD_H__
13
14 1026 bpoole
#include <stdarg.h>
15
16 1040 bpoole
#define ID_OFFSET -1
17 1026 bpoole
#define ID_RECTANGLE 3
18 1040 bpoole
#define ID_CIRCLE 2
19
#define ID_NULL 0
20
#define ID_POLY 1
21 1026 bpoole
#define POLY_DISCONNECTED 0
22
#define POLY_CONNECTED 1
23
#define POLY_RECT 2
24
25
#define NUM_SHAPES 3
26
#define RAY_MISS 1E30
27
#define CREATE(id, ...) (create_func[id](__VA_ARGS__))
28 1040 bpoole
#define PBBOX(b) {printf("(%g,%g) --> (%g, %g)\n",(b).p1.x,(b).p1.y,(b).p2.x,\
29
                                                  (b).p2.y);}
30 1021 bpoole
typedef struct {
31
    double x;
32
    double y;
33
} point_t;
34
35
typedef struct {
36
    point_t p1; /* Lower left point */
37
    point_t p2; /* Upper right point */
38 1026 bpoole
} bbox_t, rect_t, seg_t;
39 1021 bpoole
40
typedef struct {
41 1022 bpoole
    point_t p; /* origin */
42
    double d; /* direction */
43
} ray_t;
44
45
typedef struct {
46 1026 bpoole
    int type;
47
    int num_pts;
48
    point_t *pts;
49
} poly_t;
50
51
typedef struct {
52 1021 bpoole
    int id;
53
    bbox_t *bbox;
54
    void *props; /* shape-specific properties */
55
} object_t;
56
57
typedef struct {
58 1040 bpoole
    int max_objs;
59
    int cur_objs;
60 1021 bpoole
    object_t *objs;
61 1040 bpoole
    bbox_t win;
62 1021 bpoole
} world_t;
63
64 1022 bpoole
/* Specific collision functions */
65 1026 bpoole
double collide(ray_t *ray, object_t *obj);
66 1022 bpoole
double collide_circle(ray_t *ray, object_t *obj);
67
double collide_rect(ray_t *ray, object_t *obj);
68 1026 bpoole
double collide_poly(ray_t *ray, object_t *obj);
69 1022 bpoole
/*  Array of function pointers to the specific collide functions.
70
 *  Must be listed in the same order as IDs */
71 1026 bpoole
extern double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj);
72
extern int (*create_func[NUM_SHAPES])(object_t *obj, va_list ap);
73 1040 bpoole
extern int (*destroy_func[NUM_SHAPES])(object_t *obj);
74
extern world_t world;
75 1022 bpoole
76 1040 bpoole
int init_world(int num_objs, bbox_t b);
77
int destroy_world(void);
78 1026 bpoole
int create_poly(object_t *obj, va_list ap);
79 1040 bpoole
int destroy_poly(object_t *obj);
80 1026 bpoole
object_t *create(int id, ...);
81
82 1040 bpoole
void print_world(void);
83
void print_object(object_t *obj);
84
85 1021 bpoole
#endif