3d:: choice of end type for pipes

This commit is contained in:
Zeno Rogue 2022-07-14 11:28:24 +02:00
parent 6c4a53c001
commit 3b4571aa16
3 changed files with 25 additions and 7 deletions

View File

@ -1235,7 +1235,7 @@ void geometry_information::make_3d_models() {
finishshape();
}
hpcshape& geometry_information::generate_pipe(ld length, ld width) {
hpcshape& geometry_information::generate_pipe(ld length, ld width, ePipeEnd endtype) {
int id = int(length * 17 + .5) + int(157003 * log(width+.001));
if(shPipe.count(id)) return shPipe[id];
hpcshape& pipe = shPipe[id];
@ -1252,11 +1252,12 @@ hpcshape& geometry_information::generate_pipe(ld length, ld width) {
const int MAX_X = 8;
const int MAX_R = 20;
auto at = [&] (int i, int a, ld z = 1, ld s = 1) {
auto at = [&] (ld i, ld a, ld z = 1, ld s = 1) {
a += 0.5;
ld alpha = 360 * degree * a / MAX_R;
hpcpush(xpush(i * length / MAX_X) * cspin(1, 2, alpha) * ypush0(width*z));
#if CAP_GL
if(floor_textures) utt.tvertices.push_back(glhr::makevertex(0, 0.55 + s * 0.45 * sin(alpha), 0));
if(floor_textures) utt.tvertices.push_back(glhr::makevertex(0, 0.55 - s * 0.45 * sin(alpha), 0));
#endif
};
for(int i=0; i<MAX_X; i++) {
@ -1270,12 +1271,27 @@ hpcshape& geometry_information::generate_pipe(ld length, ld width) {
}
}
for(int a=0; a<MAX_R; a++) for(int x: {0, MAX_X}) {
if(endtype == ePipeEnd::sharp) for(int a=0; a<MAX_R; a++) for(int x: {0, MAX_X}) {
at(x, a, 1, 0);
at(x, a+1, 1, 0);
at(x, 0, 0, 0);
}
if(endtype == ePipeEnd::ball) for(int a=0; a<MAX_R; a++) for(int x=-MAX_R; x<MAX_R; x++) {
ld xb = x < 0 ? 0 : MAX_X;
ld mul = MAX_X * width/length * .9; // .9 to prevent Z-fighting
ld x0 = xb + mul * sin(x * 90 * degree / MAX_R);
ld x1 = xb + mul * sin((x+1) * 90 * degree / MAX_R);
ld z0 = cos(x * 90 * degree / MAX_R);
ld z1 = cos((x+1) * 90 * degree / MAX_R);
at(x0, a, z0, z0);
at(x0, a+1, z0, z0);
at(x1, a, z1, z1);
at(x1, a+1, z1, z1);
at(x1, a, z1, z1);
at(x0, a+1, z0, z0);
}
last->flags |= POLY_TRIANGLES | POLY_PRINTABLE;
finishshape();
extra_vertices();

View File

@ -142,6 +142,8 @@ struct subcellshape {
void compute_common();
};
enum class ePipeEnd {sharp, ball};
/** basic geometry parameters */
struct geometry_information {
@ -530,7 +532,7 @@ hpcshape
void require_usershapes() { if(usershape_state == usershape_changes) return; usershape_state = usershape_changes; prepare_usershapes(); }
int timestamp;
hpcshape& generate_pipe(ld length, ld width);
hpcshape& generate_pipe(ld length, ld width, ePipeEnd endtype = ePipeEnd::sharp);
map<string, unique_ptr<gi_extension>> ext;
};

View File

@ -3987,8 +3987,8 @@ EX void gridline(const shiftmatrix& V1, const hyperpoint h1, const shiftmatrix&
if(WDIM == 3 && fat_edges) {
shiftmatrix T = V1 * rgpushxto0(h1);
transmatrix S = rspintox(inverse_shift(T, V2) * h2);
transmatrix U = rspintoc(inverse_shift(T*S, shiftless(C0)), 2, 1) * cspin(1, 2, 180*degree);
auto& p = queuepoly(T * S * U, cgi.generate_pipe(d, vid.linewidth), col);
transmatrix U = rspintoc(inverse_shift(T*S, shiftless(C0)), 2, 1);
auto& p = queuepoly(T * S * U, cgi.generate_pipe(d, vid.linewidth, ePipeEnd::ball), col);
p.intester = xpush0(d/2);
return;
}