X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fshape.cpp;h=8111258be6f83d5b2f7d24baeca0a96c99757e3d;hb=d2d3cb877984b97fafb97254f5005cbf4bcf47a6;hp=e8bd2e6f42a01bb8f8c728614bbd0fa7d5e59e35;hpb=5588a6a9b1e2fb6fee8f1166f855ef497e551a09;p=blank.git diff --git a/src/shape.cpp b/src/shape.cpp index e8bd2e6..8111258 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -3,27 +3,65 @@ namespace blank { -size_t NullShape::VertexCount() const { - return 0; +void Shape::Vertices( + Model::Positions &vertex, + Model::Normals &normal, + Model::Indices &index, + const Model::Position &elem_offset, + Model::Index idx_offset +) const { + for (const auto &pos : vtx_pos) { + vertex.emplace_back(elem_offset + pos); + } + normal.insert(normal.end(), vtx_nrm.begin(), vtx_nrm.end()); + for (auto idx : vtx_idx) { + index.emplace_back(idx_offset + idx); + } } -void NullShape::Vertices(std::vector &out, const glm::vec3 &pos) const { - +void Shape::Vertices( + Model::Positions &vertex, + Model::Normals &normal, + Model::Indices &index, + const glm::mat4 &transform, + Model::Index idx_offset +) const { + for (const auto &pos : vtx_pos) { + vertex.emplace_back(transform * glm::vec4(pos, 1.0f)); + } + for (const auto &nrm : vtx_nrm) { + normal.emplace_back(transform * glm::vec4(nrm, 0.0f)); + } + for (auto idx : vtx_idx) { + index.emplace_back(idx_offset + idx); + } } -void NullShape::Normals(std::vector &out) const { - +void Shape::Outline( + OutlineModel::Positions &vertex, + OutlineModel::Indices &index, + const OutlineModel::Position &elem_offset, + OutlineModel::Index idx_offset +) const { + for (const auto &pos : out_pos) { + vertex.emplace_back(elem_offset + pos); + } + for (auto idx : out_idx) { + index.emplace_back(idx_offset + idx); + } } -size_t NullShape::OutlineCount() const { - return 0; -} -void NullShape::Outline(std::vector &out, const glm::vec3 &pos) const { +NullShape::NullShape() +: Shape() { } -bool NullShape::Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const { +bool NullShape::Intersects( + const Ray &, + const glm::mat4 &, + float &, glm::vec3 & +) const { return false; } @@ -32,232 +70,217 @@ CuboidShape::CuboidShape(const AABB &b) : Shape() , bb(b) { bb.Adjust(); + SetShape({ + { bb.min.x, bb.min.y, bb.max.z }, // front + { bb.max.x, bb.min.y, bb.max.z }, + { bb.min.x, bb.max.y, bb.max.z }, + { bb.max.x, bb.max.y, bb.max.z }, + { bb.min.x, bb.min.y, bb.min.z }, // back + { bb.min.x, bb.max.y, bb.min.z }, + { bb.max.x, bb.min.y, bb.min.z }, + { bb.max.x, bb.max.y, bb.min.z }, + { bb.min.x, bb.max.y, bb.min.z }, // top + { bb.min.x, bb.max.y, bb.max.z }, + { bb.max.x, bb.max.y, bb.min.z }, + { bb.max.x, bb.max.y, bb.max.z }, + { bb.min.x, bb.min.y, bb.min.z }, // bottom + { bb.max.x, bb.min.y, bb.min.z }, + { bb.min.x, bb.min.y, bb.max.z }, + { bb.max.x, bb.min.y, bb.max.z }, + { bb.min.x, bb.min.y, bb.min.z }, // left + { bb.min.x, bb.min.y, bb.max.z }, + { bb.min.x, bb.max.y, bb.min.z }, + { bb.min.x, bb.max.y, bb.max.z }, + { bb.max.x, bb.min.y, bb.min.z }, // right + { bb.max.x, bb.max.y, bb.min.z }, + { bb.max.x, bb.min.y, bb.max.z }, + { bb.max.x, bb.max.y, bb.max.z }, + }, { + { 0.0f, 0.0f, 1.0f }, // front + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, -1.0f }, // back + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 1.0f, 0.0f }, // top + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, // bottom + { 0.0f, -1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, // left + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, // right + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + }, { + 0, 1, 2, 2, 1, 3, // front + 4, 5, 6, 6, 5, 7, // back + 8, 9, 10, 10, 9, 11, // top + 12, 13, 14, 14, 13, 15, // bottom + 16, 17, 18, 18, 17, 19, // left + 20, 21, 22, 22, 21, 23, // right + }); + SetOutline({ + { bb.min.x, bb.min.y, bb.min.z }, // back + { bb.max.x, bb.min.y, bb.min.z }, + { bb.min.x, bb.max.y, bb.min.z }, + { bb.max.x, bb.max.y, bb.min.z }, + { bb.min.x, bb.min.y, bb.max.z }, // front + { bb.max.x, bb.min.y, bb.max.z }, + { bb.min.x, bb.max.y, bb.max.z }, + { bb.max.x, bb.max.y, bb.max.z }, + }, { + 0, 1, 1, 3, 3, 2, 2, 0, // back + 4, 5, 5, 7, 7, 6, 6, 4, // front + 0, 4, 1, 5, 2, 6, 3, 7, // sides + }); } - -size_t CuboidShape::VertexCount() const { - return 36; -} - -void CuboidShape::Vertices(std::vector &out, const glm::vec3 &pos) const { - out.reserve(36); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); // front - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); // back - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); // top - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); // bottom - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); // left - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); // right - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z); -} - -void CuboidShape::Normals(std::vector &out) const { - out.reserve(36); - out.insert(out.end(), 6, glm::vec3( 0.0f, 0.0f, 1.0f)); // front - out.insert(out.end(), 6, glm::vec3( 0.0f, 0.0f, -1.0f)); // back - out.insert(out.end(), 6, glm::vec3( 0.0f, 1.0f, 0.0f)); // top - out.insert(out.end(), 6, glm::vec3( 0.0f, -1.0f, 0.0f)); // bottom - out.insert(out.end(), 6, glm::vec3(-1.0f, 0.0f, 0.0f)); // left - out.insert(out.end(), 6, glm::vec3( 1.0f, 0.0f, 0.0f)); // right -} - - -size_t CuboidShape::OutlineCount() const { - return 24; -} - -void CuboidShape::Outline(std::vector &out, const glm::vec3 &pos) const { - out.reserve(24); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z); - out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); -} - -bool CuboidShape::Intersects(const Ray &ray, const glm::mat4 &M, float &dist, glm::vec3 &normal) const { +bool CuboidShape::Intersects( + const Ray &ray, + const glm::mat4 &M, + float &dist, glm::vec3 &normal +) const { return Intersection(ray, bb, M, &dist, &normal); } StairShape::StairShape(const AABB &bb, const glm::vec2 &clip) -: top({ { clip.x, clip.y, bb.min.z }, bb.max }) +: Shape() +, top({ { bb.min.x, clip.y, bb.min.z }, { bb.max.x, bb.max.y, clip.x } }) , bot({ bb.min, { bb.max.x, clip.y, bb.max.z } }) { - -} - - -size_t StairShape::VertexCount() const { - return 60; -} - -void StairShape::Vertices(std::vector &out, const glm::vec3 &pos) const { - out.reserve(60); - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.max.z); // front, upper - out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); // front, lower - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.min.z); // back, upper - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // back, lower - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z); // top, upper - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); // top, lower - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // bottom - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.min.z); // left, upper - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // left, lower - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); // right - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z); - out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.max.z); -} - -void StairShape::Normals(std::vector &out) const { - out.reserve(60); - out.insert(out.end(), 12, glm::vec3( 0.0f, 0.0f, 1.0f)); // front, x2 - out.insert(out.end(), 12, glm::vec3( 0.0f, 0.0f, -1.0f)); // back, x2 - out.insert(out.end(), 12, glm::vec3( 0.0f, 1.0f, 0.0f)); // top, x2 - out.insert(out.end(), 6, glm::vec3( 0.0f, -1.0f, 0.0f)); // bottom - out.insert(out.end(), 12, glm::vec3(-1.0f, 0.0f, 0.0f)); // left, x2 - out.insert(out.end(), 6, glm::vec3( 1.0f, 0.0f, 0.0f)); // right + SetShape({ + { top.min.x, top.min.y, top.max.z }, // front, upper + { top.max.x, top.min.y, top.max.z }, + { top.min.x, top.max.y, top.max.z }, + { top.max.x, top.max.y, top.max.z }, + { bot.min.x, bot.min.y, bot.max.z }, // front, lower + { bot.max.x, bot.min.y, bot.max.z }, + { bot.min.x, bot.max.y, bot.max.z }, + { bot.max.x, bot.max.y, bot.max.z }, + { bot.min.x, bot.min.y, bot.min.z }, // back + { bot.min.x, top.max.y, bot.min.z }, + { top.max.x, bot.min.y, bot.min.z }, + { top.max.x, top.max.y, bot.min.z }, + { top.min.x, top.max.y, top.min.z }, // top, upper + { top.min.x, top.max.y, top.max.z }, + { top.max.x, top.max.y, top.min.z }, + { top.max.x, top.max.y, top.max.z }, + { bot.min.x, bot.max.y, top.max.z }, // top, lower + { bot.min.x, bot.max.y, bot.max.z }, + { bot.max.x, bot.max.y, top.max.z }, + { bot.max.x, bot.max.y, bot.max.z }, + { bot.min.x, bot.min.y, bot.min.z }, // bottom + { bot.max.x, bot.min.y, bot.min.z }, + { bot.min.x, bot.min.y, bot.max.z }, + { bot.max.x, bot.min.y, bot.max.z }, + { top.min.x, top.min.y, top.min.z }, // left, upper + { top.min.x, top.min.y, top.max.z }, + { top.min.x, top.max.y, top.min.z }, + { top.min.x, top.max.y, top.max.z }, + { bot.min.x, bot.min.y, bot.min.z }, // left, lower + { bot.min.x, bot.min.y, bot.max.z }, + { bot.min.x, bot.max.y, bot.min.z }, + { bot.min.x, bot.max.y, bot.max.z }, + { top.max.x, top.min.y, top.min.z }, // right, upper + { top.max.x, top.max.y, top.min.z }, + { top.max.x, top.min.y, top.max.z }, + { top.max.x, top.max.y, top.max.z }, + { bot.max.x, bot.min.y, bot.min.z }, // right, lower + { bot.max.x, bot.max.y, bot.min.z }, + { bot.max.x, bot.min.y, bot.max.z }, + { bot.max.x, bot.max.y, bot.max.z }, + }, { + { 0.0f, 0.0f, 1.0f }, // front x2 + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 0.0f, -1.0f }, // back + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 0.0f, -1.0f }, + { 0.0f, 1.0f, 0.0f }, // top x2 + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, // bottom + { 0.0f, -1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, + { 0.0f, -1.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, // left x2 + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { -1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, // right x2 + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, + }, { + 0, 1, 2, 2, 1, 3, // front, upper + 4, 5, 6, 6, 5, 7, // front, lower + 8, 9, 10, 10, 9, 11, // back + 12, 13, 14, 14, 13, 15, // top, upper + 16, 17, 18, 18, 17, 19, // top, lower + 20, 21, 22, 22, 21, 23, // bottom + 24, 25, 26, 26, 25, 27, // left, upper + 28, 29, 30, 30, 29, 31, // left, lower + 32, 33, 34, 34, 33, 35, // right, upper + 36, 37, 38, 38, 37, 39, // right, lower + }); + SetOutline({ + { bot.min.x, bot.min.y, bot.min.z }, // bottom + { bot.max.x, bot.min.y, bot.min.z }, + { bot.min.x, bot.min.y, bot.max.z }, + { bot.max.x, bot.min.y, bot.max.z }, + { bot.min.x, bot.max.y, top.max.z }, // middle + { bot.max.x, bot.max.y, top.max.z }, + { bot.min.x, bot.max.y, bot.max.z }, + { bot.max.x, bot.max.y, bot.max.z }, + { top.min.x, top.max.y, top.min.z }, // top + { top.max.x, top.max.y, top.min.z }, + { top.min.x, top.max.y, top.max.z }, + { top.max.x, top.max.y, top.max.z }, + }, { + 0, 1, 1, 3, 3, 2, 2, 0, // bottom + 4, 5, 5, 7, 7, 6, 6, 4, // middle + 8, 9, 9, 11, 11, 10, 10 , 8, // top + 0, 8, 4, 10, 2, 6, // verticals, btf + 1, 9, 5, 11, 3, 7, + // 5, 8, 7, 10, + // 1, 9, 3, 11, + }); } - -size_t StairShape::OutlineCount() const { - return 36; -} - -void StairShape::Outline(std::vector &out, const glm::vec3 &pos) const { - out.reserve(36); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // bottom - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); // middle - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.min.z); // top - out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // verticals, ltr/btf - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.min.z); - out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z); - out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.max.z); -} - -bool StairShape::Intersects(const Ray &ray, const glm::mat4 &M, float &dist, glm::vec3 &norm) const { +bool StairShape::Intersects( + const Ray &ray, + const glm::mat4 &M, + float &dist, + glm::vec3 &norm +) const { float top_dist, bot_dist; glm::vec3 top_norm, bot_norm; bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm); @@ -288,5 +311,4 @@ bool StairShape::Intersects(const Ray &ray, const glm::mat4 &M, float &dist, glm } } - }