Made rotation/pan/zoom values camera-dependant (so now there's 7 sets of them instead of 1)

Tue, 22 Oct 2013 22:09:53 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Tue, 22 Oct 2013 22:09:53 +0300
changeset 534
3ed2ebcbc84f
parent 533
d77811a0494e
child 535
1c5cf41c1247

Made rotation/pan/zoom values camera-dependant (so now there's 7 sets of them instead of 1)

src/file.cpp file | annotate | diff | comparison | revisions
src/gldraw.cpp file | annotate | diff | comparison | revisions
src/gldraw.h file | annotate | diff | comparison | revisions
src/gui.h file | annotate | diff | comparison | revisions
--- a/src/file.cpp	Tue Oct 22 21:42:20 2013 +0300
+++ b/src/file.cpp	Tue Oct 22 22:09:53 2013 +0300
@@ -1111,7 +1111,7 @@
 		g_win->buildObjList();
 		g_win->updateTitle();
 		g_win->R()->setFile (f);
-		g_win->R()->resetAngles();
+		g_win->R()->resetAllAngles();
 		g_win->R()->repaint();
 
 		log ("Changed file to %1", f->getShortName());
--- a/src/gldraw.cpp	Tue Oct 22 21:42:20 2013 +0300
+++ b/src/gldraw.cpp	Tue Oct 22 22:09:53 2013 +0300
@@ -200,14 +200,27 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 void GLRenderer::resetAngles()
-{	m_rotX = 30.0f;
-	m_rotY = 325.f;
-	m_panX = m_panY = m_rotZ = 0.0f;
+{	rot (X) = 30.0f;
+	rot (Y) = 325.f;
+	pan (X) = pan (Y) = rot (Z) = 0.0f;
 	zoomToFit();
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
+void GLRenderer::resetAllAngles()
+{	Camera oldcam = camera();
+
+	for (int i = 0; i < 7; ++i)
+	{	setCamera ((Camera) i);
+		resetAngles();
+	}
+
+	setCamera (oldcam);
+}
+
+// =============================================================================
+// -----------------------------------------------------------------------------
 void GLRenderer::initializeGL()
 {	setBackground();
 
@@ -387,12 +400,12 @@
 
 		glLoadIdentity();
 		glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f);
-		glTranslatef (m_panX, m_panY, 0.0f);
+		glTranslatef (pan (X), pan (Y), 0.0f);
 
 		if (m_camera != Front && m_camera != Back)
-		{	glRotatef (90.0f, g_FixedCameras[m_camera].glrotate[0],
-					   g_FixedCameras[m_camera].glrotate[1],
-					   g_FixedCameras[m_camera].glrotate[2]);
+		{	glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0],
+				g_FixedCameras[camera()].glrotate[1],
+				g_FixedCameras[camera()].glrotate[2]);
 		}
 
 		// Back camera needs to be handled differently
@@ -407,10 +420,10 @@
 		glLoadIdentity();
 
 		glTranslatef (0.0f, 0.0f, -2.0f);
-		glTranslatef (m_panX, m_panY, -zoom());
-		glRotatef (m_rotX, 1.0f, 0.0f, 0.0f);
-		glRotatef (m_rotY, 0.0f, 1.0f, 0.0f);
-		glRotatef (m_rotZ, 0.0f, 0.0f, 1.0f);
+		glTranslatef (pan (X), pan (Y), -zoom());
+		glRotatef (rot (X), 1.0f, 0.0f, 0.0f);
+		glRotatef (rot (Y), 0.0f, 1.0f, 0.0f);
+		glRotatef (rot (Z), 0.0f, 0.0f, 1.0f);
 	}
 
 	const GL::ListType list = (!drawOnly() && m_picking) ? PickList : NormalList;
@@ -464,8 +477,8 @@
 				negYFac = cam->negY ? -1 : 1;
 
 	// Calculate cx and cy - these are the LDraw unit coords the cursor is at.
-	double cx = (-m_virtWidth + ( (2 * pos2d.x() * m_virtWidth) / m_width) - m_panX);
-	double cy = (m_virtHeight - ( (2 * pos2d.y() * m_virtHeight) / m_height) - m_panY);
+	double cx = (-m_virtWidth + ((2 * pos2d.x() * m_virtWidth) / m_width) - pan (X));
+	double cy = (m_virtHeight - ((2 * pos2d.y() * m_virtHeight) / m_height) - pan (Y));
 
 	if (snap)
 	{	cx = Grid::snap (cx, (Grid::Config) axisX);
@@ -507,8 +520,8 @@
 	transformed[Y] = (m[4] * x) + (m[5] * y) + (m[6] * z) + m[7];
 	transformed[Z] = (m[8] * x) + (m[9] * y) + (m[10] * z) + m[11];
 
-	double rx = (((transformed[axisX] * negXFac) + m_virtWidth + m_panX) * m_width) / (2 * m_virtWidth);
-	double ry = (((transformed[axisY] * negYFac) - m_virtHeight + m_panY) * m_height) / (2 * m_virtHeight);
+	double rx = (((transformed[axisX] * negXFac) + m_virtWidth + pan (X)) * m_width) / (2 * m_virtWidth);
+	double ry = (((transformed[axisY] * negYFac) - m_virtHeight + pan (Y)) * m_height) / (2 * m_virtHeight);
 
 	return QPoint (rx, -ry);
 }
@@ -1084,15 +1097,15 @@
 			   shift = ev->modifiers() & Qt::ShiftModifier;
 
 	if (mid || (left && shift))
-	{	m_panX += 0.03f * dx * (zoom() / 7.5f);
-		m_panY -= 0.03f * dy * (zoom() / 7.5f);
+	{	pan (X) += 0.03f * dx * (zoom() / 7.5f);
+		pan (Y) -= 0.03f * dy * (zoom() / 7.5f);
 		m_panning = true;
 	} elif (left && !m_rangepick && camera() == Free)
-	{	m_rotX = m_rotX + (dy);
-		m_rotY = m_rotY + (dx);
+	{	rot (X) = rot (X) + dy;
+		rot (Y) = rot (Y) + dx;
 
-		clampAngle (m_rotX);
-		clampAngle (m_rotY);
+		clampAngle (rot (X));
+		clampAngle (rot (Y));
 	}
 
 	// Start the tool tip timer
@@ -1130,7 +1143,7 @@
 {	makeCurrent();
 
 	zoomNotch (ev->delta() > 0);
-	setZoom (clamp<double> (zoom(), 0.01f, 10000.0f));
+	zoom() = clamp (zoom(), 0.01, 10000.0);
 
 	update();
 	ev->accept();
@@ -1739,16 +1752,16 @@
 // -----------------------------------------------------------------------------
 void GLRenderer::zoomNotch (bool inward)
 {	if (zoom() > 15)
-		setZoom (zoom() * (inward ? 0.833f : 1.2f));
+		zoom() *= inward ? 0.833f : 1.2f;
 	else
-		setZoom (zoom() + (inward ? -1.2f : 1.2f));
+		zoom() += inward ? -1.2f : 1.2f;
 }
 
 // =============================================================================
 // -----------------------------------------------------------------------------
 void GLRenderer::zoomToFit()
 {	if (file() == null || m_width == -1 || m_height == -1)
-	{	setZoom (30.0f);
+	{	zoom() = 30.0f;
 		return;
 	}
 
@@ -1766,10 +1779,10 @@
 	m_picking = true;
 
 	for (;;)
-	{	if (zoom() > 10000.0f || zoom() < 0.0f)
+	{	if (zoom() > 10000.0 || zoom() < 0.0)
 		{	// Obviously, there's nothing to draw if we get here.
 			// Default to 30.0f and break out.
-			setZoom (30.0f);
+			zoom() = 30.0;
 			break;
 		}
 
@@ -1825,6 +1838,19 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
+void GLRenderer::zoomAllToFit()
+{	Camera oldcam = camera();
+
+	for (int i = 0; i < 7; ++i)
+	{	setCamera ((Camera) i);
+		zoomToFit();
+	}
+
+	setCamera (oldcam);
+}
+
+// =============================================================================
+// -----------------------------------------------------------------------------
 void GLRenderer::updateRectVerts()
 {	if (!m_rectdraw)
 		return;
--- a/src/gldraw.h	Tue Oct 22 21:42:20 2013 +0300
+++ b/src/gldraw.h	Tue Oct 22 22:09:53 2013 +0300
@@ -64,7 +64,6 @@
 {	Q_OBJECT
 
 	PROPERTY (bool, drawOnly, setDrawOnly)
-	PROPERTY (double, zoom, setZoom)
 	PROPERTY (MessageManager*, msglog, setMessageLog)
 	READ_PROPERTY (bool, picking, setPicking)
 	DECLARE_PROPERTY (LDFile*, file, setFile)
@@ -96,6 +95,7 @@
 		void           overlaysFromObjects();
 		void           refresh();
 		void           resetAngles();
+		void           resetAllAngles();
 		uchar*         screencap (int& w, int& h);
 		void           setBackground();
 		void           setCamera (const Camera cam);
@@ -104,6 +104,7 @@
 		void           updateOverlayObjects();
 		void           zoomNotch (bool inward);
 		void           zoomToFit();
+		void           zoomAllToFit();
 
 		static void    deleteLists (LDObject* obj);
 
@@ -137,17 +138,19 @@
 		Qt::KeyboardModifiers m_keymods;
 		vertex                m_hoverpos;
 		double                m_virtWidth,
-		                      m_virtHeight,
-							  m_rotX,
-							  m_rotY,
-							  m_rotZ,
-							  m_panX,
-							  m_panY;
+	                          m_virtHeight,
+							  m_rotX[7],
+							  m_rotY[7],
+							  m_rotZ[7],
+							  m_panX[7],
+							  m_panY[7],
+		                      m_zoom[7];
 		bool                  m_darkbg,
 		                      m_rangepick,
 							  m_addpick,
 							  m_drawToolTip,
-							  m_screencap;
+							  m_screencap,
+		                      m_panning;
 		QPoint                m_pos,
 		                      m_globalpos,
 		                      m_rangeStart;
@@ -166,26 +169,69 @@
 		double                m_depthValues[6];
 		LDGLOverlay           m_overlays[6];
 		QList<vertex>         m_knownVerts;
-		bool                  m_panning;
 
 		void           addDrawnVertex (vertex m_hoverpos);
-		void           calcCameraIcons();                                      // Compute geometry for camera icons
-		void           clampAngle (double& angle) const;                       // Clamps an angle to [0, 360]
-		void           compileList (LDObject* obj, const ListType list);       // Compile one of the lists of an object
-		void           compileSubObject (LDObject* obj, const GLenum gltype);  // Sub-routine for object compiling
-		void           compileVertex (const vertex& vrt);                      // Compile a single vertex to a list
-		vertex         coordconv2_3 (const QPoint& pos2d, bool snap) const;    // Convert a 2D point to a 3D point
-		QPoint         coordconv3_2 (const vertex& pos3d) const;               // Convert a 3D point to a 2D point
 		LDOverlay*     findOverlayObject (Camera cam);
 		void           updateRectVerts();
-		void           pick (int mouseX, int mouseY);                          // Perform object selection
-		void           setObjectColor (LDObject* obj, const ListType list);    // Set the color to an object list
-		QColor         getTextPen() const;                                     // Determine which color to draw text with
 		void           getRelativeAxes (Axis& relX, Axis& relY) const;
 		matrix         getCircleDrawMatrix (double scale);
+		void           drawBlip (QPainter& paint, QPoint pos) const;
+		
+		// Compute geometry for camera icons
+		void           calcCameraIcons();
+		
+		// How large is the circle we're drawing right now?
+		double         circleDrawDist (int pos) const;
+		
+		// Clamps an angle to [0, 360]
+		void           clampAngle (double& angle) const;
+		
+		// Compile one of the lists of an object
+		void           compileList (LDObject* obj, const ListType list);
+		
+		// Sub-routine for object compiling
+		void           compileSubObject (LDObject* obj, const GLenum gltype);
+		
+		// Compile a single vertex to a list
+		void           compileVertex (const vertex& vrt);
+		
+		// Convert a 2D point to a 3D point
+		vertex         coordconv2_3 (const QPoint& pos2d, bool snap) const;
+		
+		// Convert a 3D point to a 2D point
+		QPoint         coordconv3_2 (const vertex& pos3d) const;
 
-		void           drawBlip (QPainter& paint, QPoint pos) const;
-		double         circleDrawDist(int pos) const;
+		// Determine which color to draw text with
+		QColor         getTextPen() const;
+
+		// Perform object selection
+		void           pick (int mouseX, int mouseY);
+
+		// Set the color to an object list
+		void           setObjectColor (LDObject* obj, const ListType list);
+
+		// Get a rotation value
+		inline double& rot (Axis ax)
+		{	return
+				(ax == X) ? m_rotX[camera()] :
+				(ax == Y) ? m_rotY[camera()] :
+				            m_rotZ[camera()];
+		}
+
+		// Get a panning value
+		inline double& pan (Axis ax)
+		{	return (ax == X) ? m_panX[camera()] : m_panY[camera()];
+		}
+
+		// Same except const (can be used in const methods)
+		inline const double& pan (Axis ax) const
+		{	return (ax == X) ? m_panX[camera()] : m_panY[camera()];
+		}
+
+		// Get the zoom value
+		inline double& zoom()
+		{	return m_zoom[camera()];
+		}
 
 	private slots:
 		void           slot_toolTipTimer();
--- a/src/gui.h	Tue Oct 22 21:42:20 2013 +0300
+++ b/src/gui.h	Tue Oct 22 22:09:53 2013 +0300
@@ -153,7 +153,7 @@
 		MessageManager* m_msglog;
 		Ui_LDForgeUI* ui;
 
-		void invokeAction (QAction* act, void (*func) ());
+		void invokeAction (QAction* act, void (*func)());
 
 
 	private slots:

mercurial