-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.cpp
More file actions
126 lines (116 loc) · 3.19 KB
/
Box.cpp
File metadata and controls
126 lines (116 loc) · 3.19 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "Box.h"
#include <QVector>
Box::Box(Node *parent) : Mesh(parent)
{
setType("Box");
}
Box::~Box()
{
}
void Box::init()
{
Mesh::init();
QVector<float> normals;
normals <<
// Front
0.0 << 0.0 << 1.0 <<
0.0 << 0.0 << 1.0 <<
0.0 << 0.0 << 1.0 <<
0.0 << 0.0 << 1.0 <<
// Face
0.0 << 0.0 << -1.0 <<
0.0 << 0.0 << -1.0 <<
0.0 << 0.0 << -1.0 <<
0.0 << 0.0 << -1.0 <<
// Left
-1.0 << 0.0 << 0.0 <<
-1.0 << 0.0 << 0.0 <<
-1.0 << 0.0 << 0.0 <<
-1.0 << 0.0 << 0.0 <<
// Right
1.0 << 0.0 << 0.0 <<
1.0 << 0.0 << 0.0 <<
1.0 << 0.0 << 0.0 <<
1.0 << 0.0 << 0.0 <<
// Bottom
0.0 << -1.0 << 0.0 <<
0.0 << -1.0 << 0.0 <<
0.0 << -1.0 << 0.0 <<
0.0 << -1.0 << 0.0 <<
// Top
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, 0, 0), QVector3D(0, 0, 0));
QVector<int> faces;
faces <<
0 << 1 << 2 << 0 << 2 << 3 <<
4 << 5 << 6 << 4 << 6 << 7 <<
8 << 9 << 10 << 8 << 10 << 11 <<
12 << 13 << 14 << 12 << 14 << 15 <<
16 << 17 << 18 << 16 << 18 << 19 <<
20 << 21 << 22 << 20 << 22 << 23;
setFaces(faces);
}
void Box::setFromMinMax(QVector3D const& min, QVector3D const&max)
{
_min = min;
_max = max;
_setFromMinMax();
}
void Box::setMin(const QVector3D &min)
{
_min = min;
_setFromMinMax();
}
void Box::setMax(const QVector3D &max)
{
_max = max;
_setFromMinMax();
}
const QVector3D &Box::min() const
{
return _min;
}
const QVector3D &Box::max() const
{
return _max;
}
void Box::_setFromMinMax()
{
QVector<float> vertices;
vertices <<
// Front
_min.x() << _min.y() << _min.z() <<
_max.x() << _min.y() << _min.z() <<
_max.x() << _max.y() << _min.z() <<
_min.x() << _max.y() << _min.z() <<
// Back
_min.x() << _min.y() << _max.z() <<
_max.x() << _min.y() << _max.z() <<
_max.x() << _max.y() << _max.z() <<
_min.x() << _max.y() << _max.z() <<
// Left
_min.x() << _min.y() << _min.z() <<
_min.x() << _max.y() << _min.z() <<
_min.x() << _max.y() << _max.z() <<
_min.x() << _min.y() << _max.z() <<
// Right
_max.x() << _min.y() << _min.z() <<
_max.x() << _max.y() << _min.z() <<
_max.x() << _max.y() << _max.z() <<
_max.x() << _min.y() << _max.z() <<
// 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);
}