diff --git a/simplex/include/mesh.h b/simplex/include/mesh.h index 392b416..c3dfd1f 100644 --- a/simplex/include/mesh.h +++ b/simplex/include/mesh.h @@ -121,8 +121,9 @@ Mesh joinCap(Mesh m, Mesh n) { return concat(join(m, n), concat(fill(m), fill(n))); } -Mesh<4> thicken(const Mesh<3> &m, float thickness) { - return joinCap(offset(m, glm::vec4(0, 0, 0, -thickness / 2)), offset(m, glm::vec4(0, 0, 0, thickness / 2))); +template +Mesh thicken(const Mesh &m, glm::vec4 width) { + return joinCap(m - width / 2.f, m + width / 2.f); } template @@ -149,4 +150,10 @@ Mesh operator/(Mesh m, float scl) { return scale(m, 1.f / scl); } template Mesh operator*(glm::mat4 mat, Mesh m) { return transform(m, mat); } +template +Mesh simplify(Mesh m) { + // todo remove redundant vertices and primitives + return Mesh({}, {}); +} + #endif //SIMPLEX_MESH_H diff --git a/simplex/include/solids.h b/simplex/include/solids.h index d389298..555fe7c 100644 --- a/simplex/include/solids.h +++ b/simplex/include/solids.h @@ -47,4 +47,23 @@ Mesh<4> tesseract() { rot_zw(T) * pair; } +Mesh<4> tesseract_frame(float width) { + Mesh<4> edge = tesseract() * glm::vec4(width, width, width, 1); + auto o = glm::vec3(1 - width); + + Mesh<4> set = (edge + glm::vec4(+o.x, +o.y, +o.z, 0)) + + (edge + glm::vec4(+o.x, +o.y, -o.z, 0)) + + (edge + glm::vec4(+o.x, -o.y, +o.z, 0)) + + (edge + glm::vec4(+o.x, -o.y, -o.z, 0)) + + (edge + glm::vec4(-o.x, +o.y, +o.z, 0)) + + (edge + glm::vec4(-o.x, +o.y, -o.z, 0)) + + (edge + glm::vec4(-o.x, -o.y, +o.z, 0)) + + (edge + glm::vec4(-o.x, -o.y, -o.z, 0)); + + return set + + rot_xw(T) * set + + rot_yw(T) * set + + rot_zw(T) * set; +} + #endif //SIMPLEX_SOLIDS_H diff --git a/simplex/src/main.cpp b/simplex/src/main.cpp index 22bdba6..3b57d9b 100644 --- a/simplex/src/main.cpp +++ b/simplex/src/main.cpp @@ -39,7 +39,7 @@ class GLApp : public App { bool DRAW_WIRE = true; void init() override { - mesh = tesseract(); + mesh = tesseract_frame(.125f); //region Uniforms matrices = { @@ -107,11 +107,11 @@ class GLApp : public App { float ratio = (float) width / height; matrices.model = glm::identity() * - rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 0, 1), getTime() / 3) * - rotor(glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 1, 0), getTime() / 3) * +// rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 0, 1), getTime() / 3) * +// rotor(glm::vec4(0, 1, 0, 0), glm::vec4(0, 0, 1, 0), getTime() / 3) * -// rotor(glm::vec4(1, 1, 1, 0), glm::vec4(0, 0, 0, 1), getTime() / 3) * -// rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 1, 0), getTime() / 3) * + rotor(glm::vec4(1, 1, 1, 0), glm::vec4(0, 0, 0, 1), getTime() / 3) * + rotor(glm::vec4(1, 0, 0, 0), glm::vec4(0, 0, 1, 0), getTime() / 3) * 1.f; // matrices.offset = glm::vec4(0,0,0,sin(getTime() / 2));