2 #include "CollisionBounds.hpp"
7 void CollisionBounds::Outline(PrimitiveMesh::Buffer &out) const {
8 out.vertices.insert(out.vertices.end(), out_pos.begin(), out_pos.end());
9 out.indices.insert(out.indices.end(), out_idx.begin(), out_idx.end());
12 void CollisionBounds::SetOutline(
13 const PrimitiveMesh::Positions &pos,
14 const PrimitiveMesh::Indices &idx
21 CuboidBounds::CuboidBounds(const AABB &b)
26 { bb.min.x, bb.min.y, bb.min.z }, // back
27 { bb.max.x, bb.min.y, bb.min.z },
28 { bb.min.x, bb.max.y, bb.min.z },
29 { bb.max.x, bb.max.y, bb.min.z },
30 { bb.min.x, bb.min.y, bb.max.z }, // front
31 { bb.max.x, bb.min.y, bb.max.z },
32 { bb.min.x, bb.max.y, bb.max.z },
33 { bb.max.x, bb.max.y, bb.max.z },
35 0, 1, 1, 3, 3, 2, 2, 0, // back
36 4, 5, 5, 7, 7, 6, 6, 4, // front
37 0, 4, 1, 5, 2, 6, 3, 7, // sides
41 bool CuboidBounds::Intersects(
44 float &dist, glm::vec3 &normal
46 return Intersection(ray, bb, M, &dist, &normal);
49 bool CuboidBounds::Intersects(
52 const glm::mat4 &box_M,
56 return Intersection(bb, M, box, box_M, depth, normal);
60 StairBounds::StairBounds(const AABB &bb, const glm::vec2 &clip)
62 , top({ { bb.min.x, clip.y, bb.min.z }, { bb.max.x, bb.max.y, clip.x } })
63 , bot({ bb.min, { bb.max.x, clip.y, bb.max.z } }) {
65 { bot.min.x, bot.min.y, bot.min.z }, // bottom
66 { bot.max.x, bot.min.y, bot.min.z },
67 { bot.min.x, bot.min.y, bot.max.z },
68 { bot.max.x, bot.min.y, bot.max.z },
69 { bot.min.x, bot.max.y, top.max.z }, // middle
70 { bot.max.x, bot.max.y, top.max.z },
71 { bot.min.x, bot.max.y, bot.max.z },
72 { bot.max.x, bot.max.y, bot.max.z },
73 { top.min.x, top.max.y, top.min.z }, // top
74 { top.max.x, top.max.y, top.min.z },
75 { top.min.x, top.max.y, top.max.z },
76 { top.max.x, top.max.y, top.max.z },
78 0, 1, 1, 3, 3, 2, 2, 0, // bottom
79 4, 5, 5, 7, 7, 6, 6, 4, // middle
80 8, 9, 9, 11, 11, 10, 10 , 8, // top
81 0, 8, 4, 10, 2, 6, // verticals, btf
86 bool StairBounds::Intersects(
92 float top_dist, bot_dist;
93 glm::vec3 top_norm, bot_norm;
94 bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm);
95 bool bot_hit = Intersection(ray, bot, M, &bot_dist, &bot_norm);
99 if (top_dist < bot_dist) {
113 } else if (bot_hit) {
122 bool StairBounds::Intersects(
125 const glm::mat4 &box_M,
129 bool top_hit, bot_hit;
130 float top_dist, bot_dist;
131 glm::vec3 top_normal, bot_normal;
133 top_hit = Intersection(bot, M, box, box_M, top_dist, top_normal);
134 bot_hit = Intersection(top, M, box, box_M, bot_dist, bot_normal);
137 if (bot_hit && bot_dist < top_dist) {
147 } else if (bot_hit) {