1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2008 Navit Team
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
#include <math.h>
|
21 |
#include <stdio.h>
|
22 |
#include <glib.h>
|
23 |
#include <time.h>
|
24 |
#include <stdlib.h>
|
25 |
#include <string.h>
|
26 |
#include <fcntl.h>
|
27 |
#include <unistd.h>
|
28 |
#include <termios.h>
|
29 |
#include <errno.h>
|
30 |
#include <sys/ioctl.h>
|
31 |
#include "config.h"
|
32 |
#include <navit/item.h>
|
33 |
#include <navit/main.h>
|
34 |
#include <navit/debug.h>
|
35 |
#include <navit/point.h>
|
36 |
#include <navit/graphics.h>
|
37 |
#include <navit/transform.h>
|
38 |
#include <navit/map.h>
|
39 |
#include <navit/navit.h>
|
40 |
#include <navit/callback.h>
|
41 |
#include <navit/file.h>
|
42 |
#include <navit/color.h>
|
43 |
#include <navit/route.h>
|
44 |
#include <navit/plugin.h>
|
45 |
#include <navit/layout.h>
|
46 |
#include <navit/mapset.h>
|
47 |
#include <navit/osd.h>
|
48 |
#include <navit/event.h>
|
49 |
#include <navit/command.h>
|
50 |
#include <navit/config_.h>
|
51 |
#include <navit/vehicle.h>
|
52 |
|
53 |
/* #define DEMO 1 */
|
54 |
|
55 |
#ifdef HAVE_API_ANDROID
|
56 |
#include <navit/android.h>
|
57 |
#endif
|
58 |
static struct map *global_map;
|
59 |
|
60 |
int orientation,orientation_old;
|
61 |
|
62 |
struct pedestrian {
|
63 |
struct navit *nav;
|
64 |
int w,h;
|
65 |
int yaw;
|
66 |
} pedestrian_data;
|
67 |
|
68 |
int sensors_locked;
|
69 |
|
70 |
struct attr initial_layout, main_layout;
|
71 |
|
72 |
|
73 |
struct rocket {
|
74 |
struct navit *navit;
|
75 |
struct layout *layout;
|
76 |
struct graphics *gra;
|
77 |
struct transformation *trans;
|
78 |
struct displaylist *dl;
|
79 |
struct mapset *ms;
|
80 |
int a,g,t,hog,v,vscale;
|
81 |
struct callback *callback;
|
82 |
struct event_idle *idle;
|
83 |
};
|
84 |
|
85 |
static void
|
86 |
pedestrian_rocket_idle(struct rocket *rocket)
|
87 |
{
|
88 |
struct attr follow;
|
89 |
follow.type=attr_follow;
|
90 |
follow.u.num=100;
|
91 |
transform_set_hog(rocket->trans, rocket->hog);
|
92 |
graphics_displaylist_draw(rocket->gra, rocket->dl, rocket->trans, rocket->layout, 0);
|
93 |
rocket->v+=rocket->a-rocket->g;
|
94 |
dbg(0,"enter v=%d\n",rocket->v);
|
95 |
if (rocket->t > 0)
|
96 |
rocket->t--;
|
97 |
else
|
98 |
rocket->a=0;
|
99 |
rocket->hog+=rocket->v/rocket->vscale;
|
100 |
dbg(0,"hog=%d\n",rocket->hog);
|
101 |
if (rocket->hog < 0) {
|
102 |
transform_set_hog(rocket->trans, 0);
|
103 |
transform_set_order_base(rocket->trans, 14);
|
104 |
transform_set_scale(rocket->trans, transform_get_scale(rocket->trans));
|
105 |
graphics_overlay_disable(rocket->gra, 0);
|
106 |
navit_draw(rocket->navit);
|
107 |
follow.u.num=1;
|
108 |
event_remove_idle(rocket->idle);
|
109 |
rocket->idle=NULL;
|
110 |
sensors_locked=0;
|
111 |
}
|
112 |
navit_set_attr(rocket->navit, &follow);
|
113 |
}
|
114 |
|
115 |
static void
|
116 |
pedestrian_cmd_pedestrian_rocket(struct rocket *rocket)
|
117 |
{
|
118 |
struct attr attr;
|
119 |
int max=0;
|
120 |
#if 0
|
121 |
int i,step=10;
|
122 |
#endif
|
123 |
rocket->a=2;
|
124 |
rocket->g=1;
|
125 |
rocket->t=100;
|
126 |
rocket->hog=0;
|
127 |
rocket->v=0;
|
128 |
rocket->vscale=10;
|
129 |
if (! navit_get_attr(rocket->navit, attr_graphics, &attr, NULL))
|
130 |
return;
|
131 |
rocket->gra=attr.u.graphics;
|
132 |
if (! navit_get_attr(rocket->navit, attr_transformation, &attr, NULL))
|
133 |
return;
|
134 |
rocket->trans=attr.u.transformation;
|
135 |
if (! navit_get_attr(rocket->navit, attr_displaylist, &attr, NULL))
|
136 |
return;
|
137 |
rocket->dl=attr.u.displaylist;
|
138 |
if (! navit_get_attr(rocket->navit, attr_mapset, &attr, NULL))
|
139 |
return;
|
140 |
rocket->ms=attr.u.mapset;
|
141 |
transform_set_hog(rocket->trans, max);
|
142 |
transform_set_order_base(rocket->trans, 14);
|
143 |
transform_set_scale(rocket->trans, transform_get_scale(rocket->trans));
|
144 |
transform_setup_source_rect(rocket->trans);
|
145 |
graphics_overlay_disable(rocket->gra, 1);
|
146 |
graphics_draw(rocket->gra, rocket->dl, rocket->ms, rocket->trans, rocket->layout, 0, NULL, 0);
|
147 |
sensors_locked=1;
|
148 |
if (!rocket->idle)
|
149 |
rocket->idle=event_add_idle(50, rocket->callback);
|
150 |
#if 0
|
151 |
while (hog >= 0) {
|
152 |
transform_set_hog(trans, hog);
|
153 |
#if 0
|
154 |
graphics_draw(gra, dl, ms, trans, layout, 0, NULL);
|
155 |
#else
|
156 |
graphics_displaylist_draw(gra, dl, trans, layout, 0);
|
157 |
#endif
|
158 |
v=v+a-g;
|
159 |
if (t > 0)
|
160 |
t--;
|
161 |
else
|
162 |
a=0;
|
163 |
hog=hog+v/vscale;
|
164 |
}
|
165 |
#if 0
|
166 |
for (i = 0 ; i < max ; i+=step) {
|
167 |
transform_set_hog(trans, i);
|
168 |
graphics_displaylist_draw(gra, dl, trans, layout, 0);
|
169 |
}
|
170 |
for (i = max ; i >= 0 ; i-=step) {
|
171 |
transform_set_hog(trans, i);
|
172 |
graphics_displaylist_draw(gra, dl, trans, layout, 0);
|
173 |
}
|
174 |
#endif
|
175 |
#endif
|
176 |
}
|
177 |
|
178 |
static struct command_table commands[] = {
|
179 |
{"pedestrian_rocket",command_cast(pedestrian_cmd_pedestrian_rocket)},
|
180 |
};
|
181 |
|
182 |
|
183 |
|
184 |
static void
|
185 |
osd_rocket_init(struct navit *nav)
|
186 |
{
|
187 |
struct rocket *rocket=g_new0(struct rocket, 1);
|
188 |
struct attr attr;
|
189 |
rocket->navit=nav;
|
190 |
rocket->callback=callback_new_1(callback_cast(pedestrian_rocket_idle), rocket);
|
191 |
if (navit_get_attr(nav, attr_layout, &attr, NULL))
|
192 |
rocket->layout=attr.u.layout;
|
193 |
if (navit_get_attr(nav, attr_callback_list, &attr, NULL)) {
|
194 |
dbg(0,"ok\n");
|
195 |
command_add_table(attr.u.callback_list, commands, sizeof(commands)/sizeof(struct command_table), rocket);
|
196 |
}
|
197 |
}
|
198 |
|
199 |
struct marker {
|
200 |
struct cursor *cursor;
|
201 |
};
|
202 |
|
203 |
static void
|
204 |
osd_marker_draw(struct marker *this, struct navit *nav)
|
205 |
{
|
206 |
#if 0
|
207 |
struct attr graphics;
|
208 |
struct point p;
|
209 |
dbg(0,"enter\n");
|
210 |
if (!navit_get_attr(nav, attr_graphics, &graphics, NULL))
|
211 |
return;
|
212 |
p.x=40;
|
213 |
p.y=50;
|
214 |
cursor_draw(this->cursor, graphics.u.graphics, &p, 0, 45, 0);
|
215 |
#endif
|
216 |
|
217 |
}
|
218 |
|
219 |
static void
|
220 |
osd_marker_init(struct marker *this, struct navit *nav)
|
221 |
{
|
222 |
struct attr cursor;
|
223 |
struct attr itemgra,polygon,polygoncoord1,polygoncoord2,polygoncoord3;
|
224 |
struct attr *color=attr_new_from_text("color","#ff0000");
|
225 |
|
226 |
cursor=(struct attr){attr_cursor, {(void *)cursor_new(NULL, (struct attr *[]){
|
227 |
&(struct attr){attr_w,{(void *)26}},
|
228 |
&(struct attr){attr_h,{(void *)26}},
|
229 |
NULL})}};
|
230 |
itemgra=(struct attr){attr_itemgra, {(void *)itemgra_new(&cursor, (struct attr *[]){
|
231 |
NULL})}};
|
232 |
cursor_add_attr(cursor.u.cursor, &itemgra);
|
233 |
polygon=(struct attr){attr_polygon, {(void *)polygon_new(&itemgra, (struct attr *[]){
|
234 |
color,
|
235 |
&(struct attr){attr_width,{(void *)2}},
|
236 |
NULL})}};
|
237 |
itemgra_add_attr(itemgra.u.itemgra, &polygon);
|
238 |
polygoncoord1=(struct attr){attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]){
|
239 |
&(struct attr){attr_x,{(void *)-7}},
|
240 |
&(struct attr){attr_y,{(void *)-10}},
|
241 |
NULL})}};
|
242 |
element_add_attr(polygon.u.element, &polygoncoord1);
|
243 |
polygoncoord2=(struct attr){attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]){
|
244 |
&(struct attr){attr_x,{(void *)0}},
|
245 |
&(struct attr){attr_y,{(void *)12}},
|
246 |
NULL})}};
|
247 |
element_add_attr(polygon.u.element, &polygoncoord2);
|
248 |
polygoncoord3=(struct attr){attr_coord, {(void *)coord_new_from_attrs(&polygon, (struct attr *[]){
|
249 |
&(struct attr){attr_x,{(void *)7}},
|
250 |
&(struct attr){attr_y,{(void *)-10}},
|
251 |
NULL})}};
|
252 |
element_add_attr(polygon.u.element, &polygoncoord3);
|
253 |
attr_free(color);
|
254 |
this->cursor=cursor.u.cursor;
|
255 |
osd_marker_draw(this, nav);
|
256 |
}
|
257 |
|
258 |
static struct osd_priv *
|
259 |
osd_marker_new(struct navit *nav, struct osd_methods *meth,
|
260 |
struct attr **attrs)
|
261 |
{
|
262 |
struct marker *this = g_new0(struct marker, 1);
|
263 |
navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_marker_init), attr_navit, this));
|
264 |
return (struct osd_priv *) this;
|
265 |
}
|
266 |
|
267 |
|
268 |
|
269 |
struct map_priv {
|
270 |
struct navit *navit;
|
271 |
};
|
272 |
|
273 |
struct map_rect_priv {
|
274 |
struct map_priv *mpriv;
|
275 |
struct item item;
|
276 |
struct map_rect *route_map_rect;
|
277 |
struct item *route_item;
|
278 |
struct street_data *sd;
|
279 |
struct coord c0;
|
280 |
struct coord c_base;
|
281 |
int checked;
|
282 |
int idx_base;
|
283 |
int idx_next;
|
284 |
int idx;
|
285 |
int first,last;
|
286 |
int route_item_done;
|
287 |
struct coord c_out;
|
288 |
struct coord c_next;
|
289 |
struct coord c_next_base;
|
290 |
struct coord lseg[2];
|
291 |
struct coord lseg_base[2];
|
292 |
int lseg_done;
|
293 |
int lseg_done_base;
|
294 |
};
|
295 |
|
296 |
static int
|
297 |
map_route_occluded_bbox(struct map *map, struct coord_rect *bbox)
|
298 |
{
|
299 |
struct coord c[128];
|
300 |
struct coord_rect r;
|
301 |
int i,first=1,ccount;
|
302 |
struct map_rect *map_rect=map_rect_new(map, NULL);
|
303 |
struct item *item;
|
304 |
while ((item=map_rect_get_item(map_rect))) {
|
305 |
ccount=item_coord_get(item, c, 128);
|
306 |
if (ccount && first) {
|
307 |
r.lu=c[0];
|
308 |
r.rl=c[0];
|
309 |
first=0;
|
310 |
}
|
311 |
for (i = 0 ; i < ccount ; i++)
|
312 |
coord_rect_extend(&r, &c[i]);
|
313 |
}
|
314 |
map_rect_destroy(map_rect);
|
315 |
if (first)
|
316 |
return 0;
|
317 |
*bbox=r;
|
318 |
return 1;
|
319 |
}
|
320 |
|
321 |
static struct building {
|
322 |
struct street_data *sd;
|
323 |
struct coord left,right;
|
324 |
struct building *next;
|
325 |
} *buildings;
|
326 |
|
327 |
static void
|
328 |
map_route_occluded_buildings_free(void)
|
329 |
{
|
330 |
struct building *next,*b=buildings;
|
331 |
while (b) {
|
332 |
street_data_free(b->sd);
|
333 |
next=b->next;
|
334 |
g_free(b);
|
335 |
b=next;
|
336 |
}
|
337 |
buildings=NULL;
|
338 |
}
|
339 |
|
340 |
static void
|
341 |
map_route_occluded_get_buildings(struct mapset *mapset, struct coord_rect *r)
|
342 |
{
|
343 |
struct mapset_handle *msh=mapset_open(mapset);
|
344 |
struct map *map;
|
345 |
struct map_selection sel;
|
346 |
struct map_rect *mr;
|
347 |
struct item *item;
|
348 |
struct building *b;
|
349 |
sel.next=NULL;
|
350 |
sel.u.c_rect=*r;
|
351 |
sel.order=18;
|
352 |
sel.range.min=type_poly_building;
|
353 |
sel.range.max=type_poly_building;
|
354 |
|
355 |
map_route_occluded_buildings_free();
|
356 |
while ((map = mapset_next(msh, 1))) {
|
357 |
mr=map_rect_new(map, &sel);
|
358 |
while ((item = map_rect_get_item(mr))) {
|
359 |
if (item->type == type_poly_building) {
|
360 |
#if 0
|
361 |
if (item->id_hi != 0x1 || item->id_lo != 0x1f69)
|
362 |
continue;
|
363 |
#endif
|
364 |
#if 0
|
365 |
if (item->id_hi != 0x8)
|
366 |
continue;
|
367 |
#if 1
|
368 |
if (item->id_lo != 0x2b3e0 && item->id_lo != 0x2ae7a && item->id_lo != 0x2af1a && item->id_lo != 0x2b348 && item->id_lo != 0x18bb5 && item->id_lo != 0x18ce5 && item->id_lo != 0x18a85)
|
369 |
#else
|
370 |
if (item->id_lo != 0x18bb5 && item->id_lo != 0x18ce5 && item->id_lo != 0x18a85)
|
371 |
#endif
|
372 |
continue;
|
373 |
#endif
|
374 |
b=g_new(struct building, 1);
|
375 |
b->sd=street_get_data(item);
|
376 |
b->next=buildings;
|
377 |
buildings=b;
|
378 |
}
|
379 |
}
|
380 |
map_rect_destroy(mr);
|
381 |
}
|
382 |
}
|
383 |
|
384 |
FILE *debug,*debug2;
|
385 |
|
386 |
/* < 0 left, > 0 right */
|
387 |
|
388 |
static int
|
389 |
side(struct coord *l0, struct coord *l1, struct coord *p)
|
390 |
{
|
391 |
int dxl=l1->x-l0->x;
|
392 |
int dyl=l1->y-l0->y;
|
393 |
int dxp=p->x-l0->x;
|
394 |
int dyp=p->y-l0->y;
|
395 |
|
396 |
return dxp*dyl-dyp*dxl;
|
397 |
}
|
398 |
|
399 |
static void
|
400 |
map_route_occluded_check_buildings(struct coord *c0)
|
401 |
{
|
402 |
struct building *b=buildings;
|
403 |
dbg(0,"enter\n");
|
404 |
int i,count;
|
405 |
struct coord *c;
|
406 |
#if 1
|
407 |
FILE *bdebug,*bldebug;
|
408 |
bdebug=fopen("tstb.txt","w");
|
409 |
bldebug=fopen("tstbl.txt","w");
|
410 |
#endif
|
411 |
while (b) {
|
412 |
c=b->sd->c;
|
413 |
count=b->sd->count;
|
414 |
if (c[count-1].x == c[0].x && c[count-1].y == c[0].y) {
|
415 |
#if 0
|
416 |
dbg(0,"closed\n");
|
417 |
#endif
|
418 |
count--;
|
419 |
}
|
420 |
for (i = 0 ; i < count ; i++) {
|
421 |
if (!i || side(c0, &b->left, &c[i]) < 0)
|
422 |
b->left=c[i];
|
423 |
if (!i || side(c0, &b->right, &c[i]) > 0)
|
424 |
b->right=c[i];
|
425 |
}
|
426 |
#if 1
|
427 |
if (bdebug) {
|
428 |
fprintf(bdebug,"0x%x 0x%x type=poi_hospital\n", b->left.x, b->left.y);
|
429 |
fprintf(bdebug,"0x%x 0x%x type=poi_hospital\n", b->right.x, b->right.y);
|
430 |
}
|
431 |
if (bldebug) {
|
432 |
fprintf(bldebug,"type=street_nopass\n");
|
433 |
fprintf(bldebug,"0x%x 0x%x\n", c0->x, c0->y);
|
434 |
fprintf(bldebug,"0x%x 0x%x\n", c0->x+(b->left.x-c0->x)*10, c0->y+(b->left.y-c0->y)*10);
|
435 |
fprintf(bldebug,"type=street_nopass\n");
|
436 |
fprintf(bldebug,"0x%x 0x%x\n", c0->x, c0->y);
|
437 |
fprintf(bldebug,"0x%x 0x%x\n", c0->x+(b->right.x-c0->x)*10, c0->y+(b->right.y-c0->y)*10);
|
438 |
}
|
439 |
#endif
|
440 |
b=b->next;
|
441 |
}
|
442 |
#if 1
|
443 |
if (bdebug)
|
444 |
fclose(bdebug);
|
445 |
if (bldebug)
|
446 |
fclose(bldebug);
|
447 |
#endif
|
448 |
}
|
449 |
|
450 |
static int
|
451 |
intersect(struct coord *p1, struct coord *p2, struct coord *p3, struct coord *p4, struct coord *i)
|
452 |
{
|
453 |
double num=(p4->x-p3->x)*(p1->y-p3->y)-(p4->y-p3->y)*(p1->x-p3->x);
|
454 |
double den=(p4->y-p3->y)*(p2->x-p1->x)-(p4->x-p3->x)*(p2->y-p1->y);
|
455 |
if (num < 0 && den < 0) {
|
456 |
num=-num;
|
457 |
den=-den;
|
458 |
}
|
459 |
dbg(1,"num=%f den=%f\n", num, den);
|
460 |
if (i) {
|
461 |
i->x=p1->x+(num/den)*(p2->x-p1->x)+0.5;
|
462 |
i->y=p1->y+(num/den)*(p2->y-p1->y)+0.5;
|
463 |
dbg(1,"i=0x%x,0x%x\n", i->x, i->y);
|
464 |
if (debug2)
|
465 |
fprintf(debug2, "0x%x 0x%x type=town_label_5e3\n", i->x, i->y);
|
466 |
}
|
467 |
if (num < 0 || den < 0)
|
468 |
return -1;
|
469 |
if (num > den)
|
470 |
return 257;
|
471 |
return 256*num/den;
|
472 |
}
|
473 |
|
474 |
/* return
|
475 |
0=Not clipped
|
476 |
1=Start clipped
|
477 |
2=End clipped
|
478 |
3=Both clipped
|
479 |
4=Invisible
|
480 |
*/
|
481 |
|
482 |
/* #define DEBUG_VISIBLE */
|
483 |
|
484 |
static int
|
485 |
is_visible_line(struct coord *c0, struct coord *c1, struct coord *c2)
|
486 |
{
|
487 |
int res,ret=0;
|
488 |
struct building *b=buildings;
|
489 |
struct coord cn;
|
490 |
#ifdef DEBUG_VISIBLE
|
491 |
dbg(0,"enter\n");
|
492 |
#endif
|
493 |
while (b) {
|
494 |
if (side(&b->left, &b->right, c1) < 0 || side(&b->left, &b->right, c2) < 0) {
|
495 |
#ifdef DEBUG_VISIBLE
|
496 |
dbg(0,"sides left: start %d end %d right: start %d end %d\n", side(c0, &b->left, c1), side(c0, &b->left, c2), side(c0, &b->right, c1), side(c0, &b->right, c2));
|
497 |
#endif
|
498 |
for (;;) {
|
499 |
if (side(c0, &b->left, c1) <= 0) {
|
500 |
if (side(c0, &b->left, c2) > 0) {
|
501 |
#ifdef DEBUG_VISIBLE
|
502 |
dbg(0,"visible: start is left of left corner and end is right of left corner, clipping end\n");
|
503 |
#endif
|
504 |
res=intersect(c0, &b->left, c1, c2, &cn);
|
505 |
if (res < 256)
|
506 |
break;
|
507 |
if (c1->x != cn.x || c1->y != cn.y) {
|
508 |
*c2=cn;
|
509 |
ret|=2;
|
510 |
break;
|
511 |
}
|
512 |
} else
|
513 |
break;
|
514 |
}
|
515 |
if (side(c0, &b->right, c1) >= 0) {
|
516 |
if (side(c0, &b->right, c2) < 0) {
|
517 |
#ifdef DEBUG_VISIBLE
|
518 |
dbg(0,"visible: start is right of right corner and end is left of right corner, clipping end\n");
|
519 |
#endif
|
520 |
res=intersect(c0, &b->right, c1, c2, &cn);
|
521 |
if (res < 256)
|
522 |
break;
|
523 |
if (c1->x != cn.x || c1->y != cn.y) {
|
524 |
*c2=cn;
|
525 |
ret|=2;
|
526 |
break;
|
527 |
}
|
528 |
} else
|
529 |
break;
|
530 |
}
|
531 |
if (side(c0, &b->left, c2) <= 0) {
|
532 |
if (side(c0, &b->left, c1) > 0) {
|
533 |
#ifdef DEBUG_VISIBLE
|
534 |
dbg(0,"visible: end is left of left corner and start is right of left corner, clipping start\n");
|
535 |
#endif
|
536 |
res=intersect(c0, &b->left, c1, c2, &cn);
|
537 |
if (res < 256)
|
538 |
break;
|
539 |
if (c2->x != cn.x || c2->y != cn.y) {
|
540 |
*c1=cn;
|
541 |
ret|=1;
|
542 |
break;
|
543 |
}
|
544 |
} else
|
545 |
break;
|
546 |
}
|
547 |
if (side(c0, &b->right, c2) >= 0) {
|
548 |
if (side(c0, &b->right, c1) < 0) {
|
549 |
#ifdef DEBUG_VISIBLE
|
550 |
dbg(0,"visible: end is right of right corner and start is left of right corner, clipping start\n");
|
551 |
#endif
|
552 |
res=intersect(c0, &b->right, c1, c2, &cn);
|
553 |
if (res < 256)
|
554 |
break;
|
555 |
if (c2->x != cn.x || c2->y != cn.y) {
|
556 |
*c1=cn;
|
557 |
ret|=1;
|
558 |
break;
|
559 |
}
|
560 |
} else
|
561 |
break;
|
562 |
}
|
563 |
#ifdef DEBUG_VISIBLE
|
564 |
dbg(0,"visible: not visible\n");
|
565 |
#endif
|
566 |
return 4;
|
567 |
}
|
568 |
}
|
569 |
b=b->next;
|
570 |
}
|
571 |
#ifdef DEBUG_VISIBLE
|
572 |
dbg(0,"return %d\n",ret);
|
573 |
#endif
|
574 |
return ret;
|
575 |
}
|
576 |
|
577 |
static void
|
578 |
map_route_occluded_coord_rewind(void *priv_data)
|
579 |
{
|
580 |
struct map_rect_priv *mr = priv_data;
|
581 |
dbg(1,"enter\n");
|
582 |
mr->idx=mr->idx_base;
|
583 |
mr->first=1;
|
584 |
mr->lseg_done=mr->lseg_done_base;
|
585 |
mr->c_next=mr->c_next_base;
|
586 |
mr->lseg[0]=mr->lseg_base[0];
|
587 |
mr->lseg[1]=mr->lseg_base[1];
|
588 |
mr->last=0;
|
589 |
item_coord_rewind(mr->route_item);
|
590 |
}
|
591 |
|
592 |
static void
|
593 |
map_route_occluded_attr_rewind(void *priv_data)
|
594 |
{
|
595 |
struct map_rect_priv *mr=priv_data;
|
596 |
dbg(1,"enter\n");
|
597 |
item_attr_rewind(mr->route_item);
|
598 |
}
|
599 |
|
600 |
static int
|
601 |
map_route_occluded_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
|
602 |
{
|
603 |
struct map_rect_priv *mr=priv_data;
|
604 |
dbg(1,"enter\n");
|
605 |
return item_attr_get(mr->route_item, attr_type, attr);
|
606 |
}
|
607 |
|
608 |
static int
|
609 |
coord_next(struct map_rect_priv *mr, struct coord *c)
|
610 |
{
|
611 |
if (mr->idx >= mr->sd->count)
|
612 |
return 1;
|
613 |
*c=mr->sd->c[mr->idx++];
|
614 |
return 0;
|
615 |
}
|
616 |
|
617 |
#define DEBUG_COORD_GET
|
618 |
static int
|
619 |
map_route_occluded_coord_get(void *priv_data, struct coord *c, int count)
|
620 |
{
|
621 |
struct map_rect_priv *mr=priv_data;
|
622 |
struct coord l0,l1;
|
623 |
int vis,ret=0;
|
624 |
char buffer[4096];
|
625 |
|
626 |
#ifdef DEBUG_COORD_GET
|
627 |
dbg(1,"enter\n");
|
628 |
#endif
|
629 |
dbg_assert(count >= 2);
|
630 |
if (! mr->checked) {
|
631 |
mr->c0=mr->sd->c[0];
|
632 |
map_route_occluded_check_buildings(&mr->c0);
|
633 |
mr->checked=1;
|
634 |
}
|
635 |
while (ret < count && !mr->last) {
|
636 |
#ifdef DEBUG_COORD_GET
|
637 |
dbg(1,"coord first %d lseg_done %d\n",mr->first,mr->lseg_done);
|
638 |
#endif
|
639 |
if (mr->lseg_done) {
|
640 |
#ifdef DEBUG_COORD_GET
|
641 |
dbg(1,"loading %d of %d from id_lo %d\n", mr->idx, mr->sd->count, mr->sd->item.id_lo);
|
642 |
#endif
|
643 |
if (!mr->idx) {
|
644 |
if (coord_next(mr, &mr->lseg[0])) {
|
645 |
mr->route_item_done=1;
|
646 |
mr->last=1;
|
647 |
mr->idx_base=mr->idx=0;
|
648 |
break;
|
649 |
}
|
650 |
mr->first=1;
|
651 |
} else
|
652 |
mr->lseg[0]=mr->lseg[1];
|
653 |
if (coord_next(mr, &mr->lseg[1])) {
|
654 |
mr->route_item_done=1;
|
655 |
mr->last=1;
|
656 |
mr->idx_base=mr->idx=0;
|
657 |
break;
|
658 |
}
|
659 |
mr->c_next=mr->lseg[0];
|
660 |
mr->lseg_done=0;
|
661 |
}
|
662 |
l0=mr->c_next;
|
663 |
l1=mr->lseg[1];
|
664 |
#ifdef DEBUG_COORD_GET
|
665 |
dbg(1,"line (0x%x,0x%x)-(0x%x,0x%x)\n", l0.x,l0.y,l1.x,l1.y);
|
666 |
#endif
|
667 |
vis=is_visible_line(&mr->c0, &l0, &l1);
|
668 |
if (debug) {
|
669 |
fprintf(debug,"type=tracking_%d debug=\"%s\"\n",vis*20,buffer);
|
670 |
fprintf(debug,"0x%x 0x%x\n", l0.x, l0.y);
|
671 |
fprintf(debug,"0x%x 0x%x\n", l1.x, l1.y);
|
672 |
}
|
673 |
#ifdef DEBUG_COORD_GET
|
674 |
dbg(1,"vis=%d line (0x%x,0x%x)-(0x%x,0x%x)\n", vis, l0.x,l0.y,l1.x,l1.y);
|
675 |
#endif
|
676 |
mr->idx_base=mr->idx;
|
677 |
mr->c_next_base=mr->c_next;
|
678 |
mr->lseg_base[0]=mr->lseg[0];
|
679 |
mr->lseg_base[1]=mr->lseg[1];
|
680 |
mr->lseg_done_base=mr->lseg_done;
|
681 |
switch (vis) {
|
682 |
case 0:
|
683 |
mr->c_next_base=mr->c_next;
|
684 |
#ifdef DEBUG_COORD_GET
|
685 |
dbg(1,"out 0x%x,0x%x\n", l0.x, l1.y);
|
686 |
#endif
|
687 |
c[ret++]=l0;
|
688 |
#ifdef DEBUG_COORD_GET
|
689 |
dbg(1,"out 0x%x,0x%x\n", l1.x, l1.y);
|
690 |
#endif
|
691 |
c[ret++]=l1;
|
692 |
mr->lseg_done_base=mr->lseg_done=1;
|
693 |
mr->last=1;
|
694 |
break;
|
695 |
case 1:
|
696 |
#ifdef DEBUG_COORD_GET
|
697 |
dbg(1,"begin clipped\n");
|
698 |
dbg(1,"out 0x%x,0x%x\n", l0.x, l1.y);
|
699 |
#endif
|
700 |
c[ret++]=l0;
|
701 |
#ifdef DEBUG_COORD_GET
|
702 |
dbg(1,"out 0x%x,0x%x\n", l1.x, l1.y);
|
703 |
#endif
|
704 |
c[ret++]=l1;
|
705 |
mr->c_next_base=mr->c_next=l1;
|
706 |
mr->last=1;
|
707 |
break;
|
708 |
case 2:
|
709 |
#ifdef DEBUG_COORD_GET
|
710 |
dbg(1,"end clipped\n");
|
711 |
#endif
|
712 |
mr->c_next_base=mr->c_next;
|
713 |
#ifdef DEBUG_COORD_GET
|
714 |
dbg(1,"out 0x%x,0x%x\n", l0.x, l1.y);
|
715 |
#endif
|
716 |
c[ret++]=l0;
|
717 |
#ifdef DEBUG_COORD_GET
|
718 |
dbg(1,"out 0x%x,0x%x\n", l1.x, l1.y);
|
719 |
#endif
|
720 |
c[ret++]=l1;
|
721 |
mr->c_next_base=mr->c_next=l1;
|
722 |
mr->last=1;
|
723 |
break;
|
724 |
case 3:
|
725 |
#ifdef DEBUG_COORD_GET
|
726 |
dbg(1,"both clipped\n");
|
727 |
#endif
|
728 |
mr->c_next_base=mr->c_next;
|
729 |
#ifdef DEBUG_COORD_GET
|
730 |
dbg(1,"out 0x%x,0x%x\n", l0.x, l1.y);
|
731 |
#endif
|
732 |
c[ret++]=l0;
|
733 |
#ifdef DEBUG_COORD_GET
|
734 |
dbg(1,"out 0x%x,0x%x\n", l1.x, l1.y);
|
735 |
#endif
|
736 |
c[ret++]=l1;
|
737 |
mr->c_next_base=mr->c_next=l1;
|
738 |
mr->last=1;
|
739 |
break;
|
740 |
case 4:
|
741 |
mr->last=1;
|
742 |
mr->lseg_done_base=mr->lseg_done=1;
|
743 |
break;
|
744 |
|
745 |
#if 0
|
746 |
case 2:
|
747 |
dbg(1,"visible up to 0x%x,0x%x\n",l1.x,l1.y);
|
748 |
if (mr->first) {
|
749 |
mr->first=0;
|
750 |
c[ret++]=mr->c_out;
|
751 |
dbg(1,"out 0x%x,0x%x\n", mr->c_out.x, mr->c_out.y);
|
752 |
}
|
753 |
c[ret++]=mr->c_out=l1;
|
754 |
dbg(1,"out 0x%x,0x%x\n", l1.x, l1.y);
|
755 |
mr->last=1;
|
756 |
mr->route_item_done=1;
|
757 |
break;
|
758 |
case 1:
|
759 |
case 3:
|
760 |
case 4:
|
761 |
dbg(1,"invisible\n");
|
762 |
mr->c_out=l1;
|
763 |
mr->idx++;
|
764 |
mr->last=1;
|
765 |
mr->route_item_done=1;
|
766 |
break;
|
767 |
}
|
768 |
if (!vis)
|
769 |
break;
|
770 |
#endif
|
771 |
}
|
772 |
}
|
773 |
#ifdef DEBUG_COORD_GET
|
774 |
dbg(1,"ret=%d last=%d\n", ret, mr->last);
|
775 |
#endif
|
776 |
return ret;
|
777 |
}
|
778 |
|
779 |
static struct item_methods methods_route_occluded_item = {
|
780 |
map_route_occluded_coord_rewind,
|
781 |
map_route_occluded_coord_get,
|
782 |
map_route_occluded_attr_rewind,
|
783 |
map_route_occluded_attr_get,
|
784 |
};
|
785 |
|
786 |
static void
|
787 |
map_route_occluded_destroy(struct map_priv *priv)
|
788 |
{
|
789 |
g_free(priv);
|
790 |
}
|
791 |
|
792 |
static int no_recurse;
|
793 |
|
794 |
static struct map_rect_priv *
|
795 |
map_route_occluded_rect_new(struct map_priv *priv, struct map_selection *sel)
|
796 |
{
|
797 |
struct map_rect_priv * mr;
|
798 |
struct attr route;
|
799 |
struct attr route_map;
|
800 |
struct map_rect *route_map_rect;
|
801 |
struct coord_rect r;
|
802 |
if (!navit_get_attr(priv->navit, attr_route, &route, NULL)) {
|
803 |
dbg(0,"no route in navit\n");
|
804 |
return NULL;
|
805 |
}
|
806 |
if (!route_get_attr(route.u.route, attr_map, &route_map, NULL)) {
|
807 |
dbg(0,"no map in route\n");
|
808 |
return NULL;
|
809 |
}
|
810 |
route_map_rect=map_rect_new(route_map.u.map, sel);
|
811 |
if (!route_map_rect) {
|
812 |
dbg(0,"no route map rect\n");
|
813 |
return NULL;
|
814 |
}
|
815 |
map_dump_file(route_map.u.map, "route.txt");
|
816 |
mr=g_new0(struct map_rect_priv, 1);
|
817 |
mr->route_map_rect=route_map_rect;
|
818 |
mr->mpriv = priv;
|
819 |
mr->item.priv_data = mr;
|
820 |
mr->item.meth = &methods_route_occluded_item;
|
821 |
mr->item.id_lo = -1;
|
822 |
mr->route_item_done=1;
|
823 |
mr->lseg_done_base=1;
|
824 |
mr->last=1;
|
825 |
if (!no_recurse && map_route_occluded_bbox(route_map.u.map, &r)) {
|
826 |
struct attr mapset;
|
827 |
no_recurse++;
|
828 |
if (navit_get_attr(mr->mpriv->navit, attr_mapset, &mapset, NULL))
|
829 |
map_route_occluded_get_buildings(mapset.u.mapset, &r);
|
830 |
debug=fopen("tst.txt","w");
|
831 |
debug2=fopen("tstp.txt","w");
|
832 |
no_recurse--;
|
833 |
}
|
834 |
return mr;
|
835 |
}
|
836 |
|
837 |
|
838 |
static void
|
839 |
map_route_occluded_rect_destroy(struct map_rect_priv *mr)
|
840 |
{
|
841 |
map_rect_destroy(mr->route_map_rect);
|
842 |
street_data_free(mr->sd);
|
843 |
g_free(mr);
|
844 |
if (!no_recurse) {
|
845 |
if (debug) {
|
846 |
fclose(debug);
|
847 |
debug=NULL;
|
848 |
}
|
849 |
if (debug2) {
|
850 |
fclose(debug2);
|
851 |
debug2=NULL;
|
852 |
}
|
853 |
}
|
854 |
#if 0
|
855 |
static int in_dump;
|
856 |
if (! in_dump) {
|
857 |
in_dump=1;
|
858 |
map_dump_file(global_map,"route.txt");
|
859 |
in_dump=0;
|
860 |
}
|
861 |
#endif
|
862 |
}
|
863 |
|
864 |
static struct item *
|
865 |
map_route_occluded_get_item(struct map_rect_priv *mr)
|
866 |
{
|
867 |
dbg(1,"enter last=%d\n",mr->last);
|
868 |
while (!mr->last) {
|
869 |
struct coord c[128];
|
870 |
map_route_occluded_coord_get(mr, c, 128);
|
871 |
}
|
872 |
if (mr->route_item_done) {
|
873 |
dbg(1,"next route item\n");
|
874 |
do {
|
875 |
mr->route_item=map_rect_get_item(mr->route_map_rect);
|
876 |
} while (mr->route_item && mr->route_item->type != type_street_route);
|
877 |
dbg(1,"item %p\n", mr->route_item);
|
878 |
if (!mr->route_item)
|
879 |
return NULL;
|
880 |
mr->item.type=type_street_route_occluded;
|
881 |
street_data_free(mr->sd);
|
882 |
mr->sd=street_get_data(mr->route_item);
|
883 |
mr->route_item_done=0;
|
884 |
}
|
885 |
mr->item.id_lo++;
|
886 |
#if 0
|
887 |
if (mr->item.id_lo > 20)
|
888 |
return NULL;
|
889 |
#endif
|
890 |
map_route_occluded_coord_rewind(mr);
|
891 |
dbg(1,"type %s\n", item_to_name(mr->route_item->type));
|
892 |
return &mr->item;
|
893 |
}
|
894 |
|
895 |
static struct item *
|
896 |
map_route_occluded_get_item_byid(struct map_rect_priv *mr, int id_hi, int id_lo)
|
897 |
{
|
898 |
struct item *ret=NULL;
|
899 |
while (id_lo-- > 0)
|
900 |
ret=map_route_occluded_get_item(mr);
|
901 |
return ret;
|
902 |
}
|
903 |
|
904 |
static struct map_methods map_route_occluded_methods = {
|
905 |
projection_mg,
|
906 |
"utf-8",
|
907 |
map_route_occluded_destroy,
|
908 |
map_route_occluded_rect_new,
|
909 |
map_route_occluded_rect_destroy,
|
910 |
map_route_occluded_get_item,
|
911 |
map_route_occluded_get_item_byid,
|
912 |
NULL,
|
913 |
NULL,
|
914 |
NULL,
|
915 |
};
|
916 |
|
917 |
|
918 |
static struct map_priv *
|
919 |
map_route_occluded_new(struct map_methods *meth, struct attr **attrs)
|
920 |
{
|
921 |
struct map_priv *ret;
|
922 |
struct attr *navit;
|
923 |
dbg(0,"enter\n");
|
924 |
navit=attr_search(attrs, NULL, attr_navit);
|
925 |
if (! navit)
|
926 |
return NULL;
|
927 |
ret=g_new0(struct map_priv, 1);
|
928 |
*meth=map_route_occluded_methods;
|
929 |
ret->navit=navit->u.navit;
|
930 |
dbg(0,"m=%p navit=%p\n", ret, ret->navit);
|
931 |
return ret;
|
932 |
}
|
933 |
|
934 |
static void
|
935 |
pedestrian_graphics_resize(struct graphics *gra, int w, int h)
|
936 |
{
|
937 |
#ifndef HAVE_API_ANDROID
|
938 |
static int done;
|
939 |
if (!done) {
|
940 |
int id=(int)graphics_get_data(gra, "xwindow_id");
|
941 |
char buffer[1024];
|
942 |
sprintf(buffer,"testxv %d &",id);
|
943 |
system(buffer);
|
944 |
done=1;
|
945 |
}
|
946 |
#endif
|
947 |
pedestrian_data.w=w;
|
948 |
pedestrian_data.h=h;
|
949 |
}
|
950 |
|
951 |
|
952 |
static void
|
953 |
pedestrian_draw_arrow(struct graphics *gra, char *name, int x, int y)
|
954 |
{
|
955 |
char *src=graphics_icon_path(name);
|
956 |
struct graphics_image *img=graphics_image_new(gra, src);
|
957 |
struct graphics_gc *gc=graphics_gc_new(gra);
|
958 |
struct color col={0xffff,0xffff,0xffff,0xffff};
|
959 |
struct point p;
|
960 |
graphics_gc_set_foreground(gc, &col);
|
961 |
p.x=x;
|
962 |
p.y=y;
|
963 |
graphics_draw_image(gra, gc, &p, img);
|
964 |
graphics_image_free(gra, img);
|
965 |
graphics_gc_destroy(gc);
|
966 |
g_free(src);
|
967 |
}
|
968 |
|
969 |
static void
|
970 |
pedestrian_draw_arrows(struct graphics *gra)
|
971 |
{
|
972 |
struct attr route, route_map;
|
973 |
struct map_rect *route_map_rect;
|
974 |
struct item *item;
|
975 |
|
976 |
if (orientation == 2)
|
977 |
return;
|
978 |
if (!navit_get_attr(pedestrian_data.nav, attr_route, &route, NULL)) {
|
979 |
dbg(0,"no route in navit\n");
|
980 |
return;
|
981 |
}
|
982 |
if (!route_get_attr(route.u.route, attr_map, &route_map, NULL)) {
|
983 |
dbg(0,"no map in route\n");
|
984 |
return;
|
985 |
}
|
986 |
route_map_rect=map_rect_new(route_map.u.map, NULL);
|
987 |
if (!route_map_rect) {
|
988 |
dbg(0,"no route map rect\n");
|
989 |
return;
|
990 |
}
|
991 |
while ((item=map_rect_get_item(route_map_rect))) {
|
992 |
if (item->type == type_street_route) {
|
993 |
struct coord c[2];
|
994 |
if (item_coord_get(item, c, 2) == 2) {
|
995 |
struct coord *center=transform_get_center(navit_get_trans(pedestrian_data.nav));
|
996 |
int angle=transform_get_angle_delta(center, &c[1], 0);
|
997 |
angle-=pedestrian_data.yaw;
|
998 |
if (angle < 0)
|
999 |
angle+=360;
|
1000 |
if (angle >= 360)
|
1001 |
angle-=360;
|
1002 |
if (angle > 180 && angle < 350)
|
1003 |
pedestrian_draw_arrow(gra,"gui_arrow_left_32_32.png",0,pedestrian_data.h/2-16);
|
1004 |
if (angle > 10 && angle <= 180)
|
1005 |
pedestrian_draw_arrow(gra,"gui_arrow_right_32_32.png",pedestrian_data.w-32,pedestrian_data.h/2-16);
|
1006 |
}
|
1007 |
break;
|
1008 |
}
|
1009 |
}
|
1010 |
map_rect_destroy(route_map_rect);
|
1011 |
}
|
1012 |
|
1013 |
static void
|
1014 |
pedestrian_graphics_postdraw(struct graphics *gra)
|
1015 |
{
|
1016 |
#if 0
|
1017 |
struct graphics_gc * gc = graphics_gc_new(gra);
|
1018 |
struct point p;
|
1019 |
struct color c = {0xadad,0xd8d8,0xe6e6,0xffff};
|
1020 |
p.x=0;
|
1021 |
p.y=0;
|
1022 |
graphics_gc_set_foreground(gc, &c);
|
1023 |
graphics_gc_set_stipple(gc, NULL);
|
1024 |
graphics_draw_rectangle(gra, gc, &p, 1000, 200);
|
1025 |
graphics_gc_destroy(gc);
|
1026 |
#endif
|
1027 |
pedestrian_draw_arrows(gra);
|
1028 |
}
|
1029 |
|
1030 |
#ifndef HAVE_API_ANDROID
|
1031 |
struct tilt_data {
|
1032 |
int len,axis;
|
1033 |
char buffer[32];
|
1034 |
};
|
1035 |
|
1036 |
void
|
1037 |
pedestrian_write_tilt(int fd, int axis)
|
1038 |
{
|
1039 |
char *buffer="01";
|
1040 |
int ret;
|
1041 |
|
1042 |
ret=write(fd, buffer+axis, 1);
|
1043 |
if (ret != 2) {
|
1044 |
dbg(0,"ret=%d\n",ret);
|
1045 |
}
|
1046 |
}
|
1047 |
|
1048 |
|
1049 |
void
|
1050 |
pedestrian_read_tilt(int fd, struct navit *nav, struct tilt_data *data)
|
1051 |
{
|
1052 |
int val,ret,maxlen=3;
|
1053 |
ret=read(fd, data->buffer+data->len, maxlen-data->len);
|
1054 |
if (ret > 0) {
|
1055 |
data->len+=ret;
|
1056 |
data->buffer[data->len]='\0';
|
1057 |
}
|
1058 |
if (data->len == 3) {
|
1059 |
struct attr attr;
|
1060 |
sscanf(data->buffer,"%02x",&val);
|
1061 |
data->len=0;
|
1062 |
if (navit_get_attr(nav, attr_transformation, &attr, NULL)) {
|
1063 |
struct transformation *trans=attr.u.transformation;
|
1064 |
dbg(0,"ok axis=%d val=0x%x\n", data->axis, val);
|
1065 |
if (data->axis != 1) {
|
1066 |
transform_set_pitch(trans, 90+(val-0x80));
|
1067 |
} else {
|
1068 |
transform_set_roll(trans, 0x80-val);
|
1069 |
}
|
1070 |
}
|
1071 |
data->axis=1-data->axis;
|
1072 |
|
1073 |
#if 0
|
1074 |
pedestrian_write_tilt(fd, data->axis);
|
1075 |
#endif
|
1076 |
}
|
1077 |
}
|
1078 |
|
1079 |
void
|
1080 |
pedestrian_write_tilt_timer(int fd, struct tilt_data *data)
|
1081 |
{
|
1082 |
pedestrian_write_tilt(fd, data->axis);
|
1083 |
}
|
1084 |
|
1085 |
void
|
1086 |
pedestrian_setup_tilt(struct navit *nav)
|
1087 |
{
|
1088 |
int fd,on=1;
|
1089 |
struct termios t;
|
1090 |
struct callback *cb,*cbt;
|
1091 |
struct tilt_data *data=g_new0(struct tilt_data, 1);
|
1092 |
char buffer[32];
|
1093 |
fd=open("/dev/tiltsensor",O_RDWR);
|
1094 |
if (fd == -1) {
|
1095 |
dbg(0,"Failed to set up tilt sensor, error %d\n",errno);
|
1096 |
return;
|
1097 |
}
|
1098 |
tcgetattr(fd, &t);
|
1099 |
cfmakeraw(&t);
|
1100 |
cfsetspeed(&t, B19200);
|
1101 |
tcsetattr(fd, TCSANOW, &t);
|
1102 |
ioctl(fd, FIONBIO, &on);
|
1103 |
cb=callback_new_3(callback_cast(pedestrian_read_tilt), fd, nav, data);
|
1104 |
cbt=callback_new_2(callback_cast(pedestrian_write_tilt_timer), fd, data);
|
1105 |
event_add_watch((void *)fd, event_watch_cond_read, cb);
|
1106 |
event_add_timeout(300, 1, cbt);
|
1107 |
read(fd, buffer, 32);
|
1108 |
#if 0
|
1109 |
pedestrian_write_tilt(fd, 0);
|
1110 |
#endif
|
1111 |
}
|
1112 |
|
1113 |
#else
|
1114 |
|
1115 |
|
1116 |
float sensors[2][3];
|
1117 |
|
1118 |
static void
|
1119 |
android_sensors(struct navit *nav, int sensor, float *x, float *y, float *z)
|
1120 |
{
|
1121 |
float yaw=0,pitch=0;
|
1122 |
struct attr attr;
|
1123 |
sensors[sensor-1][0]=*x;
|
1124 |
sensors[sensor-1][1]=*y;
|
1125 |
sensors[sensor-1][2]=*z;
|
1126 |
if (sensors_locked)
|
1127 |
return;
|
1128 |
dbg(1,"enter %d %f %f %f\n",sensor,*x,*y,*z);
|
1129 |
if (sensor == 1) {
|
1130 |
if (*x > 7.5)
|
1131 |
orientation=1; /* landscape */
|
1132 |
if (*y > 7.5)
|
1133 |
orientation=0; /* portrait */
|
1134 |
if (*z > 7.5)
|
1135 |
orientation=2; /* flat */
|
1136 |
dbg(1,"orientation=%d\n",orientation);
|
1137 |
}
|
1138 |
if ((orientation_old == 2) != (orientation == 2)) {
|
1139 |
struct attr attr, flags_graphics, osd_configuration;
|
1140 |
navit_set_attr(nav, orientation == 2 ? &initial_layout:&main_layout);
|
1141 |
navit_get_attr(nav, attr_transformation, &attr, NULL);
|
1142 |
transform_set_scale(attr.u.transformation, orientation == 2 ? 64:16);
|
1143 |
flags_graphics.type=attr_flags_graphics;
|
1144 |
flags_graphics.u.num=orientation == 2 ? 0:10;
|
1145 |
navit_set_attr(nav, &flags_graphics);
|
1146 |
osd_configuration.type=attr_osd_configuration;
|
1147 |
osd_configuration.u.num=orientation == 2 ? 1:2;
|
1148 |
navit_set_attr(nav, &osd_configuration);
|
1149 |
}
|
1150 |
orientation_old=orientation;
|
1151 |
switch (orientation) {
|
1152 |
case 2:
|
1153 |
if (sensor == 2) {
|
1154 |
yaw=atan2f(-*y,-*x)*180/M_PI+180;
|
1155 |
}
|
1156 |
pitch=0;
|
1157 |
break;
|
1158 |
case 1:
|
1159 |
if (sensor == 1) {
|
1160 |
pitch=atan2f(*x,*z)*180/M_PI;
|
1161 |
}
|
1162 |
if (sensor == 2) {
|
1163 |
yaw=atan2f(-*y,*z)*180/M_PI+180;
|
1164 |
}
|
1165 |
break;
|
1166 |
case 0:
|
1167 |
if (sensor == 1) {
|
1168 |
pitch=atan2f(*y,*z)*180/M_PI;
|
1169 |
}
|
1170 |
if (sensor == 2) {
|
1171 |
yaw=atan2f(*x,*z)*180/M_PI+180;
|
1172 |
}
|
1173 |
break;
|
1174 |
}
|
1175 |
if (navit_get_attr(nav, attr_transformation, &attr, NULL)) {
|
1176 |
struct transformation *trans=attr.u.transformation;
|
1177 |
if (sensor == 1) {
|
1178 |
if (orientation != 2)
|
1179 |
pitch+=2.0;
|
1180 |
transform_set_pitch(trans, (int)pitch);
|
1181 |
dbg(1,"pich %d %f\n",orientation,pitch);
|
1182 |
} else {
|
1183 |
struct attr attr;
|
1184 |
attr.type=attr_orientation;
|
1185 |
attr.u.num=yaw-1.0;
|
1186 |
if (attr.u.num < 0)
|
1187 |
attr.u.num+=360;
|
1188 |
pedestrian_data.yaw=attr.u.num;
|
1189 |
navit_set_attr(nav, &attr);
|
1190 |
dbg(1,"yaw %d %f\n",orientation,yaw);
|
1191 |
if (orientation == 2)
|
1192 |
navit_set_center_cursor(nav, 1, 0);
|
1193 |
}
|
1194 |
}
|
1195 |
}
|
1196 |
#endif
|
1197 |
|
1198 |
static void
|
1199 |
pedestrian_log(char **logstr)
|
1200 |
{
|
1201 |
#ifdef HAVE_API_ANDROID
|
1202 |
char *tag=g_strdup_printf(
|
1203 |
"\t\t<navit:compass:x>%f</navit:compass:x>\n"
|
1204 |
"\t\t<navit:compass:y>%f</navit:compass:y>\n"
|
1205 |
"\t\t<navit:compass:z>%f</navit:compass:z>\n"
|
1206 |
"\t\t<navit:accel:x>%f</navit:accel:x>\n"
|
1207 |
"\t\t<navit:accel:y>%f</navit:accel:y>\n"
|
1208 |
"\t\t<navit:accel:z>%f</navit:accel:z>\n",
|
1209 |
sensors[0][0],sensors[0][1],sensors[0][2],
|
1210 |
sensors[1][0],sensors[1][1],sensors[1][2]);
|
1211 |
vehicle_log_gpx_add_tag(tag, logstr);
|
1212 |
#endif
|
1213 |
}
|
1214 |
|
1215 |
#ifdef DEMO
|
1216 |
static void
|
1217 |
vehicle_changed(struct vehicle *v, struct transformation *trans)
|
1218 |
{
|
1219 |
struct attr attr;
|
1220 |
if (vehicle_get_attr(v, attr_position_direction, &attr, NULL)) {
|
1221 |
int dir=(int)(*attr.u.numd);
|
1222 |
dbg(0,"enter %d\n",dir);
|
1223 |
transform_set_pitch(trans, 90);
|
1224 |
transform_set_yaw(trans, dir);
|
1225 |
}
|
1226 |
}
|
1227 |
#endif
|
1228 |
|
1229 |
|
1230 |
static void
|
1231 |
pedestrian_navit_init(struct navit *nav)
|
1232 |
{
|
1233 |
struct attr route;
|
1234 |
struct attr route_map;
|
1235 |
struct attr map;
|
1236 |
struct attr mapset;
|
1237 |
struct attr graphics,attr,flags_graphics;
|
1238 |
struct transformation *trans;
|
1239 |
struct attr_iter *iter;
|
1240 |
|
1241 |
#ifdef HAVE_API_ANDROID
|
1242 |
struct callback *cb;
|
1243 |
jclass navitsensorsclass;
|
1244 |
jmethodID cid;
|
1245 |
jobject navitsensors;
|
1246 |
|
1247 |
dbg(0,"enter\n");
|
1248 |
if (android_find_class_global("com/zoffcc/applications/zanavi/NavitSensors", &navitsensorsclass)) {
|
1249 |
dbg(0,"class found\n");
|
1250 |
cid = (*jnienv)->GetMethodID(jnienv, navitsensorsclass, "<init>", "(Landroid/content/Context;I)V");
|
1251 |
dbg(0,"cid=%p\n",cid);
|
1252 |
if (cid) {
|
1253 |
cb=callback_new_1(callback_cast(android_sensors), nav);
|
1254 |
navitsensors=(*jnienv)->NewObject(jnienv, navitsensorsclass, cid, android_activity, cb);
|
1255 |
dbg(0,"object=%p\n",navitsensors);
|
1256 |
if (navitsensors)
|
1257 |
(*jnienv)->NewGlobalRef(jnienv, navitsensors);
|
1258 |
}
|
1259 |
|
1260 |
}
|
1261 |
#endif
|
1262 |
pedestrian_data.nav=nav;
|
1263 |
flags_graphics.type=attr_flags_graphics;
|
1264 |
flags_graphics.u.num=10;
|
1265 |
navit_set_attr(nav, &flags_graphics);
|
1266 |
if (navit_get_attr(nav, attr_graphics, &graphics, NULL)) {
|
1267 |
struct attr attr;
|
1268 |
struct callback *cb=callback_new_attr_1(callback_cast(pedestrian_graphics_resize),attr_resize,graphics.u.graphics);
|
1269 |
graphics_add_callback(graphics.u.graphics, cb);
|
1270 |
cb=callback_new_attr_1(callback_cast(pedestrian_graphics_postdraw),attr_postdraw,graphics.u.graphics);
|
1271 |
graphics_add_callback(graphics.u.graphics, cb);
|
1272 |
attr.type=attr_use_camera;
|
1273 |
attr.u.num=1;
|
1274 |
graphics_set_attr(graphics.u.graphics, &attr);
|
1275 |
}
|
1276 |
osd_rocket_init(nav);
|
1277 |
#if 1
|
1278 |
#ifndef HAVE_API_ANDROID
|
1279 |
pedestrian_setup_tilt(nav);
|
1280 |
#endif
|
1281 |
trans=navit_get_trans(nav);
|
1282 |
transform_set_pitch(trans, 90);
|
1283 |
transform_set_roll(trans, 0);
|
1284 |
transform_set_hog(trans, 2);
|
1285 |
transform_set_distance(trans, 0);
|
1286 |
transform_set_scales(trans, 750, 620, 32 << 8);
|
1287 |
if (!navit_get_attr(nav, attr_route, &route, NULL))
|
1288 |
return;
|
1289 |
if (!route_get_attr(route.u.route, attr_map, &route_map, NULL))
|
1290 |
return;
|
1291 |
dbg(0,"enter 1\n");
|
1292 |
#if 0
|
1293 |
struct attr active;
|
1294 |
active.type=attr_active;
|
1295 |
active.u.num=0;
|
1296 |
if (!map_set_attr(route_map.u.map, &active))
|
1297 |
return;
|
1298 |
dbg(0,"enter 2\n");
|
1299 |
#endif
|
1300 |
if (!navit_get_attr(nav, attr_mapset, &mapset, NULL))
|
1301 |
return;
|
1302 |
map.type=attr_map;
|
1303 |
map.u.map=map_new(NULL, (struct attr*[]){
|
1304 |
&(struct attr){attr_type,{"route_occluded"}},
|
1305 |
&(struct attr){attr_data,{""}},
|
1306 |
&(struct attr){attr_description,{"Occluded Route"}},
|
1307 |
&(struct attr){attr_navit,{(void *)nav}},
|
1308 |
NULL});
|
1309 |
global_map=map.u.map;
|
1310 |
mapset_add_attr(mapset.u.mapset, &map);
|
1311 |
|
1312 |
#if 0
|
1313 |
map=route_get_attr(route, attr_map);
|
1314 |
#endif
|
1315 |
#endif
|
1316 |
transform_set_scale(trans, 16);
|
1317 |
navit_get_attr(nav, attr_layout, &initial_layout, NULL);
|
1318 |
iter=navit_attr_iter_new();
|
1319 |
while(navit_get_attr(nav, attr_layout, &attr, iter)) {
|
1320 |
if (!strcmp(attr.u.layout->name, "Route")) {
|
1321 |
dbg(0,"found %s\n",attr_to_name(attr.type));
|
1322 |
main_layout=attr;
|
1323 |
#if 1
|
1324 |
navit_set_attr(nav, &attr);
|
1325 |
#endif
|
1326 |
break;
|
1327 |
}
|
1328 |
}
|
1329 |
navit_attr_iter_destroy(iter);
|
1330 |
if (navit_get_attr(nav, attr_vehicle, &attr, NULL)) {
|
1331 |
struct attr cbattr;
|
1332 |
cbattr.u.callback=callback_new_attr_0(callback_cast(pedestrian_log), attr_log_gpx);
|
1333 |
cbattr.type=attr_callback;
|
1334 |
vehicle_add_attr(attr.u.vehicle, &cbattr);
|
1335 |
#ifdef DEMO
|
1336 |
cbattr.u.callback=callback_new_attr_2(callback_cast(vehicle_changed), attr_position_coord_geo, attr.u.vehicle, trans);
|
1337 |
cbattr.type=attr_callback;
|
1338 |
vehicle_add_attr(attr.u.vehicle, &cbattr);
|
1339 |
#endif
|
1340 |
}
|
1341 |
|
1342 |
}
|
1343 |
|
1344 |
static void
|
1345 |
pedestrian_navit(struct navit *nav, int add)
|
1346 |
{
|
1347 |
dbg(0,"enter\n");
|
1348 |
struct attr callback;
|
1349 |
if (add) {
|
1350 |
callback.type=attr_callback;
|
1351 |
callback.u.callback=callback_new_attr_0(callback_cast(pedestrian_navit_init), attr_navit);
|
1352 |
navit_add_attr(nav, &callback);
|
1353 |
}
|
1354 |
}
|
1355 |
|
1356 |
void
|
1357 |
plugin_init(void)
|
1358 |
{
|
1359 |
struct attr callback,navit;
|
1360 |
struct attr_iter *iter;
|
1361 |
#ifdef HAVE_API_ANDROID
|
1362 |
jclass ActivityClass;
|
1363 |
jmethodID Activity_setRequestedOrientation;
|
1364 |
|
1365 |
if (!android_find_class_global("android/app/Activity", &ActivityClass))
|
1366 |
dbg(0,"failed to get class android/app/Activity\n");
|
1367 |
Activity_setRequestedOrientation = (*jnienv)->GetMethodID(jnienv, ActivityClass, "setRequestedOrientation", "(I)V");
|
1368 |
if (Activity_setRequestedOrientation == NULL)
|
1369 |
dbg(0,"failed to get method setRequestedOrientation from android/app/Activity\n");
|
1370 |
(*jnienv)->CallVoidMethod(jnienv, android_activity, Activity_setRequestedOrientation, 0);
|
1371 |
#endif
|
1372 |
|
1373 |
plugin_register_osd_type("marker", osd_marker_new);
|
1374 |
plugin_register_map_type("route_occluded", map_route_occluded_new);
|
1375 |
callback.type=attr_callback;
|
1376 |
callback.u.callback=callback_new_attr_0(callback_cast(pedestrian_navit), attr_navit);
|
1377 |
config_add_attr(config, &callback);
|
1378 |
iter=config_attr_iter_new();
|
1379 |
while (config_get_attr(config, attr_navit, &navit, iter))
|
1380 |
pedestrian_navit_init(navit.u.navit);
|
1381 |
config_attr_iter_destroy(iter);
|
1382 |
}
|