-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoxWireFrame.cpp
83 lines (72 loc) · 1.57 KB
/
BoxWireFrame.cpp
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
#include "BoxWireFrame.h"
#include <QVector>
BoxWireFrame::BoxWireFrame(Node *parent) : Mesh(parent)
{
setType("Box");
_isWireFrame = true;
}
BoxWireFrame::~BoxWireFrame()
{
}
void BoxWireFrame::init()
{
Mesh::init();
QVector<float> normals = {
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0,
0.0, 1.0, 0.0
};
setNormals(normals);
setFromMinMax(QVector3D(-0.5, -0.5, -0.5), QVector3D(0.5, 0.5, 0.5));
QVector<int> faces = {
0, 1, 1, 2, 2, 3, 3, 0,
4, 5, 5, 6, 6, 7, 7, 4,
0, 4, 1, 5, 2, 6, 3, 7
};
setFaces(faces);
}
void BoxWireFrame::setFromMinMax(QVector3D const& min, QVector3D const&max)
{
_min = min;
_max = max;
_setFromMinMax();
}
void BoxWireFrame::setMin(const QVector3D &min)
{
_min = min;
_setFromMinMax();
}
void BoxWireFrame::setMax(const QVector3D &max)
{
_max = max;
_setFromMinMax();
}
const QVector3D &BoxWireFrame::min() const
{
return _min;
}
const QVector3D &BoxWireFrame::max() const
{
return _max;
}
void BoxWireFrame::_setFromMinMax()
{
QVector<float> vertices = {
// Bottom
_min.x(), _min.y(), _min.z(),
_max.x(), _min.y(), _min.z(),
_max.x(), _min.y(), _max.z(),
_min.x(), _min.y(), _max.z(),
// Top
_min.x(), _max.y(), _min.z(),
_max.x(), _max.y(), _min.z(),
_max.x(), _max.y(), _max.z(),
_min.x(), _max.y(), _max.z(),
};
setVertices(vertices);
}