Statistics
| Revision:

root / branches / simulator / projects / simulator / simulator / core / world.h @ 1042

History | View | Annotate | Download (2.29 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
#include <string.h>
16
#include <stdio.h>
17
#include <stdlib.h>
18

    
19
#define ID_OFFSET -1
20
#define ID_RECTANGLE 3
21
#define ID_CIRCLE 2
22
#define ID_NULL 0
23
#define ID_POLY 1
24
#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
#define PBBOX(b) {printf("(%g,%g) --> (%g, %g)\n",(b).p1.x,(b).p1.y,(b).p2.x,\
32
                                                  (b).p2.y);}
33
#define PRAY(v) {printf("(%g,%g), %g\n", (v).p.x, (v).p.y,(v).d);}
34

    
35
#define MAX_OBJS 100
36
#define BUF_SIZE 512
37

    
38
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
} bbox_t, rect_t, seg_t;
47

    
48
typedef struct {
49
    point_t p; /* origin */
50
    double d; /* direction */
51
} ray_t;
52

    
53
typedef struct {
54
    int type;
55
    int num_pts;
56
    point_t *pts;
57
} poly_t;
58

    
59
typedef struct {
60
    int id;
61
    bbox_t *bbox;
62
    void *props; /* shape-specific properties */
63
} object_t;
64

    
65
typedef struct {
66
    int max_objs;
67
    int cur_objs;
68
    object_t *objs;
69
    bbox_t win; 
70
} world_t;
71

    
72
/* Specific collision functions */
73
double collide(ray_t *ray, object_t *obj);
74
double collide_circle(ray_t *ray, object_t *obj);
75
double collide_rect(ray_t *ray, object_t *obj);
76
double collide_poly(ray_t *ray, object_t *obj);
77
double collide_world(ray_t *ray);
78

    
79
/*  Array of function pointers to the specific collide functions.
80
 *  Must be listed in the same order as IDs */
81
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
extern int (*destroy_func[NUM_SHAPES])(object_t *obj);
84
extern world_t world;
85

    
86
int init_world(int num_objs, bbox_t b);
87
int destroy_world(void);
88
int create_poly(object_t *obj, va_list ap);
89
int destroy_poly(object_t *obj);
90
object_t *create(int id, ...);
91

    
92
void print_world(void);
93
void print_object(object_t *obj);
94

    
95

    
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
#endif
104