]> git.localhorst.tv Git - blank.git/commitdiff
renamed Shape -> CollisionBounds
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 12 Oct 2015 14:18:01 +0000 (16:18 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 12 Oct 2015 14:18:01 +0000 (16:18 +0200)
et al

12 files changed:
src/app/app.cpp
src/model/CollisionBounds.hpp [new file with mode: 0644]
src/model/Shape.hpp [deleted file]
src/model/bounds.cpp [new file with mode: 0644]
src/model/bounds.hpp [new file with mode: 0644]
src/model/model.cpp
src/model/shape.cpp [deleted file]
src/model/shapes.hpp [deleted file]
src/ui/ui.cpp
src/world/BlockType.hpp
src/world/block.cpp
src/world/chunk.cpp

index 1e82cab998b789e6a9be2fc62723defc2e012128..4f2a6ecdfaad1ff6a7b4a49cb462aea382ef426c 100644 (file)
@@ -13,7 +13,7 @@
 #include "../graphics/Font.hpp"
 #include "../graphics/Texture.hpp"
 #include "../io/TokenStreamReader.hpp"
-#include "../model/shapes.hpp"
+#include "../model/bounds.hpp"
 #include "../world/BlockType.hpp"
 #include "../world/BlockTypeRegistry.hpp"
 #include "../world/Entity.hpp"
@@ -305,9 +305,9 @@ Assets::Assets(const AssetLoader &loader)
 
 namespace {
 
-CuboidShape block_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }});
-StairShape stair_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f });
-CuboidShape slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }});
+CuboidBounds block_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }});
+StairBounds stair_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f });
+CuboidBounds slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }});
 
 }
 
