Revision 1047
Draws polygons in the environment.
gtk_environment_view.c | ||
---|---|---|
10 | 10 |
#include "gtk_environment_view.h" |
11 | 11 |
|
12 | 12 |
#include "robot.h" |
13 |
#include "world.h" |
|
13 | 14 |
|
14 | 15 |
#define ENVIRONMENT_VIEW_MIN_WIDTH 100 |
15 | 16 |
#define ENVIRONMENT_VIEW_MIN_HEIGHT 50 |
... | ... | |
38 | 39 |
GdkEventMotion* event); |
39 | 40 |
|
40 | 41 |
|
42 |
static void draw_world(GdkDrawable* drawable, GdkGC* gc, world_t* world); |
|
41 | 43 |
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, |
42 | 44 |
float x, float y, float angle); |
43 | 45 |
|
... | ... | |
191 | 193 |
return FALSE; |
192 | 194 |
|
193 | 195 |
view = GTK_ENVIRONMENT_VIEW(widget); |
196 |
|
|
197 |
draw_world(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], &world); |
|
194 | 198 |
|
195 | 199 |
robot_iterator_reset(); |
196 | 200 |
Robot* r; |
197 | 201 |
while ((r = robot_iterator_next()) != NULL) { |
198 |
printf("x: %f, y:%f, Theta: %f\n", |
|
199 |
r->pose.x, r->pose.y, r->pose.theta); |
|
200 | 202 |
draw_robot(widget->window, |
201 | 203 |
widget->style->fg_gc[GTK_WIDGET_STATE(widget)], |
202 | 204 |
r->pose.x, r->pose.y, r->pose.theta); |
... | ... | |
352 | 354 |
gdk_threads_leave(); |
353 | 355 |
} |
354 | 356 |
|
357 |
static void draw_world(GdkDrawable* drawable, GdkGC* gc, world_t* world) |
|
358 |
{ |
|
359 |
int i, j; |
|
360 |
GdkPoint* points; |
|
361 |
poly_t* p; |
|
362 |
|
|
363 |
if (!drawable || !gc || !world) |
|
364 |
return; |
|
365 |
|
|
366 |
double leftx = world->win.p1.x; |
|
367 |
double upy = world->win.p1.x; |
|
368 |
double xwidth = world->win.p2.x - leftx; |
|
369 |
double yheight = world->win.p2.y - upy; |
|
370 |
|
|
371 |
|
|
372 |
int width, height; |
|
373 |
gdk_drawable_get_size(drawable, &width, &height); |
|
374 |
|
|
375 |
if (xwidth / width < yheight / height) |
|
376 |
width = (int)(height / yheight * xwidth); |
|
377 |
else |
|
378 |
height = (int)(width / xwidth * yheight); |
|
379 |
|
|
380 |
for (i = 0 ; i < world->max_objs; i++) |
|
381 |
{ |
|
382 |
object_t* o = &(world->objs[i]); |
|
383 |
switch (o->id) |
|
384 |
{ |
|
385 |
case ID_POLY: |
|
386 |
p = (poly_t*)o->props; |
|
387 |
points = (GdkPoint*)malloc(sizeof(GdkPoint) * p->num_pts); |
|
388 |
for (j = 0; j < p->num_pts; j++) |
|
389 |
{ |
|
390 |
points[j].x = (int)((p->pts[j].x - leftx) / xwidth * width); |
|
391 |
points[j].y = (int)((p->pts[j].y - upy) / yheight * height); |
|
392 |
} |
|
393 |
switch(p->type) |
|
394 |
{ |
|
395 |
case POLY_CONNECTED: |
|
396 |
gdk_draw_polygon(drawable, gc, 1, points, p->num_pts); |
|
397 |
break; |
|
398 |
default: |
|
399 |
fprintf(stderr, "Detected unexpected type of polygon.\n"); |
|
400 |
break; |
|
401 |
} |
|
402 |
free(points); |
|
403 |
break; |
|
404 |
// no object |
|
405 |
case ID_NULL: |
|
406 |
break; |
|
407 |
default: |
|
408 |
fprintf(stderr, "Unexpected object type %d in world.\n", o->id); |
|
409 |
break; |
|
410 |
} |
|
411 |
} |
|
412 |
} |
|
413 |
|
|
355 | 414 |
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, |
356 | 415 |
float x, float y, float angle) |
357 | 416 |
{ |
Also available in: Unified diff