Project

General

Profile

Revision 1022

Added by Ben Poole about 15 years ago

completed skeleton for the environment

View differences:

branches/simulator/projects/simulator/simulator/core/world.c
1
/**
2
 * @file world.c
3
 * @author Colony Project
4
 * @brief Simulator world code
5
 *
6
 * This is the world.
7
 **/
8

  
9
#include <stdio.h>
10
#include "world.h"
11

  
12

  
13
double collide_circle(ray_t *ray, object_t *obj){
14
    return -1;
15
}
16
double collide_rect(ray_t *ray, object_t *obj){
17
    return -2;
18
}
19

  
20
double collide(ray_t *ray, object_t *obj) {
21
    if (ray == NULL || obj == NULL)
22
	return -1;
23
    return collide_func[obj->id](ray, obj);
24
}
0 25

  
branches/simulator/projects/simulator/simulator/core/world.h
2 2
 * @file world.h
3 3
 * @author Colony Project
4 4
 *
5
 * @brief Manages simulated robots.
5
 * @brief THE WHOLE WIDE WORLD
6 6
 *
7 7
 * Contains structures and function prototypes used
8
 * for managing robots in the simulator.
8
 * for managing the world.
9 9
 **/
10 10

  
11 11
#ifndef __WORLD_H__
12 12
#define __WORLD_H__
13 13

  
14
#define ID_RECTANGLE 1
15
#define ID_CIRCLE 2
14
#define ID_RECTANGLE 0
15
#define ID_CIRCLE 1
16
#define NUM_SHAPES 2
16 17

  
17 18
typedef struct {
18 19
    double x;
......
25 26
} bbox_t;
26 27

  
27 28
typedef struct {
29
    point_t p; /* origin */
30
    double d; /* direction */
31
} ray_t;
32

  
33
typedef struct {
28 34
    int id;
29 35
    bbox_t *bbox;
30 36
    void *props; /* shape-specific properties */
......
33 39
typedef struct {
34 40
    int num_objs;
35 41
    object_t *objs;
36
    bbox world;
42
    bbox_t world;
37 43
} world_t;
38 44

  
45
/* 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

  
39 57
#endif
40 58

  

Also available in: Unified diff