root / branches / simulator / projects / simulator / simulator / core / world.h @ 1068
History | View | Annotate | Download (2.23 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 | 1041 | chihsiuh | #include <string.h> |
16 | #include <stdio.h> |
||
17 | #include <stdlib.h> |
||
18 | 1026 | bpoole | |
19 | 1040 | bpoole | #define ID_OFFSET -1 |
20 | 1026 | bpoole | #define ID_RECTANGLE 3 |
21 | 1040 | bpoole | #define ID_CIRCLE 2 |
22 | #define ID_NULL 0 |
||
23 | #define ID_POLY 1 |
||
24 | 1026 | bpoole | #define POLY_DISCONNECTED 0 |
25 | #define POLY_CONNECTED 1 |
||
26 | #define POLY_RECT 2 |
||
27 | |||
28 | #define NUM_SHAPES 3 |
||
29 | 1045 | bpoole | #define RAY_MISS 10000 |
30 | 1026 | bpoole | #define CREATE(id, ...) (create_func[id](__VA_ARGS__))
|
31 | 1040 | bpoole | #define PBBOX(b) {printf("(%g,%g) --> (%g, %g)\n",(b).p1.x,(b).p1.y,(b).p2.x,\ |
32 | (b).p2.y);} |
||
33 | 1042 | bpoole | #define PRAY(v) {printf("(%g,%g), %g\n", (v).p.x, (v).p.y,(v).d);} |
34 | 1041 | chihsiuh | |
35 | #define BUF_SIZE 512 |
||
36 | |||
37 | 1021 | bpoole | typedef struct { |
38 | double x;
|
||
39 | double y;
|
||
40 | } point_t; |
||
41 | |||
42 | typedef struct { |
||
43 | point_t p1; /* Lower left point */
|
||
44 | point_t p2; /* Upper right point */
|
||
45 | 1026 | bpoole | } bbox_t, rect_t, seg_t; |
46 | 1021 | bpoole | |
47 | typedef struct { |
||
48 | 1022 | bpoole | point_t p; /* origin */
|
49 | double d; /* direction */ |
||
50 | } ray_t; |
||
51 | |||
52 | typedef struct { |
||
53 | 1026 | bpoole | int type;
|
54 | int num_pts;
|
||
55 | point_t *pts; |
||
56 | } poly_t; |
||
57 | |||
58 | typedef struct { |
||
59 | 1021 | bpoole | int id;
|
60 | bbox_t *bbox; |
||
61 | void *props; /* shape-specific properties */ |
||
62 | } object_t; |
||
63 | |||
64 | typedef struct { |
||
65 | 1040 | bpoole | int max_objs;
|
66 | int cur_objs;
|
||
67 | 1021 | bpoole | object_t *objs; |
68 | 1040 | bpoole | bbox_t win; |
69 | 1021 | bpoole | } world_t; |
70 | |||
71 | 1022 | bpoole | /* Specific collision functions */
|
72 | 1026 | bpoole | double collide(ray_t *ray, object_t *obj);
|
73 | 1022 | bpoole | double collide_circle(ray_t *ray, object_t *obj);
|
74 | double collide_rect(ray_t *ray, object_t *obj);
|
||
75 | 1026 | bpoole | double collide_poly(ray_t *ray, object_t *obj);
|
76 | 1042 | bpoole | double collide_world(ray_t *ray);
|
77 | |||
78 | 1022 | bpoole | /* Array of function pointers to the specific collide functions.
|
79 | * Must be listed in the same order as IDs */
|
||
80 | 1026 | bpoole | extern double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj); |
81 | extern int (*create_func[NUM_SHAPES])(object_t *obj, va_list ap); |
||
82 | 1040 | bpoole | extern int (*destroy_func[NUM_SHAPES])(object_t *obj); |
83 | extern world_t world;
|
||
84 | 1022 | bpoole | |
85 | 1040 | bpoole | int init_world(int num_objs, bbox_t b); |
86 | int destroy_world(void); |
||
87 | 1026 | bpoole | int create_poly(object_t *obj, va_list ap);
|
88 | 1040 | bpoole | int destroy_poly(object_t *obj);
|
89 | 1026 | bpoole | object_t *create(int id, ...);
|
90 | |||
91 | 1040 | bpoole | void print_world(void); |
92 | void print_object(object_t *obj);
|
||
93 | |||
94 | 1041 | chihsiuh | |
95 | /* WORLD 0 0 512 512
|
||
96 | * POLYGON 3 CONNECTED 1 2 3 4 5 6
|
||
97 | */
|
||
98 | 1043 | chihsiuh | int load_world (const char* filename, int max_objs); |
99 | 1041 | chihsiuh | int load_object (const char* line); |
100 | |||
101 | 1021 | bpoole | #endif
|