src/linetypes/quadrilateral.cpp

Wed, 22 Jan 2020 01:17:11 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Jan 2020 01:17:11 +0200
changeset 27
c57fb7a5ffa3
parent 26
3a9e761e4faa
child 33
4c41bfe2ec6e
permissions
-rw-r--r--

commit work done on plugging vao to the gl renderer, renders nonsense for now

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
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 linetypes::Quadrilateral::Quadrilateral(
18
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
4 const Point3D& point_1,
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
5 const Point3D& point_2,
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
6 const Point3D& point_3,
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
7 const Point3D& 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
18
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
14 linetypes::Quadrilateral::Quadrilateral(const QVector<Point3D>& 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
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 QVariant linetypes::Quadrilateral::getProperty(const Property id) const
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:
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 return points[0];
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 case Property::Point2:
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 return points[1];
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 case Property::Point3:
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 return points[2];
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 case Property::Point4:
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 return points[3];
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
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 auto linetypes::Quadrilateral::setProperty(
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:
18
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
45 points[0] = value.value<Point3D>();
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:
18
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
48 points[1] = value.value<Point3D>();
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:
18
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
51 points[2] = value.value<Point3D>();
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:
18
Teemu Piippo <teemu@hecknology.net>
parents: 15
diff changeset
54 points[3] = value.value<Point3D>();
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
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 QString linetypes::Quadrilateral::textRepresentation() const
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",
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 vertexToStringParens(points[0]),
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 vertexToStringParens(points[1]),
9e18ec63eec3 split quadrilateral and triangle into their own source files
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 vertexToStringParens(points[2]),
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
67 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
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
70 void linetypes::Quadrilateral::getPolygons(
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
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
84 void linetypes::Quadrilateral::invert()
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