Revision 1020
Now runs at a reasonable speed.
gtk_environment_view.c | ||
---|---|---|
39 | 39 |
|
40 | 40 |
|
41 | 41 |
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, |
42 |
int x, int y, int angle);
|
|
42 |
float x, float y, float angle);
|
|
43 | 43 |
|
44 | 44 |
GtkType gtk_environment_view_get_type(void) |
45 | 45 |
{ |
... | ... | |
195 | 195 |
robot_iterator_reset(); |
196 | 196 |
Robot* r; |
197 | 197 |
while ((r = robot_iterator_next()) != NULL) { |
198 |
printf("x: %d, y:%d, Theta: %f\n",
|
|
198 |
printf("x: %f, y:%f, Theta: %f\n",
|
|
199 | 199 |
r->pose.x, r->pose.y, r->pose.theta); |
200 | 200 |
draw_robot(widget->window, |
201 | 201 |
widget->style->fg_gc[GTK_WIDGET_STATE(widget)], |
... | ... | |
353 | 353 |
} |
354 | 354 |
|
355 | 355 |
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, |
356 |
int x, int y, int angle)
|
|
356 |
float x, float y, float angle)
|
|
357 | 357 |
{ |
358 | 358 |
if (!drawable || !gc) |
359 | 359 |
return; |
360 |
double ang_rad = angle * ENVIRONMENT_PI / 180; |
|
361 |
int x_c = x - ENVIRONMENT_ROBOT_DIAMETER / 2; |
|
362 |
int y_c = y - ENVIRONMENT_ROBOT_DIAMETER / 2; |
|
360 |
int x_c = (int)x - ENVIRONMENT_ROBOT_DIAMETER / 2; |
|
361 |
int y_c = (int)y - ENVIRONMENT_ROBOT_DIAMETER / 2; |
|
363 | 362 |
|
364 | 363 |
gdk_draw_arc(drawable, gc, FALSE, x_c, y_c, |
365 | 364 |
ENVIRONMENT_ROBOT_DIAMETER, ENVIRONMENT_ROBOT_DIAMETER, |
366 | 365 |
0, 360*64); |
367 | 366 |
|
368 | 367 |
gdk_draw_line(drawable, gc, x, y, |
369 |
x + (ENVIRONMENT_ROBOT_DIAMETER - 10) * cos(ang_rad),
|
|
370 |
y - (ENVIRONMENT_ROBOT_DIAMETER - 10) * sin(ang_rad));
|
|
368 |
x + (ENVIRONMENT_ROBOT_DIAMETER - 10) * cos(-angle),
|
|
369 |
y - (ENVIRONMENT_ROBOT_DIAMETER - 10) * sin(-angle));
|
|
371 | 370 |
} |
372 | 371 |
|
Also available in: Unified diff