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