From 5f33d6b51b60471e22ba43d48783cd1df56f1fd6 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 16 Sep 2020 13:51:21 +0200 Subject: [PATCH] drawing:: broken_projection as a separate function --- drawing.cpp | 145 ++++++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 67 deletions(-) diff --git a/drawing.cpp b/drawing.cpp index 8c03e6aa..10a1ad6f 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -1501,8 +1501,85 @@ EX namespace ods { #endif EX } +/** @brief render in a broken projection; return false if normal rendering is not applicable */ +bool broken_projection(dqi_poly& p0) { + int broken_coord = models::get_broken_coord(pmodel); + static bool in_broken = false; + if(broken_coord && !in_broken) { + + int zcoord = broken_coord; + int ycoord = 3 - zcoord; + + vector all; + for(int i=0; i v; + dqi_poly p = p0; + p.tab = &v; + p.offset = 0; + p.V.T = Id; + if(fail) { + dynamicval ib(in_broken, true); + ld part = ilerp(all[last_fail][0], all[last_fail+1][0], 0); + hyperpoint initial = normalize(lerp(all[last_fail], all[last_fail+1], 1 - (1-part) * .99)); + bool have_initial = true; + v.push_back(glhr::pointtogl(initial)); + last_fail++; + int at = last_fail; + do { + v.push_back(glhr::pointtogl(all[at])); + if(at == p0.cnt-1 && all[at] != all[0]) { + p.cnt = isize(v); p.draw(); v.clear(); at = 0; + have_initial = false; + } + int next = at+1; + if(next == p0.cnt) next = 0; + if(break_in(all[at], all[next])) { + ld part = ilerp(all[at][0], all[next][0], 0); + hyperpoint final = normalize(lerp(all[at], all[next], part * .99)); + v.push_back(glhr::pointtogl(final)); + if(have_initial) { + int max = 4 << vid.linequality; + if(final[0] * initial[0] > 0) { + for(int i=1; i<=max; i++) + v.push_back(glhr::pointtogl(lerp(final, initial, i * 1. / max))); + } + else { + hyperpoint end = Hypc; + end[ycoord] = final[ycoord] > 0 ? 1 : -1; + for(int i=1; i<=max; i++) + v.push_back(glhr::pointtogl(lerp(final, end, i * 1. / max))); + for(int i=1; i<=max; i++) + v.push_back(glhr::pointtogl(lerp(end, initial, i * 1. / max))); + } + } + p.cnt = isize(v); p.draw(); v.clear(); + initial = normalize(lerp(all[at], all[next], 1 - (1-part) * .99)); + have_initial = true; + v.push_back(glhr::pointtogl(initial)); + } + at = next; + } + while(at != last_fail); + return true; + } + } + return false; + } + void dqi_poly::draw() { if(flags & POLY_DEBUG) debug_this(); + if(debugflags & DF_VERTEX) { println(hlog, tie(V, offset, cnt, offset_texture, outline, linewidth, flags, intester, cache), (cell*) tinf); for(int i=0; i all; - for(int i=0; i v; - dqi_poly p = *this; - p.tab = &v; - p.offset = 0; - p.V.T = Id; - if(fail) { - dynamicval ib(in_broken, true); - ld part = ilerp(all[last_fail][0], all[last_fail+1][0], 0); - hyperpoint initial = normalize(lerp(all[last_fail], all[last_fail+1], 1 - (1-part) * .99)); - bool have_initial = true; - v.push_back(glhr::pointtogl(initial)); - last_fail++; - int at = last_fail; - do { - v.push_back(glhr::pointtogl(all[at])); - if(at == cnt-1 && all[at] != all[0]) { - p.cnt = isize(v); p.draw(); v.clear(); at = 0; - have_initial = false; - } - int next = at+1; - if(next == cnt) next = 0; - if(all[at][0] * all[next][0] <= 0 && (all[at][0] * all[next][zcoord] - all[next][0] * all[at][zcoord]) * (all[at][0] - all[next][0]) < 0) { - ld part = ilerp(all[at][0], all[next][0], 0); - if(part > .999 || part < .001) { in_broken = false; return; } - hyperpoint final = normalize(lerp(all[at], all[next], part * .99)); - v.push_back(glhr::pointtogl(final)); - if(have_initial) { - int max = 4 << vid.linequality; - if(final[0] * initial[0] > 0) { - for(int i=1; i<=max; i++) - v.push_back(glhr::pointtogl(lerp(final, initial, i * 1. / max))); - } - else { - hyperpoint end = Hypc; - end[ycoord] = final[ycoord] > 0 ? 1 : -1; - for(int i=1; i<=max; i++) - v.push_back(glhr::pointtogl(lerp(final, end, i * 1. / max))); - for(int i=1; i<=max; i++) - v.push_back(glhr::pointtogl(lerp(end, initial, i * 1. / max))); - } - } - p.cnt = isize(v); p.draw(); v.clear(); - initial = normalize(lerp(all[at], all[next], 1 - (1-part) * .99)); - have_initial = true; - v.push_back(glhr::pointtogl(initial)); - } - at = next; - } - while(at != last_fail); - return; - } - } + if(broken_projection(*this)) return; if(sphere && pmodel == mdTwoPoint && !in_twopoint) { #define MAX_PHASE 4