Sun, 26 Jan 2020 14:29:30 +0200
replaced matrix and vertex classes with glm
15
9e18ec63eec3
split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
14
diff
changeset
|
1 | #include "triangle.h" |
3 | 2 | |
13 | 3 | linetypes::Triangle::Triangle( |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
4 | const glm::vec3& point_1, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
5 | const glm::vec3& point_2, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
6 | const glm::vec3& point_3, |
3 | 7 | Color color_index) : |
13 | 8 | ColoredObject{color_index}, |
3 | 9 | points{point_1, point_2, point_3} |
10 | { | |
11 | } | |
12 | ||
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
13 | linetypes::Triangle::Triangle(const QVector<glm::vec3>& vertices, const Color color) : |
13 | 14 | ColoredObject{color}, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
15 | points{vertices[0], vertices[1], vertices[2]} |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
16 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
17 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
18 | |
13 | 19 | QVariant linetypes::Triangle::getProperty(const Property id) const |
3 | 20 | { |
21 | switch (id) | |
22 | { | |
23 | case Property::Point1: | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
24 | return QVariant::fromValue(points[0]); |
3 | 25 | case Property::Point2: |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
26 | return QVariant::fromValue(points[1]); |
3 | 27 | case Property::Point3: |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
28 | return QVariant::fromValue(points[2]); |
3 | 29 | default: |
13 | 30 | return ColoredObject::getProperty(id); |
3 | 31 | } |
32 | } | |
33 | ||
13 | 34 | auto linetypes::Triangle::setProperty(Property id, const QVariant& value) |
3 | 35 | -> SetPropertyResult |
36 | { | |
37 | switch (id) | |
38 | { | |
39 | case Property::Point1: | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
40 | points[0] = value.value<glm::vec3>(); |
3 | 41 | return SetPropertyResult::Success; |
42 | case Property::Point2: | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
43 | points[1] = value.value<glm::vec3>(); |
3 | 44 | return SetPropertyResult::Success; |
45 | case Property::Point3: | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
46 | points[2] = value.value<glm::vec3>(); |
3 | 47 | return SetPropertyResult::Success; |
48 | default: | |
13 | 49 | return ColoredObject::setProperty(id, value); |
3 | 50 | } |
51 | } | |
52 | ||
13 | 53 | QString linetypes::Triangle::textRepresentation() const |
6 | 54 | { |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
55 | return utility::format("%1 %2 %3", |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
56 | utility::vertexToStringParens(points[0]), |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
57 | utility::vertexToStringParens(points[1]), |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
58 | utility::vertexToStringParens(points[2])); |
6 | 59 | } |
21 | 60 | |
61 | void linetypes::Triangle::getPolygons( | |
62 | std::vector<gl::Polygon>& polygons, | |
63 | GetPolygonsContext* context) const | |
64 | { | |
65 | Q_UNUSED(context) | |
66 | polygons.push_back(gl::triangle( | |
67 | this->points[0], | |
68 | this->points[1], | |
69 | this->points[2], | |
70 | this->colorIndex, | |
26 | 71 | this->id)); |
21 | 72 | } |
26 | 73 | |
74 | void linetypes::Triangle::invert() | |
75 | { | |
76 | // 0 1 2 | |
77 | // -> 1 0 2 | |
78 | std::swap(this->points[0], this->points[1]); | |
79 | } |