Mon, 22 Apr 2013 17:46:09 +0300
Added panning to GL view, added action for resetting angles, zoom and pan
gldraw.cpp | file | annotate | diff | comparison | revisions | |
gldraw.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
gui_actions.cpp | file | annotate | diff | comparison | revisions |
--- a/gldraw.cpp Mon Apr 22 17:15:25 2013 +0300 +++ b/gldraw.cpp Mon Apr 22 17:46:09 2013 +0300 @@ -44,17 +44,23 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -GLRenderer::GLRenderer (QWidget* parent) { - parent = parent; // shhh, GCC - fRotX = fRotY = fRotZ = 0.0f; - fZoom = 1.0f; - bPicking = false; +GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent) { + resetAngles (); + picking = false; qPulseTimer = new QTimer (this); connect (qPulseTimer, SIGNAL (timeout ()), this, SLOT (slot_timerUpdate ())); } // ============================================================================= +void GLRenderer::resetAngles () { + rotX = 30.0f; + rotY = 325.f; + panX = panY = rotZ = 0.0f; + zoom = 1.0f; +} + +// ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::initializeGL () { @@ -116,7 +122,7 @@ void GLRenderer::setObjectColor (LDObject* obj) { QColor qCol; - if (bPicking) { + if (picking) { // Make the color by the object's index color if we're picking, so we can // make the index from the color we get from the picking results. long i = obj->getIndex (g_CurrentFile); @@ -252,14 +258,14 @@ glLoadIdentity (); glTranslatef (0.0f, 0.0f, -5.0f); - glTranslatef (0.0f, 0.0f, -fZoom); + glTranslatef (panX, panY, -zoom); - glRotatef (fRotX, 1.0f, 0.0f, 0.0f); - glRotatef (fRotY, 0.0f, 1.0f, 0.0f); - glRotatef (fRotZ, 0.0f, 0.0f, 1.0f); + glRotatef (rotX, 1.0f, 0.0f, 0.0f); + glRotatef (rotY, 0.0f, 1.0f, 0.0f); + glRotatef (rotZ, 0.0f, 0.0f, 1.0f); for (LDObject* obj : g_CurrentFile->objects) - glCallList ((bPicking == false) ? obj->uGLList : obj->uGLPickList); + glCallList ((picking == false) ? obj->uGLList : obj->uGLPickList); glPopMatrix (); } @@ -289,9 +295,9 @@ GLuint uList = glGenLists (1); glNewList (uList, GL_COMPILE); - bPicking = (upMemberList == &obj->uGLPickList); + picking = (upMemberList == &obj->uGLPickList); compileOneObject (obj); - bPicking = false; + picking = false; glEndList (); *upMemberList = uList; @@ -410,83 +416,88 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::compileVertex (vertex& vrt) { +void GLRenderer::compileVertex (vertex& vert) { glVertex3d ( - (vrt.x + g_faObjectOffset[0]) / g_StoredBBoxSize, - -(vrt.y + g_faObjectOffset[1]) / g_StoredBBoxSize, - -(vrt.z + g_faObjectOffset[2]) / g_StoredBBoxSize); + (vert.x + g_faObjectOffset[0]) / g_StoredBBoxSize, + -(vert.y + g_faObjectOffset[1]) / g_StoredBBoxSize, + -(vert.z + g_faObjectOffset[2]) / g_StoredBBoxSize); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::clampAngle (double& fAngle) { - while (fAngle < 0) - fAngle += 360.0; - while (fAngle > 360.0) - fAngle -= 360.0; +void GLRenderer::clampAngle (double& angle) { + while (angle < 0) + angle += 360.0; + while (angle > 360.0) + angle -= 360.0; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::mouseReleaseEvent (QMouseEvent* event) { - if ((qMouseButtons & Qt::LeftButton) && !(event->buttons() & Qt::LeftButton)) { +void GLRenderer::mouseReleaseEvent (QMouseEvent* ev) { + if ((qMouseButtons & Qt::LeftButton) && !(ev->buttons() & Qt::LeftButton)) { if (ulTotalMouseMove < 10) - pick (event->x(), event->y(), (qKeyMods & Qt::ControlModifier)); + pick (ev->x(), ev->y(), (qKeyMods & Qt::ControlModifier)); ulTotalMouseMove = 0; } } // ============================================================================= -void GLRenderer::mousePressEvent (QMouseEvent* event) { - qMouseButtons = event->buttons(); - if (event->buttons() & Qt::LeftButton) +void GLRenderer::mousePressEvent (QMouseEvent* ev) { + qMouseButtons = ev->buttons(); + if (ev->buttons() & Qt::LeftButton) ulTotalMouseMove = 0; } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::mouseMoveEvent (QMouseEvent *event) { - int dx = event->x () - lastPos.x (); - int dy = event->y () - lastPos.y (); +void GLRenderer::mouseMoveEvent (QMouseEvent* ev) { + int dx = ev->x () - lastPos.x (); + int dy = ev->y () - lastPos.y (); ulTotalMouseMove += abs (dx) + abs (dy); - if (event->buttons () & Qt::LeftButton) { - fRotX = fRotX + (dy); - fRotY = fRotY + (dx); - clampAngle (fRotX); - clampAngle (fRotY); + if (ev->buttons () & Qt::LeftButton) { + rotX = rotX + (dy); + rotY = rotY + (dx); + clampAngle (rotX); + clampAngle (rotY); } - if (event->buttons () & Qt::RightButton) { - fRotX = fRotX + (dy); - fRotZ = fRotZ + (dx); - clampAngle (fRotX); - clampAngle (fRotZ); + if (ev->buttons () & Qt::RightButton) { + rotX = rotX + (dy); + rotZ = rotZ + (dx); + clampAngle (rotX); + clampAngle (rotZ); } - lastPos = event->pos(); + if (ev->buttons () & Qt::MidButton) { + panX += 0.03f * dx; + panY -= 0.03f * dy; + } + + lastPos = ev->pos (); updateGL (); } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::keyPressEvent (QKeyEvent* qEvent) { - qKeyMods = qEvent->modifiers (); +void GLRenderer::keyPressEvent (QKeyEvent* ev) { + qKeyMods = ev->modifiers (); } -void GLRenderer::keyReleaseEvent (QKeyEvent* qEvent) { - qKeyMods = qEvent->modifiers (); +void GLRenderer::keyReleaseEvent (QKeyEvent* ev) { + qKeyMods = ev->modifiers (); } // ============================================================================= void GLRenderer::wheelEvent (QWheelEvent* ev) { - fZoom += (-ev->delta () / 100.0); - fZoom = clamp (fZoom, 0.01, 100.0); + zoom += (-ev->delta () / 100.0); + zoom = clamp (zoom, 0.01, 100.0); ev->accept (); updateGL (); } @@ -519,7 +530,7 @@ glDisable (GL_DITHER); glClearColor (1.0f, 1.0f, 1.0f, 1.0f); - bPicking = true; + picking = true; paintGL (); @@ -541,7 +552,7 @@ g_ForgeWindow->buildObjList (); - bPicking = false; + picking = false; glEnable (GL_DITHER); setBackground (); @@ -573,7 +584,7 @@ obj->uGLList = uList; } -// ========================================================================= // +// ============================================================================= void GLRenderer::slot_timerUpdate () { ++g_dPulseTick %= g_dNumPulseTicks;
--- a/gldraw.h Mon Apr 22 17:15:25 2013 +0300 +++ b/gldraw.h Mon Apr 22 17:46:09 2013 +0300 @@ -43,23 +43,25 @@ QColor getMainColor (); void recompileObject (LDObject* obj); void refresh (); - void updateSelFlash(); + void updateSelFlash (); + void resetAngles (); - double fRotX, fRotY, fRotZ; + double rotX, rotY, rotZ; + double panX, panY; QPoint lastPos; - double fZoom; - bool bPicking; + double zoom; + bool picking; protected: void initializeGL (); void resizeGL (int w, int h); void paintGL (); - void mousePressEvent (QMouseEvent* event); - void mouseMoveEvent (QMouseEvent* event); - void mouseReleaseEvent (QMouseEvent* event); - void keyPressEvent (QKeyEvent* qEvent); - void keyReleaseEvent (QKeyEvent* qEvent); + void mousePressEvent (QMouseEvent* ev); + void mouseMoveEvent (QMouseEvent* ev); + void mouseReleaseEvent (QMouseEvent* ev); + void keyPressEvent (QKeyEvent* ev); + void keyReleaseEvent (QKeyEvent* ev); void wheelEvent (QWheelEvent* ev); private:
--- a/gui.cpp Mon Apr 22 17:15:25 2013 +0300 +++ b/gui.cpp Mon Apr 22 17:46:09 2013 +0300 @@ -80,6 +80,7 @@ EXTERN_ACTION (gridCoarse) EXTERN_ACTION (gridMedium) EXTERN_ACTION (gridFine) +EXTERN_ACTION (resetView) #ifndef RELEASE EXTERN_ACTION (addTestQuad) @@ -190,6 +191,10 @@ qFileMenu->addSeparator (); // ------- qFileMenu->addAction (ACTION_NAME (exit)); // Exit + // View menu + qViewMenu = menuBar ()->addMenu (tr ("&View")); + qViewMenu->addAction (ACTION_NAME (resetView)); + // Insert menu qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); qInsertMenu->addAction (ACTION_NAME (newSubfile)); // New Subfile @@ -692,7 +697,7 @@ // Update the shared selection array, unless this was called during GL picking, // in which case the GL renderer takes care of the selection. - if (R->bPicking == false) { + if (R->picking == false) { std::vector<LDObject*> paPriorSelection = paSelection; paSelection = getSelectedObjects ();
--- a/gui.h Mon Apr 22 17:15:25 2013 +0300 +++ b/gui.h Mon Apr 22 17:46:09 2013 +0300 @@ -107,7 +107,8 @@ // Object list view QTreeWidget* qObjList; QTextEdit* qMessageLog; - QMenu* qFileMenu, *qEditMenu, *qInsertMenu, *qMoveMenu, *qHelpMenu, *qControlMenu; + QMenu* qFileMenu, *qEditMenu, *qViewMenu, *qInsertMenu, *qMoveMenu, + *qHelpMenu, *qControlMenu; QMenu* qRecentFilesMenu; std::vector<QAction*> qaRecentFiles;
--- a/gui_actions.cpp Mon Apr 22 17:15:25 2013 +0300 +++ b/gui_actions.cpp Mon Apr 22 17:46:09 2013 +0300 @@ -243,6 +243,12 @@ } // ============================================================================= +ACTION (resetView, "Reset View", "reset-view", "Reset view angles, pan and zoom", CTRL (0)) { + g_ForgeWindow->R->resetAngles (); + g_ForgeWindow->R->updateGL (); +} + +// ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= // Debug things