13 void calc_vis(int dir);
14 int is_visible(float x, float y, float dir);
20 printf("struct {int dx, dy;} visoffs[%d][32] = {\n", NUM_DIRS);
22 for(i=0; i<NUM_DIRS; i++) {
24 printf("\t/* dir %d */\n", i);
32 int cellcmp(const void *a, const void *b)
34 const struct cell *ca = a;
35 const struct cell *cb = b;
36 int za = ca->dx * ca->dx + ca->dy * ca->dy;
37 int zb = cb->dx * cb->dx + cb->dy * cb->dy;
41 void calc_vis(int dir)
46 float theta = (float)(dir + 2) / NUM_DIRS * M_PI * 2.0f;
48 fprintf(stderr, "DIR: %d (angle: %g)\n", dir, theta * 180.0f / M_PI);
50 for(i=0; i<MAX_DIST*2+1; i++) {
52 for(j=0; j<MAX_DIST*2+1; j++) {
55 if(is_visible(x, y, theta)) {
69 qsort(vis, count, sizeof *vis, cellcmp);
73 for(i=0; i<count; i++) {
74 col += printf("{%d,%d}", vis[i].dx, vis[i].dy);
77 fputs(",\n\t ", stdout);
85 fputs(dir < NUM_DIRS - 1 ? "},\n" : "}\n", stdout);
90 float ptlinedist(float x, float y, float dir)
92 return -y * cos(dir) + sin(dir) * x;
95 int is_visible(float x, float y, float dir)
97 static const char voffs[][2] = {{-0.5, -0.5}, {0.5, -0.5}, {0.5, 0.5}, {-0.5, 0.5}};
100 float hfov = 0.5f * FOV * M_PI / 180.0f;
102 d0 = ptlinedist(x, y, dir - hfov);
103 d1 = ptlinedist(x, y, dir + hfov);
104 if(d0 >= 0 && d1 <= 0) {
109 d0 = ptlinedist(x + voffs[i][0], y + voffs[i][1], dir - hfov);
110 d1 = ptlinedist(x + voffs[i][0], y + voffs[i][1], dir + hfov);
112 if(d0 >= 0 && d1 <= 0) {