root / branches / simulator / projects / simulator / simulator / core / world.h @ 1026
History | View | Annotate | Download (1.56 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 | #define ID_RECTANGLE 3 |
||
17 | 1022 | bpoole | #define ID_CIRCLE 1 |
18 | 1021 | bpoole | |
19 | 1026 | bpoole | #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 | 1021 | bpoole | 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 | 1026 | bpoole | } bbox_t, rect_t, seg_t; |
36 | 1021 | bpoole | |
37 | typedef struct { |
||
38 | 1022 | bpoole | point_t p; /* origin */
|
39 | double d; /* direction */ |
||
40 | } ray_t; |
||
41 | |||
42 | typedef struct { |
||
43 | 1026 | bpoole | int type;
|
44 | int num_pts;
|
||
45 | point_t *pts; |
||
46 | } poly_t; |
||
47 | |||
48 | typedef struct { |
||
49 | 1021 | bpoole | 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 | 1022 | bpoole | bbox_t world; |
58 | 1021 | bpoole | } world_t; |
59 | |||
60 | 1022 | bpoole | /* Specific collision functions */
|
61 | 1026 | bpoole | double collide(ray_t *ray, object_t *obj);
|
62 | 1022 | bpoole | double collide_circle(ray_t *ray, object_t *obj);
|
63 | double collide_rect(ray_t *ray, object_t *obj);
|
||
64 | 1026 | bpoole | double collide_poly(ray_t *ray, object_t *obj);
|
65 | 1022 | bpoole | /* Array of function pointers to the specific collide functions.
|
66 | * Must be listed in the same order as IDs */
|
||
67 | 1026 | bpoole | 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 | 1022 | bpoole | |
70 | 1026 | bpoole | |
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 | 1021 | bpoole | #endif
|