-
Notifications
You must be signed in to change notification settings - Fork 6
/
rules.h
50 lines (40 loc) · 1.68 KB
/
rules.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "polyhedron/glm_ext/glm_extensions.h"
#include "polyhedron/io/stl/stl_import.h"
#include <tuple>
#include <vector>
#include <array>
#include "checks.h"
#include "xml_config.h"
struct build_stl_cube {
static std::array<stl::face, 12> mesh(const glm::vec3 &pos, const glm::vec3 cube_size) {
auto get_corners = [=](const glm::vec3 &size) {
std::array<glm::vec3, 8> arr = {
glm::vec3(pos.x - size.x/2, pos.y - size.y/2, pos.z - size.z/2),
glm::vec3(pos.x + size.x/2, pos.y - size.y/2, pos.z - size.z/2),
glm::vec3(pos.x + size.x/2, pos.y + size.y/2, pos.z - size.z/2),
glm::vec3(pos.x - size.x/2, pos.y + size.y/2, pos.z - size.z/2),
glm::vec3(pos.x - size.x/2, pos.y - size.y/2, pos.z + size.z/2),
glm::vec3(pos.x + size.x/2, pos.y - size.y/2, pos.z + size.z/2),
glm::vec3(pos.x + size.x/2, pos.y + size.y/2, pos.z + size.z/2),
glm::vec3(pos.x - size.x/2, pos.y + size.y/2, pos.z + size.z/2)
};
return arr;
};
std::array<glm::vec3, 8> c = get_corners(cube_size);
return {
stl::face(c[1], c[0], c[3] ),
stl::face(c[3], c[2], c[1] ),
stl::face(c[5], c[1], c[2] ),
stl::face(c[2], c[6], c[5] ),
stl::face(c[5], c[6], c[7] ),
stl::face(c[7], c[4], c[5] ),
stl::face(c[3], c[0], c[4] ),
stl::face(c[4], c[7], c[3] ),
stl::face(c[6], c[2], c[3] ),
stl::face(c[3], c[7], c[6] ),
stl::face(c[0], c[1], c[5] ),
stl::face(c[5], c[4], c[0] )
};
}
};