Project

General

Profile

Revision 1184

Added by Rich Hong about 15 years ago

Able to read and draw circles in the environment

View differences:

world.c
40 40

  
41 41
double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj) =
42 42
    {
43
    collide_poly
43
    collide_poly, collide_circle
44 44
    };
45 45
int (*create_func[NUM_SHAPES])(object_t *obj, va_list ap) =
46 46
{
47
    create_poly
47
    create_poly, create_circle
48 48
};
49 49
int (*destroy_func[NUM_SHAPES])(object_t *obj) = 
50 50
    {
51
    destroy_poly
51
    destroy_poly, destroy_circle
52 52
    };
53 53

  
54 54

  
......
205 205
    return 1;
206 206
}
207 207

  
208
/* ap = x, y, radius */
209
int create_circle(object_t *obj, va_list ap)
210
{
211
	circle_t *c;
212

  
213
	c = malloc(sizeof(circle_t));
214
	
215
	c->center.x = va_arg(ap, double);
216
	c->center.y = va_arg(ap, double);
217
	c->radius = va_arg(ap, double);
218

  
219
	obj->id = ID_CIRCLE;
220
	obj->bbox = NULL;
221
	obj->props = c;
222
	return 0;	
223
}
224

  
208 225
int create_rect(object_t *obj, va_list ap)
209 226
{
210 227
    /*int i;
......
223 240
    return 1;
224 241
}
225 242

  
243
int destroy_circle (object_t *obj)
244
{
245
	free(obj->props);
246
	free(obj);
247
	return 0;
248
}
249

  
226 250
void print_world(void)
227 251
{
228 252
    int i;
......
301 325
  }else if (strstr(line,"CIRCLE") == line){
302 326
		id = ID_CIRCLE;
303 327
		i = strlen("CIRCLE") + 1;
304
		//TODO
328
		double x,y,r;
329
		sscanf(line + i, "%lf %lf %lf", &x, &y, &r);
330
		create(id,x,y,r);
305 331
	}else if (strstr(line,"RECTANGLE") == line){
306 332
		id = ID_RECTANGLE;
307 333
		i = strlen("RECTANGLE") + 1;

Also available in: Unified diff