- Use a QGenericMatrix to store the matrix, instead of a C array

Wed, 08 Feb 2017 16:51:55 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 08 Feb 2017 16:51:55 +0200
changeset 1095
cb58a160bed3
parent 1094
8a419cead363
child 1096
7cc929d8fc4d

- Use a QGenericMatrix to store the matrix, instead of a C array
- Only reset angles when GL is initialized, otherwise bad things happen
- Fixed missing "}" in matrix string representation

src/format.h file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
--- a/src/format.h	Wed Feb 08 16:45:32 2017 +0200
+++ b/src/format.h	Wed Feb 08 16:51:55 2017 +0200
@@ -78,11 +78,12 @@
 				if (column > 0)
 					m_text += ", ";
 
-				m_text += StringFormatArg{matrix(row, column)}.text();
+				m_text += StringFormatArg {matrix(row, column)}.text();
 			}
 
 			m_text += "}";
 		}
+		m_text += "}";
 	}
 
 	inline QString text() const
--- a/src/glRenderer.cpp	Wed Feb 08 16:45:32 2017 +0200
+++ b/src/glRenderer.cpp	Wed Feb 08 16:51:55 2017 +0200
@@ -210,14 +210,17 @@
 //
 void GLRenderer::resetAngles()
 {
-	// Why did I even bother trying to compute this by pen and paper? Let GL figure it out...
-	glMatrixMode(GL_MODELVIEW);
-	glPushMatrix();
-	glLoadIdentity();
-	glRotatef(30, 1, 0, 0);
-	glRotatef(330, 0, 1, 0);
-	glGetFloatv(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix);
-	glPopMatrix();
+	if (m_initialized)
+	{
+		// Why did I even bother trying to compute this by pen and paper? Let GL figure it out...
+		glMatrixMode(GL_MODELVIEW);
+		glPushMatrix();
+		glLoadIdentity();
+		glRotatef(30, 1, 0, 0);
+		glRotatef(330, 0, 1, 0);
+		glGetFloatv(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix.data());
+		glPopMatrix();
+	}
 	panning(X) = panning(Y) = 0.0f;
 	needZoomToFit();
 }
@@ -251,6 +254,8 @@
 	compiler()->initialize();
 	initializeAxes();
 	m_initialized = true;
+	// Now that GL is initialized, we can reset angles.
+	resetAllAngles();
 }
 
 // =============================================================================
@@ -406,7 +411,7 @@
 		glLoadIdentity();
 		glTranslatef(0.0f, 0.0f, -2.0f);
 		glTranslatef(panning (X), panning (Y), -zoom());
-		glMultMatrixf(currentDocumentData().rotationMatrix);
+		glMultMatrixf(currentDocumentData().rotationMatrix.constData());
 	}
 
 	glEnableClientState (GL_VERTEX_ARRAY);
@@ -612,7 +617,7 @@
 #ifndef RELEASE
 	{
 		QString text = format("Rotation: %1\nPanning: (%2, %3), Zoom: %4",
-		    QGenericMatrix<4, 4, GLfloat>(currentDocumentData().rotationMatrix), panning(X), panning(Y), zoom());
+		    currentDocumentData().rotationMatrix, panning(X), panning(Y), zoom());
 		QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text);
 		painter.setPen(textPen());
 		painter.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
@@ -808,8 +813,8 @@
 			glLoadIdentity();
 			// 0.6 is an arbitrary rotation sensitivity scalar
 			glRotatef(0.6 * hypot(xMove, yMove), yMove, xMove, 0);
-			glMultMatrixf(currentDocumentData().rotationMatrix);
-			glGetFloatv(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix);
+			glMultMatrixf(currentDocumentData().rotationMatrix.constData());
+			glGetFloatv(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix.data());
 			glPopMatrix();
 			m_isCameraMoving = true;
 		}
--- a/src/glRenderer.h	Wed Feb 08 16:45:32 2017 +0200
+++ b/src/glRenderer.h	Wed Feb 08 16:51:55 2017 +0200
@@ -69,7 +69,7 @@
 //
 struct LDGLData
 {
-	GLfloat			rotationMatrix[16];
+	QGenericMatrix<4, 4, GLfloat> rotationMatrix;
 	double			panX[7];
 	double			panY[7];
 	double			zoom[7];
@@ -79,7 +79,6 @@
 	bool			needZoomToFit;
 
 	LDGLData() :
-	    rotationMatrix {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
 		init (false),
 		needZoomToFit (true)
 	{

mercurial