Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (2.23 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 BUF_SIZE 512
36

    
37
typedef struct {
38
    double x;
39
    double y;
40
} point_t;
41

    
42
typedef struct {
43
    point_t p1; /* Lower left point */
44
    point_t p2; /* Upper right point */
45
} bbox_t, rect_t, seg_t;
46

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

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

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

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

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

    
78
/*  Array of function pointers to the specific collide functions.
79
 *  Must be listed in the same order as IDs */
80
extern double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj);
81
extern int (*create_func[NUM_SHAPES])(object_t *obj, va_list ap);
82
extern int (*destroy_func[NUM_SHAPES])(object_t *obj);
83
extern world_t world;
84

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

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

    
94

    
95
/* WORLD 0 0 512 512
96
 * POLYGON 3 CONNECTED 1 2 3 4 5 6
97
 */   
98
int load_world (const char* filename, int max_objs);
99
int load_object (const char* line);
100

    
101
#endif
102