src/dialogs/circularprimitiveeditor.cpp

changeset 1413
6b0ca41c158f
parent 1412
f5eb947a2e7f
child 1414
04db55860880
--- a/src/dialogs/circularprimitiveeditor.cpp	Tue Jun 19 23:18:58 2018 +0300
+++ b/src/dialogs/circularprimitiveeditor.cpp	Tue Jun 19 23:56:07 2018 +0300
@@ -125,6 +125,8 @@
 		if (this->primitive)
 			this->primitive->setInverted(checked);
 	});
+	connect(ui.rotateCcw, &QPushButton::clicked, [&](){ rotate(-1); });
+	connect(ui.rotateCw, &QPushButton::clicked, [&](){ rotate(1); });
 	// Connect the reset button, "reset button" here meaning any button with the reset role.
 	connect(
 		ui.buttonBox,
@@ -193,3 +195,16 @@
 	if (primitive)
 		primitive->restore(originalState); // Restoring does not change 'originalState'
 }
+
+void CircularPrimitiveEditor::rotate(double factor)
+{
+	if (primitive)
+	{
+		double angle = factor * 360.0 / primitive->divisions();
+
+		QQuaternion rotation = QQuaternion::fromAxisAndAngle({0.0f, 1.0f, 0.0f}, angle);
+		QMatrix4x4 matrix = primitive->transformationMatrix();
+		matrix.rotate(rotation);
+		primitive->setTransformationMatrix(matrix);
+	}
+}

mercurial