1 |
c137512e
|
Oto Šťáva
|
#include "element.hpp"
|
2 |
|
|
|
3 |
|
|
const int Element::DATA_COUNT_FOR_VERTEX = 7;
|
4 |
|
|
const int Element::TRAJECTORY = 0;
|
5 |
|
|
const int Element::SPHERE = 1;
|
6 |
|
|
const int Element::SPHERE_FIXED = 2;
|
7 |
|
|
const int Element::ARROW = 3;
|
8 |
|
|
const int Element::ARROW_SPECIAL = 4;
|
9 |
|
|
const int Element::WALL = 5;
|
10 |
|
|
|
11 |
|
|
Element::Element(const int category)
|
12 |
|
|
{
|
13 |
|
|
this->category = category;
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
const float *Element::getData() const
|
17 |
|
|
{
|
18 |
|
|
return data.data();
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
int Element::dataCount() const
|
22 |
|
|
{
|
23 |
|
|
return data.size();
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
int Element::vertexCount() const
|
27 |
|
|
{
|
28 |
|
|
return dataCount() / DATA_COUNT_FOR_VERTEX;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
void Element::addVertex(const QVector3D &v, const QVector3D &n)
|
32 |
|
|
{
|
33 |
|
|
data.insert(data.end(), {v.x(), v.y(), v.z(), n.x(), n.y(), n.z(), (float) category});
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
void Element::addTetragon(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &d)
|
37 |
|
|
{
|
38 |
|
|
QVector3D n = normal(a, d, b);
|
39 |
|
|
addTriangleWithNormal(a, d, b, n);
|
40 |
|
|
addTriangleWithNormal(c, b, d, n);
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
void Element::addTriangle(const QVector3D &a, const QVector3D &b, const QVector3D &c)
|
44 |
|
|
{
|
45 |
|
|
addTriangleWithNormal(a, b, c, normal(a, b, c));
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
QVector3D Element::normal(const QVector3D &a, const QVector3D &b, const QVector3D &c)
|
49 |
|
|
{
|
50 |
|
|
return QVector3D::normal(b - a, c - a);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
void Element::clear()
|
54 |
|
|
{
|
55 |
|
|
data.clear();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
void Element::addTriangleWithNormal(const QVector3D &a, const QVector3D &b, const QVector3D &c, const QVector3D &n)
|
59 |
|
|
{
|
60 |
|
|
addVertex(a, n);
|
61 |
|
|
addVertex(b, n);
|
62 |
|
|
addVertex(c, n);
|
63 |
|
|
}
|