src/linetypes/triangle.cpp

changeset 87
93ec4d630346
parent 86
4bec0525ef1b
child 132
488d0ba6070b
equal deleted inserted replaced
86:4bec0525ef1b 87:93ec4d630346
1 #include "triangle.h" 1 #include "triangle.h"
2
3 ldraw::Triangle::Triangle(
4 const glm::vec3& point_1,
5 const glm::vec3& point_2,
6 const glm::vec3& point_3,
7 Color color_index) :
8 ColoredObject{color_index},
9 points{point_1, point_2, point_3}
10 {
11 }
12
13 ldraw::Triangle::Triangle(const std::array<glm::vec3, 3>& vertices, const Color color) :
14 ColoredObject{color},
15 points{vertices[0], vertices[1], vertices[2]}
16 {
17 }
18
19 ldraw::Triangle::Triangle(const glm::vec3 (&vertices)[3], const Color color) :
20 ColoredObject{color},
21 points{vertices[0], vertices[1], vertices[2]}
22 {
23 }
24
25 QVariant ldraw::Triangle::getProperty(const Property id) const
26 {
27 switch (id)
28 {
29 case Property::Point0:
30 return QVariant::fromValue(points[0]);
31 case Property::Point1:
32 return QVariant::fromValue(points[1]);
33 case Property::Point2:
34 return QVariant::fromValue(points[2]);
35 default:
36 return ColoredObject::getProperty(id);
37 }
38 }
39
40 void ldraw::Triangle::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
41 {
42 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point0, {points[0] = value;})
43 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point1, {points[1] = value;})
44 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point2, {points[2] = value;})
45 ColoredObject::setProperty(result, pair);
46 }
47 2
48 QString ldraw::Triangle::textRepresentation() const 3 QString ldraw::Triangle::textRepresentation() const
49 { 4 {
50 return utility::format("%1 %2 %3", 5 return utility::format("%1 %2 %3",
51 utility::vertexToStringParens(points[0]), 6 utility::vertexToStringParens(points[0]),
61 polygons.push_back(gl::triangle( 16 polygons.push_back(gl::triangle(
62 this->points[0], 17 this->points[0],
63 this->points[1], 18 this->points[1],
64 this->points[2], 19 this->points[2],
65 this->colorIndex, 20 this->colorIndex,
66 this->id)); 21 this->id));
67 } 22 }
68 23
69 void ldraw::Triangle::invert() 24 void ldraw::Triangle::invert()
70 { 25 {
71 // 0 1 2 26 // 0 1 2
72 // -> 1 0 2 27 // -> 1 0 2
73 std::swap(this->points[0], this->points[1]); 28 std::swap(this->points[0], this->points[1]);
74 } 29 }
75
76 int ldraw::Triangle::numPoints() const
77 {
78 return 3;
79 }
80
81 const glm::vec3& ldraw::Triangle::getPoint(int index) const
82 {
83 if (index >= 0 and index < 3)
84 {
85 return this->points[index];
86 }
87 else
88 {
89 return ldraw::ColoredObject::getPoint(index);
90 }
91 }

mercurial