Revision 1026
working ray-polygon collisions, but needs a lot of clean up
world.h | ||
---|---|---|
11 | 11 |
#ifndef __WORLD_H__ |
12 | 12 |
#define __WORLD_H__ |
13 | 13 |
|
14 |
#define ID_RECTANGLE 0 |
|
14 |
#include <stdarg.h> |
|
15 |
|
|
16 |
#define ID_RECTANGLE 3 |
|
15 | 17 |
#define ID_CIRCLE 1 |
16 |
#define NUM_SHAPES 2 |
|
17 | 18 |
|
19 |
#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__)) |
|
18 | 27 |
typedef struct { |
19 | 28 |
double x; |
20 | 29 |
double y; |
... | ... | |
23 | 32 |
typedef struct { |
24 | 33 |
point_t p1; /* Lower left point */ |
25 | 34 |
point_t p2; /* Upper right point */ |
26 |
} bbox_t; |
|
35 |
} bbox_t, rect_t, seg_t;
|
|
27 | 36 |
|
28 | 37 |
typedef struct { |
29 | 38 |
point_t p; /* origin */ |
... | ... | |
31 | 40 |
} ray_t; |
32 | 41 |
|
33 | 42 |
typedef struct { |
43 |
int type; |
|
44 |
int num_pts; |
|
45 |
point_t *pts; |
|
46 |
} poly_t; |
|
47 |
|
|
48 |
typedef struct { |
|
34 | 49 |
int id; |
35 | 50 |
bbox_t *bbox; |
36 | 51 |
void *props; /* shape-specific properties */ |
... | ... | |
43 | 58 |
} world_t; |
44 | 59 |
|
45 | 60 |
/* Specific collision functions */ |
61 |
double collide(ray_t *ray, object_t *obj); |
|
46 | 62 |
double collide_circle(ray_t *ray, object_t *obj); |
47 | 63 |
double collide_rect(ray_t *ray, object_t *obj); |
48 |
|
|
64 |
double collide_poly(ray_t *ray, object_t *obj); |
|
49 | 65 |
/* Array of function pointers to the specific collide functions. |
50 | 66 |
* 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 |
}; |
|
67 |
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); |
|
56 | 69 |
|
70 |
|
|
71 |
int create_poly(object_t *obj, va_list ap); |
|
72 |
object_t *create(int id, ...); |
|
73 |
|
|
74 |
void destroy_poly (object_t *obj); |
|
57 | 75 |
#endif |
58 | 76 |
|
Also available in: Unified diff