diff --git a/src/model/CollisionBounds.hpp b/src/model/CollisionBounds.hpp
new file mode 100644 (file)
index 0000000..15c4fe1
--- /dev/null
@@ -0,0 +1,103 @@
+#ifndef BLANK_MODEL_COLLISIONBOUNDS_HPP_
+#define BLANK_MODEL_COLLISIONBOUNDS_HPP_
+
+#include "../graphics/BlockMesh.hpp"
+#include "../graphics/EntityMesh.hpp"
+#include "../graphics/OutlineMesh.hpp"
+
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class AABB;
+class Ray;
+
+struct CollisionBounds {
+
+       /// the number of vertices (and normals) this shape has
+       size_t VertexCount() const noexcept { return vtx_pos.size(); }
+       /// the number of vertex indices this shape has
+       size_t VertexIndexCount() const noexcept { return vtx_idx.size(); }
+
+       const EntityMesh::Normal &VertexNormal(size_t idx) const noexcept { return vtx_nrm[idx]; }
+       EntityMesh::Normal VertexNormal(
+               size_t idx, const glm::mat4 &transform
+       ) const noexcept {
+               return EntityMesh::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f));
+       }
+
+       /// fill given buffers with this shape's elements with an
+       /// optional transform and offset
+       void Vertices(
+               EntityMesh::Buffer &out,
+               float tex_offset = 0.0f
+       ) const;
+       void Vertices(
+               EntityMesh::Buffer &out,
+               const glm::mat4 &transform,
+               float tex_offset = 0.0f,
+               EntityMesh::Index idx_offset = 0
+       ) const;
+       void Vertices(
+               BlockMesh::Buffer &out,
+               const glm::mat4 &transform,
+               float tex_offset = 0.0f,
+               BlockMesh::Index idx_offset = 0
+       ) const;
+
+       /// the number of vertices this shape's outline has
+       size_t OutlineCount() const { return out_pos.size(); }
+       /// the number of vertex indices this shape's outline has
+       size_t OutlineIndexCount() const { return out_idx.size(); }
+
+       /// fill given buffers with this shape's outline's elements
+       void Outline(OutlineMesh::Buffer &out) const;
+
+       /// Check if given ray would pass though this shape if it were
+       /// transformed with given matrix.
+       /// If true, dist and normal hold the intersection distance and
+       /// normal, otherwise their content is undefined.
+       virtual bool Intersects(
+               const Ray &,
+               const glm::mat4 &,
+               float &dist,
+               glm::vec3 &normal
+       ) const noexcept = 0;
+
+       /// Check for intersection with given OBB.
+       /// The OBB is defined by box and box_M, M is applied to the shape.
+       virtual bool Intersects(
+               const glm::mat4 &M,
+               const AABB &box,
+               const glm::mat4 &box_M,
+               float &depth,
+               glm::vec3 &normal
+       ) const noexcept = 0;
+
+protected:
+       void SetShape(
+               const EntityMesh::Positions &pos,
+               const EntityMesh::Normals &nrm,
+               const EntityMesh::Indices &idx);
+       void SetTexture(
+               const BlockMesh::TexCoords &tex_coords);
+       void SetOutline(
+               const OutlineMesh::Positions &pos,
+               const OutlineMesh::Indices &idx);
+
+private:
+       EntityMesh::Positions vtx_pos;
+       EntityMesh::Normals vtx_nrm;
+       EntityMesh::Indices vtx_idx;
+
+       BlockMesh::TexCoords vtx_tex_coords;
+
+       OutlineMesh::Positions out_pos;
+       OutlineMesh::Indices out_idx;
+
+};
+
+}
+
+#endif
diff --git a/src/model/Shape.hpp b/src/model/Shape.hpp
deleted file mode 100644 (file)
index d2e0695..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-#ifndef BLANK_MODEL_SHAPE_HPP_
-#define BLANK_MODEL_SHAPE_HPP_
-
-#include "../graphics/BlockMesh.hpp"
-#include "../graphics/EntityMesh.hpp"
-#include "../graphics/OutlineMesh.hpp"
-
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class AABB;
-class Ray;
-
-struct Shape {
-
-       /// the number of vertices (and normals) this shape has
-       size_t VertexCount() const noexcept { return vtx_pos.size(); }
-       /// the number of vertex indices this shape has
-       size_t VertexIndexCount() const noexcept { return vtx_idx.size(); }
-
-       const EntityMesh::Normal &VertexNormal(size_t idx) const noexcept { return vtx_nrm[idx]; }
-       EntityMesh::Normal VertexNormal(
-               size_t idx, const glm::mat4 &transform
-       ) const noexcept {
-               return EntityMesh::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f));
-       }
-
-       /// fill given buffers with this shape's elements with an
-       /// optional transform and offset
-       void Vertices(
-               EntityMesh::Buffer &out,
-               float tex_offset = 0.0f
-       ) const;
-       void Vertices(
-               EntityMesh::Buffer &out,
-               const glm::mat4 &transform,
-               float tex_offset = 0.0f,
-               EntityMesh::Index idx_offset = 0
-       ) const;
-       void Vertices(
-               BlockMesh::Buffer &out,
-               const glm::mat4 &transform,
-               float tex_offset = 0.0f,
-               BlockMesh::Index idx_offset = 0
-       ) const;
-
-       /// the number of vertices this shape's outline has
-       size_t OutlineCount() const { return out_pos.size(); }
-       /// the number of vertex indices this shape's outline has
-       size_t OutlineIndexCount() const { return out_idx.size(); }
-
-       /// fill given buffers with this shape's outline's elements
-       void Outline(OutlineMesh::Buffer &out) const;
-
-       /// Check if given ray would pass though this shape if it were
-       /// transformed with given matrix.
-       /// If true, dist and normal hold the intersection distance and
-       /// normal, otherwise their content is undefined.
-       virtual bool Intersects(
-               const Ray &,
-               const glm::mat4 &,
-               float &dist,
-               glm::vec3 &normal
-       ) const noexcept = 0;
-
-       /// Check for intersection with given OBB.
-       /// The OBB is defined by box and box_M, M is applied to the shape.
-       virtual bool Intersects(
-               const glm::mat4 &M,
-               const AABB &box,
-               const glm::mat4 &box_M,
-               float &depth,
-               glm::vec3 &normal
-       ) const noexcept = 0;
-
-protected:
-       void SetShape(
-               const EntityMesh::Positions &pos,
-               const EntityMesh::Normals &nrm,
-               const EntityMesh::Indices &idx);
-       void SetTexture(
-               const BlockMesh::TexCoords &tex_coords);
-       void SetOutline(
-               const OutlineMesh::Positions &pos,
-               const OutlineMesh::Indices &idx);
-
-private:
-       EntityMesh::Positions vtx_pos;
-       EntityMesh::Normals vtx_nrm;
-       EntityMesh::Indices vtx_idx;
-
-       BlockMesh::TexCoords vtx_tex_coords;
-
-       OutlineMesh::Positions out_pos;
-       OutlineMesh::Indices out_idx;
-
-};
-
-}
-
-#endif
diff --git a/src/model/bounds.cpp b/src/model/bounds.cpp
new file mode 100644 (file)
index 0000000..c1c04e1
--- /dev/null
@@ -0,0 +1,471 @@
+#include "bounds.hpp"
+#include "CollisionBounds.hpp"
+
+
+namespace blank {
+
+void CollisionBounds::Vertices(
+       EntityMesh::Buffer &out,
+       float tex_offset
+) const {
+       for (const auto &pos : vtx_pos) {
+               out.vertices.emplace_back(pos);
+       }
+       for (const auto &coord : vtx_tex_coords) {
+               out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
+       }
+       for (const auto &nrm : vtx_nrm) {
+               out.normals.emplace_back(nrm);
+       }
+       for (auto idx : vtx_idx) {
+               out.indices.emplace_back(idx);
+       }
+}
+
+void CollisionBounds::Vertices(
+       EntityMesh::Buffer &out,
+       const glm::mat4 &transform,
+       float tex_offset,
+       EntityMesh::Index idx_offset
+) const {
+       for (const auto &pos : vtx_pos) {
+               out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
+       }
+       for (const auto &coord : vtx_tex_coords) {
+               out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
+       }
+       for (const auto &nrm : vtx_nrm) {
+               out.normals.emplace_back(transform * glm::vec4(nrm, 0.0f));
+       }
+       for (auto idx : vtx_idx) {
+               out.indices.emplace_back(idx_offset + idx);
+       }
+}
+
+void CollisionBounds::Vertices(
+       BlockMesh::Buffer &out,
+       const glm::mat4 &transform,
+       float tex_offset,
+       BlockMesh::Index idx_offset
+) const {
+       for (const auto &pos : vtx_pos) {
+               out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
+       }
+       for (const auto &coord : vtx_tex_coords) {
+               out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
+       }
+       for (auto idx : vtx_idx) {
+               out.indices.emplace_back(idx_offset + idx);
+       }
+}
+
+void CollisionBounds::Outline(OutlineMesh::Buffer &out) const {
+       out.vertices.insert(out.vertices.end(), out_pos.begin(), out_pos.end());
+       out.indices.insert(out.indices.end(), out_idx.begin(), out_idx.end());
+}
+
+void CollisionBounds::SetShape(
+       const EntityMesh::Positions &pos,
+       const EntityMesh::Normals &nrm,
+       const EntityMesh::Indices &idx
+) {
+       vtx_pos = pos;
+       vtx_nrm = nrm;
+       vtx_idx = idx;
+}
+
+void CollisionBounds::SetTexture(
+       const BlockMesh::TexCoords &tex_coords
+) {
+       vtx_tex_coords = tex_coords;
+}
+
+void CollisionBounds::SetOutline(
+       const OutlineMesh::Positions &pos,
+       const OutlineMesh::Indices &idx
+) {
+       out_pos = pos;
+       out_idx = idx;
+}
+
+
+NullBounds::NullBounds()
+: CollisionBounds() {
+
+}
+
+bool NullBounds::Intersects(
+       const Ray &,
+       const glm::mat4 &,
+       float &, glm::vec3 &
+) const noexcept {
+       return false;
+}
+
+bool NullBounds::Intersects(
+       const glm::mat4 &,
+       const AABB &,
+       const glm::mat4 &,
+       float &,
+       glm::vec3 &
+) const noexcept {
+       return false;
+}
+
+
+CuboidBounds::CuboidBounds(const AABB &b)
+: CollisionBounds()
+, 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
+       });
+       SetTexture({
+               { 0.0f, 1.0f, 0.0f }, // front
+               { 1.0f, 1.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+               { 1.0f, 0.0f, 0.0f },
+               { 1.0f, 1.0f, 0.0f }, // back
+               { 1.0f, 0.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f }, // top
+               { 0.0f, 1.0f, 0.0f },
+               { 1.0f, 0.0f, 0.0f },
+               { 1.0f, 1.0f, 0.0f },
+               { 1.0f, 0.0f, 0.0f }, // bottom
+               { 0.0f, 0.0f, 0.0f },
+               { 1.0f, 1.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f }, // left
+               { 1.0f, 1.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+               { 1.0f, 0.0f, 0.0f },
+               { 1.0f, 1.0f, 0.0f }, // right
+               { 1.0f, 0.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+       });
+       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
+       });
+}
+
+bool CuboidBounds::Intersects(
+       const Ray &ray,
+       const glm::mat4 &M,
+       float &dist, glm::vec3 &normal
+) const noexcept {
+       return Intersection(ray, bb, M, &dist, &normal);
+}
+
+bool CuboidBounds::Intersects(
+       const glm::mat4 &M,
+       const AABB &box,
+       const glm::mat4 &box_M,
+       float &depth,
+       glm::vec3 &normal
+) const noexcept {
+       return Intersection(bb, M, box, box_M, depth, normal);
+}
+
+
+StairBounds::StairBounds(const AABB &bb, const glm::vec2 &clip)
+: CollisionBounds()
+, 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 } }) {
+       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
+       });
+       SetTexture({
+               { 0.0f, 0.5f, 0.0f }, // front, upper
+               { 1.0f, 0.5f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+               { 1.0f, 0.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f }, // front, lower
+               { 1.0f, 1.0f, 0.0f },
+               { 0.0f, 0.5f, 0.0f },
+               { 1.0f, 0.5f, 0.0f },
+               { 1.0f, 1.0f, 0.0f }, // back
+               { 1.0f, 0.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+               { 0.0f, 0.0f, 0.0f }, // top, upper
+               { 0.0f, 0.5f, 0.0f },
+               { 1.0f, 0.0f, 0.0f },
+               { 1.0f, 0.5f, 0.0f },
+               { 0.0f, 0.5f, 0.0f }, // top, lower
+               { 0.0f, 1.0f, 0.0f },
+               { 1.0f, 0.5f, 0.0f },
+               { 1.0f, 1.0f, 0.0f },
+               { 1.0f, 0.0f, 0.0f }, // bottom
+               { 0.0f, 0.0f, 0.0f },
+               { 1.0f, 1.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f },
+               { 0.0f, 0.5f, 0.0f }, // left, upper
+               { 0.5f, 0.5f, 0.0f },
+               { 0.0f, 0.0f, 0.0f },
+               { 0.5f, 0.0f, 0.0f },
+               { 0.0f, 1.0f, 0.0f }, // left, lower
+               { 1.0f, 1.0f, 0.0f },
+               { 0.0f, 0.5f, 0.0f },
+               { 1.0f, 0.5f, 0.0f },
+               { 1.0f, 0.5f, 0.0f }, // right, upper
+               { 1.0f, 0.0f, 0.0f },
+               { 0.5f, 0.5f, 0.0f },
+               { 0.5f, 0.0f, 0.0f },
+               { 1.0f, 1.0f, 0.0f }, // right, lower
+               { 1.0f, 0.5f, 0.0f },
+               { 0.0f, 1.0f, 0.0f },
+               { 0.0f, 0.5f, 0.0f },
+       });
+       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,
+       });
+}
+
+bool StairBounds::Intersects(
+       const Ray &ray,
+       const glm::mat4 &M,
+       float &dist,
+       glm::vec3 &norm
+) const noexcept {
+       float top_dist, bot_dist;
+       glm::vec3 top_norm, bot_norm;
+       bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm);
+       bool bot_hit = Intersection(ray, bot, M, &bot_dist, &bot_norm);
+
+       if (top_hit) {
+               if (bot_hit) {
+                       if (top_dist < bot_dist) {
+                               dist = top_dist;
+                               norm = top_norm;
+                               return true;
+                       } else {
+                               dist = bot_dist;
+                               norm = bot_norm;
+                               return true;
+                       }
+               } else {
+                       dist = top_dist;
+                       norm = top_norm;
+                       return true;
+               }
+       } else if (bot_hit) {
+               dist = bot_dist;
+               norm = bot_norm;
+               return true;
+       } else {
+               return false;
+       }
+}
+
+bool StairBounds::Intersects(
+       const glm::mat4 &M,
+       const AABB &box,
+       const glm::mat4 &box_M,
+       float &dist,
+       glm::vec3 &normal
+) const noexcept {
+       bool top_hit, bot_hit;
+       float top_dist, bot_dist;
+       glm::vec3 top_normal, bot_normal;
+
+       top_hit = Intersection(bot, M, box, box_M, top_dist, top_normal);
+       bot_hit = Intersection(top, M, box, box_M, bot_dist, bot_normal);
+
+       if (top_hit) {
+               if (bot_hit && bot_dist < top_dist) {
+                       dist = bot_dist;
+                       normal = bot_normal;
+                       return true;
+               } else {
+                       dist = top_dist;
+                       normal = top_normal;
+                       return true;
+               }
+               return true;
+       } else if (bot_hit) {
+               dist = bot_dist;
+               normal = bot_normal;
+               return true;
+       } else {
+               return false;
+       }
+}
+
+}
diff --git a/src/model/bounds.hpp b/src/model/bounds.hpp
new file mode 100644 (file)
index 0000000..05f8df1
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef BLANK_MODEL_BOUNDS_HPP_
+#define BLANK_MODEL_BOUNDS_HPP_
+
+#include "CollisionBounds.hpp"
+#include "geometry.hpp"
+
+#include <vector>
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class NullBounds
+: public CollisionBounds {
+
+public:
+       NullBounds();
+
+       bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
+       bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
+
+};
+
+
+class CuboidBounds
+: public CollisionBounds {
+
+public:
+       CuboidBounds(const AABB &bounds);
+
+       bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
+       bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
+
+private:
+       AABB bb;
+
+};
+
+
+class StairBounds
+: public CollisionBounds {
+
+public:
+       StairBounds(const AABB &bounds, const glm::vec2 &clip);
+
+       bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
+       bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
+
+private:
+       AABB top, bot;
+
+};
+
+}
+
+#endif
index 987d86c3be4fbcc655324f2da8d8bd6edc989741..22d2bedfc54211cbc68202ac04a0074a768829a6 100644 (file)
@@ -2,7 +2,7 @@
 #include "Instance.hpp"
 #include "Skeletons.hpp"
 
