root / branches / simulator / projects / simulator / simulator / core / world.h @ 1040
History | View | Annotate | Download (1.9 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_OFFSET -1 |
| 17 | #define ID_RECTANGLE 3 |
| 18 | #define ID_CIRCLE 2 |
| 19 | #define ID_NULL 0 |
| 20 | #define ID_POLY 1 |
| 21 | #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 | #define PBBOX(b) {printf("(%g,%g) --> (%g, %g)\n",(b).p1.x,(b).p1.y,(b).p2.x,\ |
| 29 | (b).p2.y);} |
| 30 | 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 | } bbox_t, rect_t, seg_t; |
| 39 | |
| 40 | typedef struct { |
| 41 | point_t p; /* origin */
|
| 42 | double d; /* direction */ |
| 43 | } ray_t; |
| 44 | |
| 45 | typedef struct { |
| 46 | int type;
|
| 47 | int num_pts;
|
| 48 | point_t *pts; |
| 49 | } poly_t; |
| 50 | |
| 51 | typedef struct { |
| 52 | int id;
|
| 53 | bbox_t *bbox; |
| 54 | void *props; /* shape-specific properties */ |
| 55 | } object_t; |
| 56 | |
| 57 | typedef struct { |
| 58 | int max_objs;
|
| 59 | int cur_objs;
|
| 60 | object_t *objs; |
| 61 | bbox_t win; |
| 62 | } world_t; |
| 63 | |
| 64 | /* Specific collision functions */
|
| 65 | double collide(ray_t *ray, object_t *obj);
|
| 66 | double collide_circle(ray_t *ray, object_t *obj);
|
| 67 | double collide_rect(ray_t *ray, object_t *obj);
|
| 68 | double collide_poly(ray_t *ray, object_t *obj);
|
| 69 | /* Array of function pointers to the specific collide functions.
|
| 70 | * Must be listed in the same order as IDs */ |
| 71 | 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 | extern int (*destroy_func[NUM_SHAPES])(object_t *obj); |
| 74 | extern world_t world;
|
| 75 | |
| 76 | int init_world(int num_objs, bbox_t b); |
| 77 | int destroy_world(void); |
| 78 | int create_poly(object_t *obj, va_list ap);
|
| 79 | int destroy_poly(object_t *obj);
|
| 80 | object_t *create(int id, ...);
|
| 81 | |
| 82 | void print_world(void); |
| 83 | void print_object(object_t *obj);
|
| 84 | |
| 85 | #endif
|
| 86 |