src/linetypes/subfilereference.cpp

changeset 26
3a9e761e4faa
parent 23
3387a84ddaba
child 33
4c41bfe2ec6e
--- a/src/linetypes/subfilereference.cpp	Sun Jan 19 14:25:57 2020 +0200
+++ b/src/linetypes/subfilereference.cpp	Wed Jan 22 00:23:29 2020 +0200
@@ -1,5 +1,6 @@
 #include "subfilereference.h"
 #include "documentmanager.h"
+#include "invert.h"
 
 linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation,
 	const QString& referenceName,
@@ -53,6 +54,7 @@
 	Model* model = this->resolve(context->documents);
 	if (model != nullptr)
 	{
+		const bool needInverting = math::det(this->transformation) < 0;
 		const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents);
 		polygons.reserve(polygons.size() + modelPolygons.size());
 		for (gl::Polygon polygon : modelPolygons)
@@ -61,6 +63,10 @@
 			{
 				polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation);
 			}
+			if (needInverting != this->isInverted)
+			{
+				gl::invert(polygon);
+			}
 			if (polygon.color == colors::main)
 			{
 				polygon.color = this->colorIndex;
@@ -76,6 +82,11 @@
 	return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)};
 }
 
+void linetypes::SubfileReference::invert()
+{
+	this->isInverted = not this->isInverted;
+}
+
 Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const
 {
 	return documents->findModelByName(this->referenceName);

mercurial