diff --git a/graph.cpp b/graph.cpp index 4ad15ccc..b7f3e35c 100644 --- a/graph.cpp +++ b/graph.cpp @@ -721,13 +721,13 @@ bool drawing_usershape_on(cell *c, mapeditor::eShapegroup sg) { ld max_eu_dist = 0; transmatrix radar_transform; -void addradar(const transmatrix& V, char ch, color_t col, color_t outline) { - hyperpoint h = tC0(V); - if(GDIM == 3 && WDIM == 2) h = tC0(radar_transform * V); +pair makeradar(hyperpoint h) { + if(GDIM == 3 && WDIM == 2) h = radar_transform * h; using namespace hyperpoint_vec; ld d = hdist0(h); - if(d > sightranges[geometry]) return; + if(d >= sightranges[geometry]) return {false, h}; + if(WDIM == 3) { if(d) h = h * (d / sightranges[geometry] / hypot_d(3, h)); } @@ -741,7 +741,21 @@ void addradar(const transmatrix& V, char ch, color_t col, color_t outline) { if(d > max_eu_dist) max_eu_dist = d; if(d) h = h * (d / (max_eu_dist + cgi.scalefactor/4) / hypot_d(3, h)); } - radarpoints.emplace_back(radarpoint{h, ch, col, outline}); + return {true, h}; + } + +void addradar(const transmatrix& V, char ch, color_t col, color_t outline) { + hyperpoint h = tC0(V); + auto hp = makeradar(h); + if(hp.first) + radarpoints.emplace_back(radarpoint{hp.second, ch, col, outline}); + } + +void addradar(const hyperpoint h1, const hyperpoint h2, color_t col) { + auto hp1 = makeradar(h1); + auto hp2 = makeradar(h2); + if(hp1.first && hp2.first) + radarlines.emplace_back(radarline{hp1.second, hp2.second, col}); } color_t kind_outline(eItem it) { @@ -4431,6 +4445,12 @@ void gridline(const transmatrix& V, const hyperpoint h1, const hyperpoint h2, co gridline(V, h1, V, h2, col, prec); } +void radar_grid(cell *c, const transmatrix& V) { + for(int t=0; ttype; t++) + if(c->move(t) && c->move(t) < c) + addradar(V*get_corner_position(c, t%c->type), V*get_corner_position(c, (t+1)%c->type), gridcolor(c, c->move(t))); + } + void draw_grid_at(cell *c, const transmatrix& V) { dynamicval lw(vid.linewidth, vid.linewidth); @@ -6285,7 +6305,9 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { if(vid.grid || (c->land == laAsteroids && !(WDIM == 2 && GDIM == 3))) draw_grid_at(c, V); - if(onradar && WDIM == 2) addradar(V, ch, darkenedby(asciicol, darken), 0); + if(onradar && WDIM == 2 && GDIM == 3) addradar(V, ch, darkenedby(asciicol, darken), 0); + + if(WDIM == 2 && GDIM == 3) radar_grid(c, V); #endif if(!euclid) { @@ -6861,6 +6883,7 @@ void drawthemap() { if(DIM == 3) make_clipping_planes(); radarpoints.clear(); + radarlines.clear(); if(!(cmode & sm::NORMAL)) max_eu_dist = 0; callhooks(hooks_drawmap); diff --git a/hud.cpp b/hud.cpp index 6058c610..6f0c4eee 100644 --- a/hud.cpp +++ b/hud.cpp @@ -4,6 +4,7 @@ namespace hr { vector radarpoints; +vector radarlines; purehookset hooks_stats; @@ -396,19 +397,33 @@ void draw_radar(bool cornermode) { queueline(atscreenpos(cx+rad * r.h[0], cy - rad * r.h[2] * si + rad * r.h[1] * co, 0)*C0, atscreenpos(cx+rad*r.h[0], cy - rad*r.h[2] * si, 0)*C0, r.line, -1); } + auto locate = [&] (hyperpoint h) { + if(sph) + return point3(cx + (rad-10) * h[0], cy + (rad-10) * h[2] * si + (rad-10) * h[1] * co, +h[1] * si > h[2] * co ? 8 : 16); + else if(hyp) + return point3(cx + rad * h[0], cy + rad * h[1], 1/(1+h[3]) * cgi.scalefactor * current_display->radius / (inHighQual ? 10 : 6)); + else + return point3(cx + rad * h[0], cy + rad * h[1], rad * cgi.scalefactor / (max_eu_dist + cgi.scalefactor/4) * 0.8); + }; + + for(auto& r: radarlines) { + hyperpoint h1 = locate(r.h1); + hyperpoint h2 = locate(r.h2); + h1 = tC0(atscreenpos(h1[0], h1[1], 1)); + h2 = tC0(atscreenpos(h2[0], h2[1], 1)); + queueline(h1, h2, r.line, -1); + } + quickqueue(); glflush(); - - for(auto& r: radarpoints) + + for(auto& r: radarpoints) { if(d3) displaychr(int(cx + rad * r.h[0]), int(cy - rad * r.h[2] * si + rad * r.h[1] * co), 0, 8, r.glyph, r.color); - else if(sph) displaychr(int(cx + (rad-10) * r.h[0]), int(cy + (rad-10) * r.h[2] * si + (rad-10) * r.h[1] * co), 0, +r.h[1] * si > r.h[2] * co ? 8 : 16, r.glyph, r.color); - else if(hyp) { - int siz = 1/(1+r.h[3]) * cgi.scalefactor * current_display->radius / (inHighQual ? 10 : 6); - displaychr(int(cx + rad * r.h[0]), int(cy + rad * r.h[1]), 0, siz, r.glyph, r.color); - } else { - displaychr(int(cx + rad * r.h[0]), int(cy + rad * r.h[1]), 0, rad * cgi.scalefactor / (max_eu_dist + cgi.scalefactor/4) * 0.8, r.glyph, r.color); - } + hyperpoint h = locate(r.h); + displaychr(int(h[0]), int(h[1]), 0, int(h[2]), r.glyph, r.color); + } + } } void drawStats() { diff --git a/hyper.h b/hyper.h index 6d10d136..099f51da 100644 --- a/hyper.h +++ b/hyper.h @@ -1185,7 +1185,13 @@ struct radarpoint { color_t line; }; +struct radarline { + hyperpoint h1, h2; + color_t line; + }; + extern vector radarpoints; +extern vector radarlines; extern vector< function > screens;