-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample3.cpp
More file actions
112 lines (85 loc) · 3.33 KB
/
example3.cpp
File metadata and controls
112 lines (85 loc) · 3.33 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "bsptree.hpp"
#include "stl.hpp"
#include <boost/qvm/vec.hpp>
#include <boost/qvm/vec_operations.hpp>
#include <boost/qvm/mat_operations.hpp>
#include <boost/qvm/map_vec_mat.hpp>
#include <boost/qvm/swizzle.hpp>
#include <boost/qvm/vec_mat_operations.hpp>
#include <boost/qvm/mat.hpp>
#include <vector>
// this example demonstrates some other features of the library
using namespace boost::qvm;
struct Vertex
{
vec<float, 3> pos;
};
namespace bsp
{
template <> struct vertex_traits<Vertex>
{
typedef vec<float, 3> position_type;
static const position_type & getPosition(const Vertex & v)
{
return v.pos;
}
static Vertex getInterpolatedVertex(const Vertex & a, const Vertex & b, float i)
{
return { a.pos*(1-i) + b.pos*i };
}
// because we use the transform functionality, we need to add this
// function to the trait
static void transform(Vertex & v, const boost::qvm::mat<float, 4, 4> & m)
{
boost::qvm::vec<float, 4> pp = boost::qvm::XYZ1(v.pos);
pp = m * pp;
pp /= boost::qvm::W(pp);
v.pos = boost::qvm::XYZ(pp);
}
};
}
int main()
{
// Example 3
std::vector<Vertex> v3 {
{0, 0, 1},{1, 0, 1},{1, 1, 1}, {0, 0, 1}, {1, 1, 1}, {0, 1, 1},
{0, 0, 0},{1, 1, 0},{1, 0, 0}, {0, 0, 0}, {0, 1, 0}, {1, 1, 0},
{0, 1, 0},{1, 1, 1},{1, 1, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1},
{0, 0, 0},{1, 0, 0},{1, 0, 1}, {0, 0, 0}, {1, 0, 1}, {0, 0, 1},
{1, 0, 0},{1, 1, 0},{1, 1, 1}, {1, 0, 0}, {1, 1, 1}, {1, 0, 1},
{0, 0, 0},{0, 1, 1},{0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1},
};
std::vector<Vertex> v1 {
// 0 1 2 3 4 5 6 7
{0, 0, 1}, {1, 0, 1}, {1, 2, 1}, {0, 2, 1}, {0, 0, 0}, {1, 0, 0}, {0, 2, 0}, {1, 2, 0}
// {0, 0, 1},{1, 0, 1},{1, 2, 1}, {0, 0, 1}, {1, 2, 1}, {0, 2, 1},
// {0, 0, 0},{1, 2, 0},{1, 0, 0}, {0, 0, 0}, {0, 2, 0}, {1, 2, 0},
// {0, 2, 0},{1, 2, 1},{1, 2, 0}, {0, 2, 0}, {0, 2, 1}, {1, 2, 1},
// {0, 0, 0},{1, 0, 0},{1, 0, 1}, {0, 0, 0}, {1, 0, 1}, {0, 0, 1},
// {1, 0, 0},{1, 2, 0},{1, 2, 1}, {1, 0, 0}, {1, 2, 1}, {1, 0, 1},
// {0, 0, 0},{0, 2, 1},{0, 2, 0}, {0, 0, 0}, {0, 0, 1}, {0, 2, 1},
};
std::vector<uint16_t> i1 {
0, 1, 2, 0, 2, 3,
4, 7, 5, 4, 6, 7,
6, 2, 7, 6, 3, 2,
4, 5, 1, 4, 1, 0,
5, 7, 2, 5, 2, 1,
4, 3, 6, 4, 0, 3,
};
bsp::BspTree<std::vector<Vertex>, std::vector<uint16_t>> bsp1(std::move(v1), i1);
bsp::BspTree<std::vector<Vertex>, std::vector<uint16_t>> bsp3(std::move(v3));
auto a3 = bsp3.sort(vec<float, 3>{-5, 5, 5});
if (bsp3.isInside(vec<float, 3>{-5, 5, 5})) printf("oops 1\n");
if (!bsp3.isInside(vec<float, 3>{0.5, 0.5, 0.5})) printf("oops 3\n");
bsp3.transform(translation_mat(vec<double,3>{-0.5, -0.5, -0.5}));
bsp3.transform(rot_mat<4>(vec<double,3>{-0.5, -0.5, -0.5}, 1.0));
// bsp3.transform(translation_mat(vec<double,3>{1.5, 1.5, 1.5}));
if (bsp3.isInside(vec<float, 3>{1, 1, 0.5})) printf("oops 4\n");
if (!bsp3.isInside(vec<float, 3>{1, 1, 1.5})) printf("oops 5\n");
auto u = bsp1.unify(bsp1, bsp3);
// auto u = bsp1.intersect(bsp1, bsp3);
// auto u = bsp1.subtract(bsp1, bsp3);
// auto u = bsp1.subtract(bsp3, bsp1);
printSTL(u.getVertices(), u.sort(vec<float, 3>{-5, 5, 5}));
}