src/linetypes/triangle.cpp

Wed, 18 Mar 2020 15:52:16 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 18 Mar 2020 15:52:16 +0200
changeset 83
b8bd338eb602
parent 81
62373840e33a
child 86
4bec0525ef1b
permissions
-rw-r--r--

refactor, added splitter

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
55a55a9ec2c2 Added lots of code
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::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
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 Color color_index) :
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
8 ColoredObject{color_index},
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 points{point_1, point_2, point_3}
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12
77
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
13 ldraw::Triangle::Triangle(const std::array<glm::vec3, 3>& vertices, const Color color) :
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
14 ColoredObject{color},
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
15 points{vertices[0], vertices[1], vertices[2]}
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
16 {
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
17 }
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
18
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
19 ldraw::Triangle::Triangle(const glm::vec3 (&vertices)[3], const Color color) :
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
20 ColoredObject{color},
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
21 points{vertices[0], vertices[1], vertices[2]}
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
22 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
23 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
24
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
25 QVariant ldraw::Triangle::getProperty(const Property id) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 switch (id)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 case Property::Point1:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
30 return QVariant::fromValue(points[0]);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 case Property::Point2:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
32 return QVariant::fromValue(points[1]);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 case Property::Point3:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
34 return QVariant::fromValue(points[2]);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 default:
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
36 return ColoredObject::getProperty(id);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
40 auto ldraw::Triangle::setProperty(Property id, const QVariant& value)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 -> SetPropertyResult
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 switch (id)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 case Property::Point1:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
46 points[0] = value.value<glm::vec3>();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 return SetPropertyResult::Success;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 case Property::Point2:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
49 points[1] = value.value<glm::vec3>();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 return SetPropertyResult::Success;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 case Property::Point3:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
52 points[2] = value.value<glm::vec3>();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 return SetPropertyResult::Success;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 default:
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
55 return ColoredObject::setProperty(id, value);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
59 QString ldraw::Triangle::textRepresentation() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
60 {
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
61 return utility::format("%1 %2 %3",
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
62 utility::vertexToStringParens(points[0]),
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
63 utility::vertexToStringParens(points[1]),
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 26
diff changeset
64 utility::vertexToStringParens(points[2]));
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
65 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
66
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
67 void ldraw::Triangle::getPolygons(
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
68 std::vector<gl::Polygon>& polygons,
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
69 GetPolygonsContext* context) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
70 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
71 Q_UNUSED(context)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
72 polygons.push_back(gl::triangle(
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
73 this->points[0],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
74 this->points[1],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
75 this->points[2],
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
76 this->colorIndex,
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
77 this->id));
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
78 }
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
79
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
80 void ldraw::Triangle::invert()
26
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
81 {
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
82 // 0 1 2
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
83 // -> 1 0 2
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
84 std::swap(this->points[0], this->points[1]);
3a9e761e4faa at least VAOs work now
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
85 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
86
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
87 int ldraw::Triangle::numPoints() const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
88 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
89 return 3;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
90 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
91
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
92 const glm::vec3& ldraw::Triangle::getPoint(int index) const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
93 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
94 if (index >= 0 and index < 3)
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
95 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
96 return this->points[index];
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
97 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
98 else
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
99 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
100 return ldraw::ColoredObject::getPoint(index);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
101 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
102 }

mercurial