Project

General

Profile

Revision 1184

Added by Rich Hong about 15 years ago

Able to read and draw circles in the environment

View differences:

branches/simulator/projects/simulator/simulator/gui/gtk_environment_view.c
476 476
	int i, j;
477 477
	GdkPoint* points;
478 478
	poly_t* p;
479
	circle_t* c;
480
	int x, y, r;
479 481

  
480 482
	if (!drawable || !gc || !world)
481 483
		return;
......
501 503
				}
502 504
				free(points);
503 505
				break;
506
			case ID_CIRCLE:
507
				c = (circle_t*)o->props;
508
				to_window_scale(view, c->radius, &r);
509
				to_window_coordinates(view, c->center.x, c->center.y, &x, &y);
510
				gdk_draw_arc(drawable, gc, 1, 
511
							(int)(x - (float)r / 2),
512
							(int)(y - (float)r / 2), 
513
							r, r, 0, 360*64);
514
				break;
504 515
			// no object
505 516
			case ID_NULL:
506 517
				break;
branches/simulator/projects/simulator/simulator/core/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;
branches/simulator/projects/simulator/simulator/core/world.h
90 90
int init_world(int num_objs, bbox_t b);
91 91
int destroy_world(void);
92 92
int create_poly(object_t *obj, va_list ap);
93
int create_circle(object_t *obj, va_list ap);
93 94
int destroy_poly(object_t *obj);
95
int destroy_circle(object_t *obj);
94 96
object_t *create(int id, ...);
95 97

  
96 98
void print_world(void);
branches/simulator/projects/simulator/test/world.txt
6 6

  
7 7
#POLYGON 4 CONNECTED -20 -20 -20 20 20 20 20 -20
8 8
POLYGON 4 CONNECTED -100 -500 -100 500 -80 500 -80 -500
9
#CIRCLE 300 300 100
9 10

  

Also available in: Unified diff