src/linetypes/quadrilateral.cpp

Fri, 31 Jan 2020 00:25:35 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 31 Jan 2020 00:25:35 +0200
changeset 36
bbb901b97404
parent 35
98906a94732f
child 77
028798a72591
permissions
-rw-r--r--

added render style storage

15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "quadrilateral.h"
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
3 ldraw::Quadrilateral::Quadrilateral(
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,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
7 const glm::vec3& point_4,
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 Color color_index) :
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 ColoredObject{color_index},
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 points{point_1, point_2, point_3, point_4}
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 }
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
14 ldraw::Quadrilateral::Quadrilateral(const QVector<glm::vec3>& vertices, const Color color) :
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 ColoredObject{color},
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 points{vertices[0], vertices[1], vertices[2], vertices[3]}
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 }
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
20 QVariant ldraw::Quadrilateral::getProperty(const Property id) const
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 switch (id)
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 case Property::Point1:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
25 return QVariant::fromValue(points[0]);
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 case Property::Point2:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
27 return QVariant::fromValue(points[1]);
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 case Property::Point3:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
29 return QVariant::fromValue(points[2]);
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 case Property::Point4:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
31 return QVariant::fromValue(points[3]);
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 default:
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 return ColoredObject::getProperty(id);
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 }
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 }
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
37 auto ldraw::Quadrilateral::setProperty(
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 const Property id,
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 const QVariant& value)
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 -> SetPropertyResult
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 switch (id)
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 case Property::Point1:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
45 points[0] = value.value<glm::vec3>();
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 return SetPropertyResult::Success;
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 case Property::Point2:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
48 points[1] = value.value<glm::vec3>();
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 return SetPropertyResult::Success;
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 case Property::Point3:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
51 points[2] = value.value<glm::vec3>();
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 return SetPropertyResult::Success;
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 case Property::Point4:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
54 points[3] = value.value<glm::vec3>();
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 return SetPropertyResult::Success;
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 default:
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 return ColoredObject::setProperty(id, value);
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 }
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 }
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
61 QString ldraw::Quadrilateral::textRepresentation() const
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 {
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 return utility::format("%1 %2 %3 %4",
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
64 utility::vertexToStringParens(points[0]),
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
65 utility::vertexToStringParens(points[1]),
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
66 utility::vertexToStringParens(points[2]),
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
67 utility::vertexToStringParens(points[3]));
15
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
69
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
70 void ldraw::Quadrilateral::getPolygons(
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
71 std::vector<gl::Polygon>& polygons,
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
72 GetPolygonsContext* context) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
73 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
74 Q_UNUSED(context)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
75 polygons.push_back(gl::quadrilateral(
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
76 this->points[0],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
77 this->points[1],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
78 this->points[2],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
79 this->points[3],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
80 this->colorIndex,
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
81 this->id));
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
82 }
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
83
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
84 void ldraw::Quadrilateral::invert()
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
85 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
86 // 0 1 2 3
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
87 // -> 2 1 0 3
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
88 std::swap(this->points[0], this->points[2]);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
89 }

mercurial