root / branches / simulator / projects / simulator / simulator / core / world.h @ 1042
History | View | Annotate | Download (2.29 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 | #define RAY_MISS 1E30 |
||
30 | #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 MAX_OBJS 100 |
||
36 | #define BUF_SIZE 512 |
||
37 | |||
38 | 1021 | bpoole | typedef struct { |
39 | double x;
|
||
40 | double y;
|
||
41 | } point_t; |
||
42 | |||
43 | typedef struct { |
||
44 | point_t p1; /* Lower left point */
|
||
45 | point_t p2; /* Upper right point */
|
||
46 | 1026 | bpoole | } bbox_t, rect_t, seg_t; |
47 | 1021 | bpoole | |
48 | typedef struct { |
||
49 | 1022 | bpoole | point_t p; /* origin */
|
50 | double d; /* direction */ |
||
51 | } ray_t; |
||
52 | |||
53 | typedef struct { |
||
54 | 1026 | bpoole | int type;
|
55 | int num_pts;
|
||
56 | point_t *pts; |
||
57 | } poly_t; |
||
58 | |||
59 | typedef struct { |
||
60 | 1021 | bpoole | int id;
|
61 | bbox_t *bbox; |
||
62 | void *props; /* shape-specific properties */ |
||
63 | } object_t; |
||
64 | |||
65 | typedef struct { |
||
66 | 1040 | bpoole | int max_objs;
|
67 | int cur_objs;
|
||
68 | 1021 | bpoole | object_t *objs; |
69 | 1040 | bpoole | bbox_t win; |
70 | 1021 | bpoole | } world_t; |
71 | |||
72 | 1022 | bpoole | /* Specific collision functions */
|
73 | 1026 | bpoole | double collide(ray_t *ray, object_t *obj);
|
74 | 1022 | bpoole | double collide_circle(ray_t *ray, object_t *obj);
|
75 | double collide_rect(ray_t *ray, object_t *obj);
|
||
76 | 1026 | bpoole | double collide_poly(ray_t *ray, object_t *obj);
|
77 | 1042 | bpoole | double collide_world(ray_t *ray);
|
78 | |||
79 | 1022 | bpoole | /* Array of function pointers to the specific collide functions.
|
80 | * Must be listed in the same order as IDs */
|
||
81 | 1026 | bpoole | extern double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj); |
82 | extern int (*create_func[NUM_SHAPES])(object_t *obj, va_list ap); |
||
83 | 1040 | bpoole | extern int (*destroy_func[NUM_SHAPES])(object_t *obj); |
84 | extern world_t world;
|
||
85 | 1022 | bpoole | |
86 | 1040 | bpoole | int init_world(int num_objs, bbox_t b); |
87 | int destroy_world(void); |
||
88 | 1026 | bpoole | int create_poly(object_t *obj, va_list ap);
|
89 | 1040 | bpoole | int destroy_poly(object_t *obj);
|
90 | 1026 | bpoole | object_t *create(int id, ...);
|
91 | |||
92 | 1040 | bpoole | void print_world(void); |
93 | void print_object(object_t *obj);
|
||
94 | |||
95 | 1041 | chihsiuh | |
96 | /* WORLD 0 0 512 512
|
||
97 | * POLYGON 3 CONNECTED 1 2 3 4 5 6
|
||
98 | */
|
||
99 | int load_world (const char* filename); |
||
100 | int load_object (const char* line); |
||
101 | int starts_with (const char* line, const char* word); |
||
102 | |||
103 | 1021 | bpoole | #endif
|