6 size_t NullShape::VertexCount() const {
10 void NullShape::Vertices(std::vector<glm::vec3> &out, const glm::vec3 &pos) const {
14 void NullShape::Normals(std::vector<glm::vec3> &out) const {
18 size_t NullShape::OutlineCount() const {
22 void NullShape::Outline(std::vector<glm::vec3> &out, const glm::vec3 &pos) const {
26 bool NullShape::Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const {
31 CuboidShape::CuboidShape(const AABB &b)
38 size_t CuboidShape::VertexCount() const {
42 void CuboidShape::Vertices(std::vector<glm::vec3> &out, const glm::vec3 &pos) const {
44 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z); // front
45 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
46 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
47 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
48 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z);
49 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
50 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); // back
51 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
52 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
53 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
54 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
55 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
56 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z); // top
57 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
58 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
59 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
60 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
61 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z);
62 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); // bottom
63 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
64 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
65 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
66 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
67 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
68 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z); // left
69 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
70 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
71 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
72 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
73 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
74 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z); // right
75 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
76 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
77 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
78 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
79 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z);
82 void CuboidShape::Normals(std::vector<glm::vec3> &out) const {
84 out.insert(out.end(), 6, glm::vec3( 0.0f, 0.0f, 1.0f)); // front
85 out.insert(out.end(), 6, glm::vec3( 0.0f, 0.0f, -1.0f)); // back
86 out.insert(out.end(), 6, glm::vec3( 0.0f, 1.0f, 0.0f)); // top
87 out.insert(out.end(), 6, glm::vec3( 0.0f, -1.0f, 0.0f)); // bottom
88 out.insert(out.end(), 6, glm::vec3(-1.0f, 0.0f, 0.0f)); // left
89 out.insert(out.end(), 6, glm::vec3( 1.0f, 0.0f, 0.0f)); // right
93 size_t CuboidShape::OutlineCount() const {
97 void CuboidShape::Outline(std::vector<glm::vec3> &out, const glm::vec3 &pos) const {
99 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z);
100 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
101 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
102 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
103 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
104 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
105 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
106 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z);
107 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.min.z);
108 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
109 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.min.z);
110 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
111 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.min.z);
112 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z);
113 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.min.z);
114 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
115 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
116 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
117 out.emplace_back(pos.x + bb.max.x, pos.y + bb.min.y, pos.z + bb.max.z);
118 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z);
119 out.emplace_back(pos.x + bb.max.x, pos.y + bb.max.y, pos.z + bb.max.z);
120 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
121 out.emplace_back(pos.x + bb.min.x, pos.y + bb.max.y, pos.z + bb.max.z);
122 out.emplace_back(pos.x + bb.min.x, pos.y + bb.min.y, pos.z + bb.max.z);
125 bool CuboidShape::Intersects(const Ray &ray, const glm::mat4 &M, float &dist, glm::vec3 &normal) const {
126 return Intersection(ray, bb, M, &dist, &normal);
130 StairShape::StairShape(const AABB &bb, const glm::vec2 &clip)
131 : top({ { clip.x, clip.y, bb.min.z }, bb.max })
132 , bot({ bb.min, { bb.max.x, clip.y, bb.max.z } }) {
137 size_t StairShape::VertexCount() const {
141 void StairShape::Vertices(std::vector<glm::vec3> &out, const glm::vec3 &pos) const {
143 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.max.z); // front, upper
144 out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.max.z);
145 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z);
146 out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.max.z);
147 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.max.z);
148 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z);
149 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z); // front, lower
150 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
151 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
152 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
153 out.emplace_back(pos.x + bot.max.x, pos.y + bot.max.y, pos.z + bot.max.z);
154 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
155 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.min.z); // back, upper
156 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z);
157 out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.min.z);
158 out.emplace_back(pos.x + top.max.x, pos.y + top.min.y, pos.z + top.min.z);
159 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z);
160 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z);
161 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // back, lower
162 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
163 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
164 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
165 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
166 out.emplace_back(pos.x + bot.max.x, pos.y + bot.max.y, pos.z + bot.min.z);
167 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z); // top, upper
168 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z);
169 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z);
170 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z);
171 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z);
172 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.max.z);
173 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); // top, lower
174 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
175 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
176 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
177 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
178 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
179 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // bottom
180 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
181 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
182 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
183 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
184 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
185 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.min.z); // left, upper
186 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.max.z);
187 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z);
188 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.min.z);
189 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + top.max.z);
190 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + top.max.z);
191 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // left, lower
192 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
193 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
194 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
195 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
196 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
197 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z); // right
198 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z);
199 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
200 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
201 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.min.z);
202 out.emplace_back(pos.x + top.max.x, pos.y + top.max.y, pos.z + top.max.z);
205 void StairShape::Normals(std::vector<glm::vec3> &out) const {
207 out.insert(out.end(), 12, glm::vec3( 0.0f, 0.0f, 1.0f)); // front, x2
208 out.insert(out.end(), 12, glm::vec3( 0.0f, 0.0f, -1.0f)); // back, x2
209 out.insert(out.end(), 12, glm::vec3( 0.0f, 1.0f, 0.0f)); // top, x2
210 out.insert(out.end(), 6, glm::vec3( 0.0f, -1.0f, 0.0f)); // bottom
211 out.insert(out.end(), 12, glm::vec3(-1.0f, 0.0f, 0.0f)); // left, x2
212 out.insert(out.end(), 6, glm::vec3( 1.0f, 0.0f, 0.0f)); // right
216 size_t StairShape::OutlineCount() const {
220 void StairShape::Outline(std::vector<glm::vec3> &out, const glm::vec3 &pos) const {
222 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // bottom
223 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
224 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
225 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
226 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
227 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
228 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
229 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z);
230 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z); // middle
231 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
232 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
233 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
234 out.emplace_back(pos.x + top.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
235 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
236 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
237 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
238 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.min.z); // top
239 out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.min.z);
240 out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.min.z);
241 out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.max.z);
242 out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.max.z);
243 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.max.z);
244 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.max.z);
245 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.min.z);
246 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.min.z); // verticals, ltr/btf
247 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.min.z);
248 out.emplace_back(pos.x + bot.min.x, pos.y + bot.min.y, pos.z + bot.max.z);
249 out.emplace_back(pos.x + bot.min.x, pos.y + bot.max.y, pos.z + bot.max.z);
250 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + bot.min.z);
251 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.min.z);
252 out.emplace_back(pos.x + top.min.x, pos.y + top.min.y, pos.z + bot.max.z);
253 out.emplace_back(pos.x + top.min.x, pos.y + top.max.y, pos.z + bot.max.z);
254 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.min.z);
255 out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.min.z);
256 out.emplace_back(pos.x + bot.max.x, pos.y + bot.min.y, pos.z + bot.max.z);
257 out.emplace_back(pos.x + bot.max.x, pos.y + top.max.y, pos.z + bot.max.z);
260 bool StairShape::Intersects(const Ray &ray, const glm::mat4 &M, float &dist, glm::vec3 &norm) const {
261 float top_dist, bot_dist;
262 glm::vec3 top_norm, bot_norm;
263 bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm);
264 bool bot_hit = Intersection(ray, bot, M, &bot_dist, &bot_norm);
268 if (top_dist < bot_dist) {
282 } else if (bot_hit) {