Moved more stuff to GLCamera

Tue, 14 Feb 2017 08:33:44 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 14 Feb 2017 08:33:44 +0200
changeset 1134
daa9808d626e
parent 1133
47f6db5ea24d
child 1135
8e0691be0b6f

Moved more stuff to GLCamera

src/editmodes/circleMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/circleMode.h file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
src/glcamera.cpp file | annotate | diff | comparison | revisions
src/glcamera.h file | annotate | diff | comparison | revisions
--- a/src/editmodes/circleMode.cpp	Tue Feb 14 08:26:39 2017 +0200
+++ b/src/editmodes/circleMode.cpp	Tue Feb 14 08:33:44 2017 +0200
@@ -61,30 +61,6 @@
 }
 
 
-Matrix CircleMode::getCircleDrawMatrix(double scale)
-{
-	// Matrix templates. 2 is substituted with the scale value, 1 is inverted to -1 if needed.
-	static const Matrix templates[3] =
-	{
-		{ 2, 0, 0, 0, 1, 0, 0, 0, 2 },
-		{ 2, 0, 0, 0, 0, 2, 0, 1, 0 },
-		{ 0, 1, 0, 2, 0, 0, 0, 0, 2 },
-	};
-
-	Matrix transform = templates[static_cast<int>(renderer()->camera()) % 3];
-
-	for (double& value : transform)
-	{
-		if (value == 2)
-			value = scale;
-		else if (value == 1 and static_cast<int>(renderer()->camera()) >= 3)
-			value = -1;
-	}
-
-	return transform;
-}
-
-
 void CircleMode::endDraw()
 {
 	Model model {m_documents};
@@ -106,7 +82,7 @@
 		// If the radii are the same, there's no ring space to fill. Use a circle.
 		primitiveModel.type = PrimitiveModel::Circle;
 		primitiveFile = primitives()->getPrimitive(primitiveModel);
-		transform = getCircleDrawMatrix(dist0);
+		transform = renderer()->currentCamera().transformationMatrix(dist0);
 		circleOrDisc = true;
 	}
 	else if (dist0 == 0 or dist1 == 0)
@@ -114,7 +90,7 @@
 		// If either radii is 0, use a disc.
 		primitiveModel.type = PrimitiveModel::Disc;
 		primitiveFile = primitives()->getPrimitive(primitiveModel);
-		transform = getCircleDrawMatrix ((dist0 != 0) ? dist0 : dist1);
+		transform = renderer()->currentCamera().transformationMatrix((dist0 != 0) ? dist0 : dist1);
 		circleOrDisc = true;
 	}
 	else if (g_RingFinder.findRings(dist0, dist1))
@@ -126,7 +102,8 @@
 		{
 			primitiveModel.ringNumber = component.num;
 			primitiveFile = primitives()->getPrimitive(primitiveModel);
-			model.emplace<LDSubfileReference>(primitiveFile, getCircleDrawMatrix(component.scale), m_drawedVerts.first());
+			model.emplace<LDSubfileReference>(primitiveFile, renderer()->currentCamera().transformationMatrix(component.scale),
+			                                  m_drawedVerts.first());
 		}
 	}
 	else
--- a/src/editmodes/circleMode.h	Tue Feb 14 08:26:39 2017 +0200
+++ b/src/editmodes/circleMode.h	Tue Feb 14 08:33:44 2017 +0200
@@ -28,7 +28,6 @@
 
 	void endDraw() override;
 	double getCircleDrawDist (int position) const;
-	Matrix getCircleDrawMatrix (double scale);
 	int maxVertices() const override;
 	bool preAddVertex (Vertex const&) override;
 	void render (QPainter& painter) const override;
--- a/src/glRenderer.cpp	Tue Feb 14 08:26:39 2017 +0200
+++ b/src/glRenderer.cpp	Tue Feb 14 08:33:44 2017 +0200
@@ -46,10 +46,10 @@
     m_model {model},
     m_cameras {
         {"Top camera", {1,  0, 0, X, Z, false, false, false}}, // top
-        {"Front camera", {0,  0, 0, X, Y, false,  true, false}}, // front
+        {"Front camera", {0,  0, 1, X, Y, false,  true, false}}, // front
         {"Left camera", {0,  1, 0, Z, Y,  true,  true, false}}, // left
         {"Bottom camera", {-1,  0, 0, X, Z, false,  true, true}}, // bottom
-        {"Back camera", {0,  0, 0, X, Y,  true,  true, true}}, // back
+        {"Back camera", {0,  0, -1, X, Y,  true,  true, true}}, // back
         {"Right camera", {0, -1, 0, Z, Y, false,  true, true}}, // right
         {"Free camera", GLCamera::FreeCamera}, // free
     }
@@ -382,7 +382,7 @@
 		glTranslatef(panning (X), panning (Y), 0.0f);
 
 		if (camera() != Camera::Front and camera() != Camera::Back)
-			glRotatef(90.0f, currentCamera().glRotate(X), currentCamera().glRotate(Y), currentCamera().glRotate(Z));
+			glRotatef(90.0f, currentCamera().glRotate(X), currentCamera().glRotate(Y), 0);
 
 		// Back camera needs to be handled differently
 		if (camera() == Camera::Back)
--- a/src/glRenderer.h	Tue Feb 14 08:26:39 2017 +0200
+++ b/src/glRenderer.h	Tue Feb 14 08:33:44 2017 +0200
@@ -80,7 +80,6 @@
 	QColor backgroundColor() const;
 	Camera camera() const;
 	QByteArray capturePixels();
-	GLCompiler* compiler() const;
 	GLCamera& currentCamera();
 	const GLCamera& currentCamera() const;
 	void drawGLScene();
--- a/src/glcamera.cpp	Tue Feb 14 08:26:39 2017 +0200
+++ b/src/glcamera.cpp	Tue Feb 14 08:33:44 2017 +0200
@@ -242,3 +242,36 @@
 {
 	return m_name;
 }
+
+/*
+ * Returns the camera's transformation matrix, scaled by the given scale value.
+ */
+Matrix GLCamera::transformationMatrix(double scale) const
+{
+	// Matrix templates. 2 is substituted with the scale value, 1 is inverted to -1 if needed.
+	static const Matrix templates[3] =
+	{
+	    { 2, 0, 0, 0, 1, 0, 0, 0, 2 },
+	    { 2, 0, 0, 0, 0, 2, 0, 1, 0 },
+	    { 0, 1, 0, 2, 0, 0, 0, 0, 2 },
+	};
+
+	Matrix transform;
+
+	if (m_localX == X and m_localY == Z)
+		transform = templates[0];
+	else if (m_localX == X and m_localY == Y)
+		transform = templates[1];
+	if (m_localX == Y and m_localY == Z)
+		transform = templates[2];
+
+	for (double& value : transform)
+	{
+		if (value == 2)
+			value = scale;
+		else if (value == 1 and (glRotate(X) + glRotate(Y) + glRotate(Z)) < 0)
+			value = -1;
+	}
+
+	return transform;
+}
--- a/src/glcamera.h	Tue Feb 14 08:26:39 2017 +0200
+++ b/src/glcamera.h	Tue Feb 14 08:33:44 2017 +0200
@@ -61,6 +61,7 @@
 	Q_SLOT void rendererResized(int width, int height);
 	void setPanning(double x, double y);
 	void setZoom(double zoom);
+	Matrix transformationMatrix(double scale) const;
 	const QSizeF& virtualSize() const;
 	double zoom() const;
 	void zoomNotch(bool inward);

mercurial