root / branches / simulator / projects / simulator / simulator / core / world.h @ 1022
History | View | Annotate | Download (1.06 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 | 1022 | bpoole | #define ID_RECTANGLE 0 |
15 | #define ID_CIRCLE 1 |
||
16 | #define NUM_SHAPES 2 |
||
17 | 1021 | bpoole | |
18 | typedef struct { |
||
19 | double x;
|
||
20 | double y;
|
||
21 | } point_t; |
||
22 | |||
23 | typedef struct { |
||
24 | point_t p1; /* Lower left point */
|
||
25 | point_t p2; /* Upper right point */
|
||
26 | } bbox_t; |
||
27 | |||
28 | typedef struct { |
||
29 | 1022 | bpoole | point_t p; /* origin */
|
30 | double d; /* direction */ |
||
31 | } ray_t; |
||
32 | |||
33 | typedef struct { |
||
34 | 1021 | bpoole | int id;
|
35 | bbox_t *bbox; |
||
36 | void *props; /* shape-specific properties */ |
||
37 | } object_t; |
||
38 | |||
39 | typedef struct { |
||
40 | int num_objs;
|
||
41 | object_t *objs; |
||
42 | 1022 | bpoole | bbox_t world; |
43 | 1021 | bpoole | } world_t; |
44 | |||
45 | 1022 | bpoole | /* Specific collision functions */
|
46 | double collide_circle(ray_t *ray, object_t *obj);
|
||
47 | double collide_rect(ray_t *ray, object_t *obj);
|
||
48 | |||
49 | /* Array of function pointers to the specific collide functions.
|
||
50 | * Must be listed in the same order as IDs */
|
||
51 | double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj) =
|
||
52 | { |
||
53 | collide_rect, |
||
54 | collide_circle |
||
55 | }; |
||
56 | |||
57 | 1021 | bpoole | #endif
|