1 #include "subfilereference.h" |
1 #include "subfilereference.h" |
2 #include "documentmanager.h" |
2 #include "documentmanager.h" |
3 #include "invert.h" |
3 #include "invert.h" |
4 |
4 |
5 linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation, |
5 linetypes::SubfileReference::SubfileReference(const glm::mat4& transformation, |
6 const QString& referenceName, |
6 const QString& referenceName, |
7 const Color color) : |
7 const Color color) : |
8 ColoredObject{color}, |
8 ColoredObject{color}, |
9 transformation{transformation}, |
9 transformation{transformation}, |
10 referenceName{referenceName} |
10 referenceName{referenceName} |
30 -> SetPropertyResult |
30 -> SetPropertyResult |
31 { |
31 { |
32 switch (property) |
32 switch (property) |
33 { |
33 { |
34 case Property::Transformation: |
34 case Property::Transformation: |
35 this->transformation = value.value<Matrix4x4>(); |
35 this->transformation = value.value<glm::mat4>(); |
36 return SetPropertyResult::Success; |
36 return SetPropertyResult::Success; |
37 case Property::ReferenceName: |
37 case Property::ReferenceName: |
38 this->referenceName = value.toString(); |
38 this->referenceName = value.toString(); |
39 return SetPropertyResult::Success; |
39 return SetPropertyResult::Success; |
40 default: |
40 default: |
42 } |
42 } |
43 } |
43 } |
44 |
44 |
45 QString linetypes::SubfileReference::textRepresentation() const |
45 QString linetypes::SubfileReference::textRepresentation() const |
46 { |
46 { |
47 return referenceName + " " + vertexToStringParens(this->position()); |
47 return referenceName + " " + utility::vertexToStringParens(this->position()); |
48 } |
48 } |
49 |
49 |
50 void linetypes::SubfileReference::getPolygons( |
50 void linetypes::SubfileReference::getPolygons( |
51 std::vector<gl::Polygon>& polygons, |
51 std::vector<gl::Polygon>& polygons, |
52 GetPolygonsContext* context) const |
52 GetPolygonsContext* context) const |
53 { |
53 { |
54 Model* model = this->resolve(context->documents); |
54 Model* model = this->resolve(context->documents); |
55 if (model != nullptr) |
55 if (model != nullptr) |
56 { |
56 { |
57 const bool needInverting = math::det(this->transformation) < 0; |
57 const bool needInverting = glm::determinant(this->transformation) < 0; |
58 const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); |
58 const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); |
59 polygons.reserve(polygons.size() + modelPolygons.size()); |
59 polygons.reserve(polygons.size() + modelPolygons.size()); |
60 for (gl::Polygon polygon : modelPolygons) |
60 for (gl::Polygon polygon : modelPolygons) |
61 { |
61 { |
62 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
62 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
63 { |
63 { |
64 polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation); |
64 glm::vec4 vertex {polygon.vertices[i], 1}; |
|
65 vertex = this->transformation * vertex; |
|
66 polygon.vertices[i] = vertex; |
65 } |
67 } |
66 if (needInverting != this->isInverted) |
68 if (needInverting != this->isInverted) |
67 { |
69 { |
68 gl::invert(polygon); |
70 gl::invert(polygon); |
69 } |
71 } |
75 polygons.push_back(polygon); |
77 polygons.push_back(polygon); |
76 } |
78 } |
77 } |
79 } |
78 } |
80 } |
79 |
81 |
80 Point3D linetypes::SubfileReference::position() const |
82 glm::vec3 linetypes::SubfileReference::position() const |
81 { |
83 { |
82 return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)}; |
84 return {this->transformation[3][0], this->transformation[3][1], this->transformation[3][2]}; |
83 } |
85 } |
84 |
86 |
85 void linetypes::SubfileReference::invert() |
87 void linetypes::SubfileReference::invert() |
86 { |
88 { |
87 this->isInverted = not this->isInverted; |
89 this->isInverted = not this->isInverted; |