-#include "shapes.hpp"
+#include "bounds.hpp"
 #include "../graphics/DirectionalLighting.hpp"
 #include "../graphics/EntityMesh.hpp"
 
@@ -149,7 +149,7 @@ void Skeletons::Load() {
        meshes.resize(4);
        EntityMesh::Buffer buf;
        {
-               CuboidShape shape(skeletons[0]->Bounds());
+               CuboidBounds shape(skeletons[0]->Bounds());
                shape.Vertices(buf, 3.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
                buf.rgb_mods.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f });
@@ -157,7 +157,7 @@ void Skeletons::Load() {
                skeletons[0]->SetNodeMesh(&meshes[0]);
        }
        {
-               CuboidShape shape(skeletons[1]->Bounds());
+               CuboidBounds shape(skeletons[1]->Bounds());
                buf.Clear();
                shape.Vertices(buf, 0.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
@@ -166,7 +166,7 @@ void Skeletons::Load() {
                skeletons[1]->SetNodeMesh(&meshes[1]);
        }
        {
-               StairShape shape(skeletons[2]->Bounds(), { 0.4f, 0.4f });
+               StairBounds shape(skeletons[2]->Bounds(), { 0.4f, 0.4f });
                buf.Clear();
                shape.Vertices(buf, 1.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
@@ -175,7 +175,7 @@ void Skeletons::Load() {
                skeletons[2]->SetNodeMesh(&meshes[2]);
        }
        {
-               CuboidShape shape(skeletons[3]->Bounds());
+               CuboidBounds shape(skeletons[3]->Bounds());
                buf.Clear();
                shape.Vertices(buf, 2.0f);
                buf.hsl_mods.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
diff --git a/src/model/shape.cpp b/src/model/shape.cpp
deleted file mode 100644 (file)
index d69046e..0000000
+++ /dev/null
@@ -1,471 +0,0 @@
-#include "Shape.hpp"
-#include "shapes.hpp"
-
-
-namespace blank {
-
-void Shape::Vertices(
-       EntityMesh::Buffer &out,
-       float tex_offset
-) const {
-       for (const auto &pos : vtx_pos) {
-               out.vertices.emplace_back(pos);
-       }
-       for (const auto &coord : vtx_tex_coords) {
-               out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
-       }
-       for (const auto &nrm : vtx_nrm) {
-               out.normals.emplace_back(nrm);
-       }
-       for (auto idx : vtx_idx) {
-               out.indices.emplace_back(idx);
-       }
-}
-
-void Shape::Vertices(
-       EntityMesh::Buffer &out,
-       const glm::mat4 &transform,
-       float tex_offset,
-       EntityMesh::Index idx_offset
-) const {
-       for (const auto &pos : vtx_pos) {
-               out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
-       }
-       for (const auto &coord : vtx_tex_coords) {
-               out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
-       }
-       for (const auto &nrm : vtx_nrm) {
-               out.normals.emplace_back(transform * glm::vec4(nrm, 0.0f));
-       }
-       for (auto idx : vtx_idx) {
-               out.indices.emplace_back(idx_offset + idx);
-       }
-}
-
-void Shape::Vertices(
-       BlockMesh::Buffer &out,
-       const glm::mat4 &transform,
-       float tex_offset,
-       BlockMesh::Index idx_offset
-) const {
-       for (const auto &pos : vtx_pos) {
-               out.vertices.emplace_back(transform * glm::vec4(pos, 1.0f));
-       }
-       for (const auto &coord : vtx_tex_coords) {
-               out.tex_coords.emplace_back(coord.x, coord.y, coord.z + tex_offset);
-       }
-       for (auto idx : vtx_idx) {
-               out.indices.emplace_back(idx_offset + idx);
-       }
-}
-
-void Shape::Outline(OutlineMesh::Buffer &out) const {
-       out.vertices.insert(out.vertices.end(), out_pos.begin(), out_pos.end());
-       out.indices.insert(out.indices.end(), out_idx.begin(), out_idx.end());
-}
-
-void Shape::SetShape(
-       const EntityMesh::Positions &pos,
-       const EntityMesh::Normals &nrm,
-       const EntityMesh::Indices &idx
-) {
-       vtx_pos = pos;
-       vtx_nrm = nrm;
-       vtx_idx = idx;
-}
-
-void Shape::SetTexture(
-       const BlockMesh::TexCoords &tex_coords
-) {
-       vtx_tex_coords = tex_coords;
-}
-
-void Shape::SetOutline(
-       const OutlineMesh::Positions &pos,
-       const OutlineMesh::Indices &idx
-) {
-       out_pos = pos;
-       out_idx = idx;
-}
-
-
-NullShape::NullShape()
-: Shape() {
-
-}
-
-bool NullShape::Intersects(
-       const Ray &,
-       const glm::mat4 &,
-       float &, glm::vec3 &
-) const noexcept {
-       return false;
-}
-
-bool NullShape::Intersects(
-       const glm::mat4 &,
-       const AABB &,
-       const glm::mat4 &,
-       float &,
-       glm::vec3 &
-) const noexcept {
-       return false;
-}
-
-
-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
-       });
-       SetTexture({
-               { 0.0f, 1.0f, 0.0f }, // front
-               { 1.0f, 1.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-               { 1.0f, 0.0f, 0.0f },
-               { 1.0f, 1.0f, 0.0f }, // back
-               { 1.0f, 0.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f }, // top
-               { 0.0f, 1.0f, 0.0f },
-               { 1.0f, 0.0f, 0.0f },
-               { 1.0f, 1.0f, 0.0f },
-               { 1.0f, 0.0f, 0.0f }, // bottom
-               { 0.0f, 0.0f, 0.0f },
-               { 1.0f, 1.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f }, // left
-               { 1.0f, 1.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-               { 1.0f, 0.0f, 0.0f },
-               { 1.0f, 1.0f, 0.0f }, // right
-               { 1.0f, 0.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-       });
-       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
-       });
-}
-
-bool CuboidShape::Intersects(
-       const Ray &ray,
-       const glm::mat4 &M,
-       float &dist, glm::vec3 &normal
-) const noexcept {
-       return Intersection(ray, bb, M, &dist, &normal);
-}
-
-bool CuboidShape::Intersects(
-       const glm::mat4 &M,
-       const AABB &box,
-       const glm::mat4 &box_M,
-       float &depth,
-       glm::vec3 &normal
-) const noexcept {
-       return Intersection(bb, M, box, box_M, depth, normal);
-}
-
-
-StairShape::StairShape(const AABB &bb, const glm::vec2 &clip)
-: 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 } }) {
-       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
-       });
-       SetTexture({
-               { 0.0f, 0.5f, 0.0f }, // front, upper
-               { 1.0f, 0.5f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-               { 1.0f, 0.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f }, // front, lower
-               { 1.0f, 1.0f, 0.0f },
-               { 0.0f, 0.5f, 0.0f },
-               { 1.0f, 0.5f, 0.0f },
-               { 1.0f, 1.0f, 0.0f }, // back
-               { 1.0f, 0.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-               { 0.0f, 0.0f, 0.0f }, // top, upper
-               { 0.0f, 0.5f, 0.0f },
-               { 1.0f, 0.0f, 0.0f },
-               { 1.0f, 0.5f, 0.0f },
-               { 0.0f, 0.5f, 0.0f }, // top, lower
-               { 0.0f, 1.0f, 0.0f },
-               { 1.0f, 0.5f, 0.0f },
-               { 1.0f, 1.0f, 0.0f },
-               { 1.0f, 0.0f, 0.0f }, // bottom
-               { 0.0f, 0.0f, 0.0f },
-               { 1.0f, 1.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f },
-               { 0.0f, 0.5f, 0.0f }, // left, upper
-               { 0.5f, 0.5f, 0.0f },
-               { 0.0f, 0.0f, 0.0f },
-               { 0.5f, 0.0f, 0.0f },
-               { 0.0f, 1.0f, 0.0f }, // left, lower
-               { 1.0f, 1.0f, 0.0f },
-               { 0.0f, 0.5f, 0.0f },
-               { 1.0f, 0.5f, 0.0f },
-               { 1.0f, 0.5f, 0.0f }, // right, upper
-               { 1.0f, 0.0f, 0.0f },
-               { 0.5f, 0.5f, 0.0f },
-               { 0.5f, 0.0f, 0.0f },
-               { 1.0f, 1.0f, 0.0f }, // right, lower
-               { 1.0f, 0.5f, 0.0f },
-               { 0.0f, 1.0f, 0.0f },
-               { 0.0f, 0.5f, 0.0f },
-       });
-       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,
-       });
-}
-
-bool StairShape::Intersects(
-       const Ray &ray,
-       const glm::mat4 &M,
-       float &dist,
-       glm::vec3 &norm
-) const noexcept {
-       float top_dist, bot_dist;
-       glm::vec3 top_norm, bot_norm;
-       bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm);
-       bool bot_hit = Intersection(ray, bot, M, &bot_dist, &bot_norm);
-
-       if (top_hit) {
-               if (bot_hit) {
-                       if (top_dist < bot_dist) {
-                               dist = top_dist;
-                               norm = top_norm;
-                               return true;
-                       } else {
-                               dist = bot_dist;
-                               norm = bot_norm;
-                               return true;
-                       }
-               } else {
-                       dist = top_dist;
-                       norm = top_norm;
-                       return true;
-               }
-       } else if (bot_hit) {
-               dist = bot_dist;
-               norm = bot_norm;
-               return true;
-       } else {
-               return false;
-       }
-}
-
-bool StairShape::Intersects(
-       const glm::mat4 &M,
-       const AABB &box,
-       const glm::mat4 &box_M,
-       float &dist,
-       glm::vec3 &normal
-) const noexcept {
-       bool top_hit, bot_hit;
-       float top_dist, bot_dist;
-       glm::vec3 top_normal, bot_normal;
-
-       top_hit = Intersection(bot, M, box, box_M, top_dist, top_normal);
-       bot_hit = Intersection(top, M, box, box_M, bot_dist, bot_normal);
-
-       if (top_hit) {
-               if (bot_hit && bot_dist < top_dist) {
-                       dist = bot_dist;
-                       normal = bot_normal;
-                       return true;
-               } else {
-                       dist = top_dist;
-                       normal = top_normal;
-                       return true;
-               }
-               return true;
-       } else if (bot_hit) {
-               dist = bot_dist;
-               normal = bot_normal;
-               return true;
-       } else {
-               return false;
-       }
-}
-
-}
diff --git a/src/model/shapes.hpp b/src/model/shapes.hpp
deleted file mode 100644 (file)
index 4820530..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef BLANK_MODEL_SHAPES_HPP_
-#define BLANK_MODEL_SHAPES_HPP_
-
-#include "geometry.hpp"
-#include "Shape.hpp"
-
-#include <vector>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class NullShape
-: public Shape {
-
-public:
-       NullShape();
-
-       bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
-       bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
-
-};
-
-
-class CuboidShape
-: public Shape {
-
-public:
-       CuboidShape(const AABB &bounds);
-
-       bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
-       bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
-
-private:
-       AABB bb;
-
-};
-
-
-class StairShape
-: public Shape {
-
-public:
-       StairShape(const AABB &bounds, const glm::vec2 &clip);
-
-       bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
-       bool Intersects(const glm::mat4 &, const AABB &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override;
-
-private:
-       AABB top, bot;
-
-};
-
-}
-
-#endif
index c249ed47148a3a67d5f0e38cc85a91064e64634a..c7d8b2498c97a39e31b1ef75fa32002a96bc227f 100644 (file)
@@ -15,7 +15,7 @@
 #include "../graphics/Font.hpp"
 #include "../graphics/Viewport.hpp"
 #include "../io/TokenStreamReader.hpp"
