src/glRenderer.cpp

changeset 1092
7a50a7f6b492
parent 1086
621c2e5853bb
child 1093
3fb96ed48e49
equal deleted inserted replaced
1091:4a754362f660 1092:7a50a7f6b492
208 208
209 // ============================================================================= 209 // =============================================================================
210 // 210 //
211 void GLRenderer::resetAngles() 211 void GLRenderer::resetAngles()
212 { 212 {
213 rotation (X) = 30.0f; 213 // Why did I even bother trying to compute this by pen and paper? Let GL figure it out...
214 rotation (Y) = 325.f; 214 glMatrixMode(GL_MODELVIEW);
215 panning (X) = panning (Y) = rotation (Z) = 0.0f; 215 glPushMatrix();
216 glLoadIdentity();
217 glRotated(30, 1, 0, 0);
218 glRotated(330, 0, 1, 0);
219 glGetDoublev(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix);
220 glPopMatrix();
221 panning(X) = panning(Y) = 0.0f;
216 needZoomToFit(); 222 needZoomToFit();
217 } 223 }
218 224
219 // ============================================================================= 225 // =============================================================================
220 // 226 //
398 glMatrixMode(GL_MODELVIEW); 404 glMatrixMode(GL_MODELVIEW);
399 glPushMatrix(); 405 glPushMatrix();
400 glLoadIdentity(); 406 glLoadIdentity();
401 glTranslatef(0.0f, 0.0f, -2.0f); 407 glTranslatef(0.0f, 0.0f, -2.0f);
402 glTranslatef(panning (X), panning (Y), -zoom()); 408 glTranslatef(panning (X), panning (Y), -zoom());
403 glRotatef(rotation(X), 1.0f, 0.0f, 0.0f); 409 glMultMatrixd(currentDocumentData().rotationMatrix);
404 glRotatef(rotation(Y), 0.0f, 1.0f, 0.0f);
405 glRotatef(rotation(Z), 0.0f, 0.0f, 1.0f);
406 } 410 }
407 411
408 glEnableClientState (GL_VERTEX_ARRAY); 412 glEnableClientState (GL_VERTEX_ARRAY);
409 glEnableClientState (GL_COLOR_ARRAY); 413 glEnableClientState (GL_COLOR_ARRAY);
410 414
605 if (isDrawOnly() or m_isDrawingSelectionScene) 609 if (isDrawOnly() or m_isDrawingSelectionScene)
606 return; 610 return;
607 611
608 #ifndef RELEASE 612 #ifndef RELEASE
609 { 613 {
610 QString text = format("Rotation: (%1°, %2°, %3°)\nPanning: (%4, %5), Zoom: %6", 614 QString text = format("Rotation: %1\nPanning: (%2, %3), Zoom: %4",
611 rotation(X), rotation(Y), rotation(Z), panning(X), panning(Y), zoom()); 615 QGenericMatrix<4, 4, GLdouble>(currentDocumentData().rotationMatrix), panning(X), panning(Y), zoom());
612 QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text); 616 QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text);
613 painter.setPen(textPen()); 617 painter.setPen(textPen());
614 painter.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), 618 painter.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
615 textSize.height(), Qt::AlignCenter, text); 619 textSize.height(), Qt::AlignCenter, text);
616 } 620 }
805 panning(X) += 0.03f * xMove * (zoom() / 7.5f); 809 panning(X) += 0.03f * xMove * (zoom() / 7.5f);
806 panning(Y) -= 0.03f * yMove * (zoom() / 7.5f); 810 panning(Y) -= 0.03f * yMove * (zoom() / 7.5f);
807 m_panning = true; 811 m_panning = true;
808 m_isCameraMoving = true; 812 m_isCameraMoving = true;
809 } 813 }
810 else if (left and camera() == FreeCamera) 814 else if (left and camera() == FreeCamera and (xMove != 0 or yMove != 0))
811 { 815 {
812 rotation(X) = rotation(X) + yMove; 816 // Apply current rotation input to the rotation matrix
813 rotation(Y) = rotation(Y) + xMove; 817 // ref: https://forums.ldraw.org/thread-22006-post-24426.html#pid24426
814 clampAngle(rotation (X)); 818 glPushMatrix();
815 clampAngle(rotation (Y)); 819 glLoadIdentity();
820 // 0.6 is an arbitrary rotation sensitivity scalar
821 glRotated(0.6 * hypot(xMove, yMove), yMove, xMove, 0);
822 glMultMatrixd(currentDocumentData().rotationMatrix);
823 glGetDoublev(GL_MODELVIEW_MATRIX, currentDocumentData().rotationMatrix);
824 glPopMatrix();
816 m_isCameraMoving = true; 825 m_isCameraMoving = true;
817 } 826 }
818 } 827 }
819 828
820 // Start the tool tip timer 829 // Start the tool tip timer
1621 LDGLData& GLRenderer::currentDocumentData() const 1630 LDGLData& GLRenderer::currentDocumentData() const
1622 { 1631 {
1623 return *document()->glData(); 1632 return *document()->glData();
1624 } 1633 }
1625 1634
1626 double& GLRenderer::rotation (Axis ax)
1627 {
1628 return
1629 (ax == X) ? currentDocumentData().rotationX :
1630 (ax == Y) ? currentDocumentData().rotationY :
1631 currentDocumentData().rotationZ;
1632 }
1633
1634 double& GLRenderer::panning (Axis ax) 1635 double& GLRenderer::panning (Axis ax)
1635 { 1636 {
1636 return (ax == X) ? currentDocumentData().panX[camera()] : 1637 return (ax == X) ? currentDocumentData().panX[camera()] :
1637 currentDocumentData().panY[camera()]; 1638 currentDocumentData().panY[camera()];
1638 } 1639 }

mercurial