1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-09-05 03:47:58 +00:00

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();