-#include "../model/shapes.hpp"
+#include "../model/bounds.hpp"
 #include "../world/BlockLookup.hpp"
 #include "../world/World.hpp"
 #include "../world/WorldManipulator.hpp"
index 5fab9318dd2c44b5bd7066d048ca142b4dcc99eb..4208d94665d29ed56436b8662a406427f787b0b8 100644 (file)
@@ -5,7 +5,7 @@
 #include "../graphics/BlockMesh.hpp"
 #include "../graphics/EntityMesh.hpp"
 #include "../graphics/OutlineMesh.hpp"
-#include "../model/shapes.hpp"
+#include "../model/bounds.hpp"
 
 #include <glm/glm.hpp>
 
@@ -16,7 +16,7 @@ namespace blank {
 /// attributes of a type of block
 struct BlockType {
 
-       const Shape *shape;
+       const CollisionBounds *shape;
        float texture;
        glm::vec3 hsl_mod;
        glm::vec3 rgb_mod;
@@ -75,7 +75,7 @@ struct BlockType {
 
        BlockType() noexcept;
 
-       static const NullShape DEFAULT_SHAPE;
+       static const NullBounds DEFAULT_SHAPE;
 
        bool FaceFilled(const Block &block, Block::Face face) const noexcept {
                return fill[block.OrientedFace(face)];
index d2453cf534a705fe5435a030500ca3e3960f64db..727fcade04984bfcb8140dae48c4948a3580f2ce 100644 (file)
@@ -11,7 +11,7 @@
 
 namespace blank {
 
-const NullShape BlockType::DEFAULT_SHAPE;
+const NullBounds BlockType::DEFAULT_SHAPE;
 
 
 std::ostream &operator <<(std::ostream &out, const Block &block) {
index 14c3af5c9c9af0fdc6560a2718d3b118553db205..bd2d426f1005b8fc0088429117a49011ee7276c3 100644 (file)
@@ -435,7 +435,7 @@ BlockMesh::Buffer buf;
 void Chunk::Update(BlockMesh &model) noexcept {
        int vtx_count = 0, idx_count = 0;
        for (const auto &block : blocks) {
-               const Shape *shape = Type(block).shape;
+               const CollisionBounds *shape = Type(block).shape;
                vtx_count += shape->VertexCount();
                idx_count += shape->VertexIndexCount();
        }