Revision 1064
Cleaned up code, removed all compiler warnings.
world.c | ||
---|---|---|
16 | 16 |
|
17 | 17 |
world_t world; |
18 | 18 |
|
19 |
int destroy(object_t *obj); |
|
20 |
|
|
19 | 21 |
int init_world(int max_objs, bbox_t b) |
20 | 22 |
{ |
21 |
double pts[8] = {b.p1.x, b.p1.y, b.p1.x, b.p2.y, b.p2.x,b.p2.y,b.p2.x,b.p1.y}; |
|
22 | 23 |
world.max_objs = max_objs; |
23 | 24 |
world.cur_objs = 0; |
24 | 25 |
world.objs = calloc(max_objs, sizeof(object_t)); |
25 | 26 |
world.win = b; |
26 |
/* Add a polygon surrounding the world */ |
|
27 |
// this devours the world - brian |
|
28 |
//create(ID_POLY,4,POLY_CONNECTED,pts); |
|
27 |
|
|
28 |
return 0; |
|
29 | 29 |
} |
30 |
|
|
30 | 31 |
int destroy_world() |
31 | 32 |
{ |
32 | 33 |
int i; |
33 |
for (i = 0; i < world.cur_objs; i++) { |
|
34 |
destroy(&world.objs[i]); |
|
35 |
} |
|
34 |
for (i = 0; i < world.cur_objs; i++) |
|
35 |
destroy(&world.objs[i]); |
|
36 | 36 |
free(world.objs); |
37 |
|
|
38 |
return 0; |
|
37 | 39 |
} |
38 | 40 |
|
39 | 41 |
double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj) = |
... | ... | |
50 | 52 |
}; |
51 | 53 |
|
52 | 54 |
|
53 |
|
|
54 | 55 |
double collide_circle(ray_t *ray, object_t *obj) |
55 | 56 |
{ |
56 | 57 |
return -1; |
... | ... | |
147 | 148 |
int destroy(object_t *obj) |
148 | 149 |
{ |
149 | 150 |
if (obj->id == ID_NULL) |
150 |
return 0;
|
|
151 |
return 0;
|
|
151 | 152 |
destroy_func[obj->id+ID_OFFSET](obj); |
152 | 153 |
obj->id = ID_NULL; |
154 |
|
|
155 |
return 0; |
|
153 | 156 |
} |
154 | 157 |
|
155 | 158 |
/** |
... | ... | |
184 | 187 |
|
185 | 188 |
int create_rect(object_t *obj, va_list ap) |
186 | 189 |
{ |
187 |
int i; |
|
190 |
/*int i;
|
|
188 | 191 |
poly_t *p; |
189 |
int argc = va_arg(ap, int); |
|
192 |
int argc = va_arg(ap, int);*/ |
|
193 |
|
|
194 |
return 0; |
|
190 | 195 |
} |
191 | 196 |
|
192 | 197 |
int destroy_poly (object_t *obj) |
... | ... | |
228 | 233 |
} |
229 | 234 |
|
230 | 235 |
|
231 |
/* |
|
232 |
* XXX: This shouldn't be here. Where should it be? |
|
233 |
*/ |
|
234 |
/* These need to be measured... */ |
|
235 |
double rf_thetas[5] = {0.0, 2*M_PI/5, 4*M_PI/5, 6*M_PI/5, 8*M_PI/5}; |
|
236 |
//double rf_thetas[5] = {0.0, 0.0, M_PI/2, M_PI, 3*M_PI/2}; |
|
237 |
void update_rangefinders(Robot *bot) |
|
238 |
{ |
|
239 |
RangeFinder r = bot->shared->ranges; |
|
240 |
ray_t rf = {bot->pose.x, bot->pose.y, 0}; |
|
241 |
/* Motion code has +y going down, I don't. |
|
242 |
* So to compensate, just reflect theta up to first quadrant.*/ |
|
243 |
double theta = bot->pose.theta; |
|
244 |
int ir; |
|
245 |
double x; |
|
246 |
for (ir = 0; ir < 5; ir++) |
|
247 |
{ |
|
248 |
rf.d = theta + rf_thetas[ir]; |
|
249 |
x = collide_world(&rf); |
|
250 |
//printf("@(%g) - [%d] = %g --> %d\n",rf.d, ir, x, (short)x); |
|
251 |
bot->shared->ranges.d[ir] = x; |
|
252 |
} |
|
253 |
} |
|
254 |
|
|
255 | 236 |
int load_object (const char* line) { |
256 | 237 |
char buf[BUF_SIZE]; |
257 | 238 |
int i = 0; |
... | ... | |
317 | 298 |
int load_world (const char* filename,int max_objs) { |
318 | 299 |
FILE* fin; |
319 | 300 |
char buf[BUF_SIZE]; |
320 |
bbox_t bbox = {0,0,0,0};
|
|
301 |
bbox_t bbox; |
|
321 | 302 |
if ((fin = fopen(filename,"r"))==NULL){ |
322 | 303 |
// open file failed |
323 | 304 |
perror("Fail to open file"); |
Also available in: Unified diff