src/gldraw.cpp

changeset 534
3ed2ebcbc84f
parent 529
c294b2070185
child 538
2f85d4d286e5
child 665
4355e72ffd47
equal deleted inserted replaced
533:d77811a0494e 534:3ed2ebcbc84f
198 } 198 }
199 199
200 // ============================================================================= 200 // =============================================================================
201 // ----------------------------------------------------------------------------- 201 // -----------------------------------------------------------------------------
202 void GLRenderer::resetAngles() 202 void GLRenderer::resetAngles()
203 { m_rotX = 30.0f; 203 { rot (X) = 30.0f;
204 m_rotY = 325.f; 204 rot (Y) = 325.f;
205 m_panX = m_panY = m_rotZ = 0.0f; 205 pan (X) = pan (Y) = rot (Z) = 0.0f;
206 zoomToFit(); 206 zoomToFit();
207 }
208
209 // =============================================================================
210 // -----------------------------------------------------------------------------
211 void GLRenderer::resetAllAngles()
212 { Camera oldcam = camera();
213
214 for (int i = 0; i < 7; ++i)
215 { setCamera ((Camera) i);
216 resetAngles();
217 }
218
219 setCamera (oldcam);
207 } 220 }
208 221
209 // ============================================================================= 222 // =============================================================================
210 // ----------------------------------------------------------------------------- 223 // -----------------------------------------------------------------------------
211 void GLRenderer::initializeGL() 224 void GLRenderer::initializeGL()
385 { glMatrixMode (GL_PROJECTION); 398 { glMatrixMode (GL_PROJECTION);
386 glPushMatrix(); 399 glPushMatrix();
387 400
388 glLoadIdentity(); 401 glLoadIdentity();
389 glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f); 402 glOrtho (-m_virtWidth, m_virtWidth, -m_virtHeight, m_virtHeight, -100.0f, 100.0f);
390 glTranslatef (m_panX, m_panY, 0.0f); 403 glTranslatef (pan (X), pan (Y), 0.0f);
391 404
392 if (m_camera != Front && m_camera != Back) 405 if (m_camera != Front && m_camera != Back)
393 { glRotatef (90.0f, g_FixedCameras[m_camera].glrotate[0], 406 { glRotatef (90.0f, g_FixedCameras[camera()].glrotate[0],
394 g_FixedCameras[m_camera].glrotate[1], 407 g_FixedCameras[camera()].glrotate[1],
395 g_FixedCameras[m_camera].glrotate[2]); 408 g_FixedCameras[camera()].glrotate[2]);
396 } 409 }
397 410
398 // Back camera needs to be handled differently 411 // Back camera needs to be handled differently
399 if (m_camera == GLRenderer::Back) 412 if (m_camera == GLRenderer::Back)
400 { glRotatef (180.0f, 1.0f, 0.0f, 0.0f); 413 { glRotatef (180.0f, 1.0f, 0.0f, 0.0f);
405 { glMatrixMode (GL_MODELVIEW); 418 { glMatrixMode (GL_MODELVIEW);
406 glPushMatrix(); 419 glPushMatrix();
407 glLoadIdentity(); 420 glLoadIdentity();
408 421
409 glTranslatef (0.0f, 0.0f, -2.0f); 422 glTranslatef (0.0f, 0.0f, -2.0f);
410 glTranslatef (m_panX, m_panY, -zoom()); 423 glTranslatef (pan (X), pan (Y), -zoom());
411 glRotatef (m_rotX, 1.0f, 0.0f, 0.0f); 424 glRotatef (rot (X), 1.0f, 0.0f, 0.0f);
412 glRotatef (m_rotY, 0.0f, 1.0f, 0.0f); 425 glRotatef (rot (Y), 0.0f, 1.0f, 0.0f);
413 glRotatef (m_rotZ, 0.0f, 0.0f, 1.0f); 426 glRotatef (rot (Z), 0.0f, 0.0f, 1.0f);
414 } 427 }
415 428
416 const GL::ListType list = (!drawOnly() && m_picking) ? PickList : NormalList; 429 const GL::ListType list = (!drawOnly() && m_picking) ? PickList : NormalList;
417 430
418 if (gl_colorbfc && !m_picking && !drawOnly()) 431 if (gl_colorbfc && !m_picking && !drawOnly())
462 const Axis axisY = cam->axisY; 475 const Axis axisY = cam->axisY;
463 const short negXFac = cam->negX ? -1 : 1, 476 const short negXFac = cam->negX ? -1 : 1,
464 negYFac = cam->negY ? -1 : 1; 477 negYFac = cam->negY ? -1 : 1;
465 478
466 // Calculate cx and cy - these are the LDraw unit coords the cursor is at. 479 // Calculate cx and cy - these are the LDraw unit coords the cursor is at.
467 double cx = (-m_virtWidth + ( (2 * pos2d.x() * m_virtWidth) / m_width) - m_panX); 480 double cx = (-m_virtWidth + ((2 * pos2d.x() * m_virtWidth) / m_width) - pan (X));
468 double cy = (m_virtHeight - ( (2 * pos2d.y() * m_virtHeight) / m_height) - m_panY); 481 double cy = (m_virtHeight - ((2 * pos2d.y() * m_virtHeight) / m_height) - pan (Y));
469 482
470 if (snap) 483 if (snap)
471 { cx = Grid::snap (cx, (Grid::Config) axisX); 484 { cx = Grid::snap (cx, (Grid::Config) axisX);
472 cy = Grid::snap (cy, (Grid::Config) axisY); 485 cy = Grid::snap (cy, (Grid::Config) axisY);
473 } 486 }
505 vertex transformed; 518 vertex transformed;
506 transformed[X] = (m[0] * x) + (m[1] * y) + (m[2] * z) + m[3]; 519 transformed[X] = (m[0] * x) + (m[1] * y) + (m[2] * z) + m[3];
507 transformed[Y] = (m[4] * x) + (m[5] * y) + (m[6] * z) + m[7]; 520 transformed[Y] = (m[4] * x) + (m[5] * y) + (m[6] * z) + m[7];
508 transformed[Z] = (m[8] * x) + (m[9] * y) + (m[10] * z) + m[11]; 521 transformed[Z] = (m[8] * x) + (m[9] * y) + (m[10] * z) + m[11];
509 522
510 double rx = (((transformed[axisX] * negXFac) + m_virtWidth + m_panX) * m_width) / (2 * m_virtWidth); 523 double rx = (((transformed[axisX] * negXFac) + m_virtWidth + pan (X)) * m_width) / (2 * m_virtWidth);
511 double ry = (((transformed[axisY] * negYFac) - m_virtHeight + m_panY) * m_height) / (2 * m_virtHeight); 524 double ry = (((transformed[axisY] * negYFac) - m_virtHeight + pan (Y)) * m_height) / (2 * m_virtHeight);
512 525
513 return QPoint (rx, -ry); 526 return QPoint (rx, -ry);
514 } 527 }
515 528
516 // ============================================================================= 529 // =============================================================================
1082 const bool left = ev->buttons() & Qt::LeftButton, 1095 const bool left = ev->buttons() & Qt::LeftButton,
1083 mid = ev->buttons() & Qt::MidButton, 1096 mid = ev->buttons() & Qt::MidButton,
1084 shift = ev->modifiers() & Qt::ShiftModifier; 1097 shift = ev->modifiers() & Qt::ShiftModifier;
1085 1098
1086 if (mid || (left && shift)) 1099 if (mid || (left && shift))
1087 { m_panX += 0.03f * dx * (zoom() / 7.5f); 1100 { pan (X) += 0.03f * dx * (zoom() / 7.5f);
1088 m_panY -= 0.03f * dy * (zoom() / 7.5f); 1101 pan (Y) -= 0.03f * dy * (zoom() / 7.5f);
1089 m_panning = true; 1102 m_panning = true;
1090 } elif (left && !m_rangepick && camera() == Free) 1103 } elif (left && !m_rangepick && camera() == Free)
1091 { m_rotX = m_rotX + (dy); 1104 { rot (X) = rot (X) + dy;
1092 m_rotY = m_rotY + (dx); 1105 rot (Y) = rot (Y) + dx;
1093 1106
1094 clampAngle (m_rotX); 1107 clampAngle (rot (X));
1095 clampAngle (m_rotY); 1108 clampAngle (rot (Y));
1096 } 1109 }
1097 1110
1098 // Start the tool tip timer 1111 // Start the tool tip timer
1099 if (!m_drawToolTip) 1112 if (!m_drawToolTip)
1100 m_toolTipTimer->start (500); 1113 m_toolTipTimer->start (500);
1128 // ----------------------------------------------------------------------------- 1141 // -----------------------------------------------------------------------------
1129 void GLRenderer::wheelEvent (QWheelEvent* ev) 1142 void GLRenderer::wheelEvent (QWheelEvent* ev)
1130 { makeCurrent(); 1143 { makeCurrent();
1131 1144
1132 zoomNotch (ev->delta() > 0); 1145 zoomNotch (ev->delta() > 0);
1133 setZoom (clamp<double> (zoom(), 0.01f, 10000.0f)); 1146 zoom() = clamp (zoom(), 0.01, 10000.0);
1134 1147
1135 update(); 1148 update();
1136 ev->accept(); 1149 ev->accept();
1137 } 1150 }
1138 1151
1737 1750
1738 // ============================================================================= 1751 // =============================================================================
1739 // ----------------------------------------------------------------------------- 1752 // -----------------------------------------------------------------------------
1740 void GLRenderer::zoomNotch (bool inward) 1753 void GLRenderer::zoomNotch (bool inward)
1741 { if (zoom() > 15) 1754 { if (zoom() > 15)
1742 setZoom (zoom() * (inward ? 0.833f : 1.2f)); 1755 zoom() *= inward ? 0.833f : 1.2f;
1743 else 1756 else
1744 setZoom (zoom() + (inward ? -1.2f : 1.2f)); 1757 zoom() += inward ? -1.2f : 1.2f;
1745 } 1758 }
1746 1759
1747 // ============================================================================= 1760 // =============================================================================
1748 // ----------------------------------------------------------------------------- 1761 // -----------------------------------------------------------------------------
1749 void GLRenderer::zoomToFit() 1762 void GLRenderer::zoomToFit()
1750 { if (file() == null || m_width == -1 || m_height == -1) 1763 { if (file() == null || m_width == -1 || m_height == -1)
1751 { setZoom (30.0f); 1764 { zoom() = 30.0f;
1752 return; 1765 return;
1753 } 1766 }
1754 1767
1755 bool lastfilled = false; 1768 bool lastfilled = false;
1756 bool firstrun = true; 1769 bool firstrun = true;
1764 // Use the pick list while drawing the scene, this way we can tell whether borders 1777 // Use the pick list while drawing the scene, this way we can tell whether borders
1765 // are background or not. 1778 // are background or not.
1766 m_picking = true; 1779 m_picking = true;
1767 1780
1768 for (;;) 1781 for (;;)
1769 { if (zoom() > 10000.0f || zoom() < 0.0f) 1782 { if (zoom() > 10000.0 || zoom() < 0.0)
1770 { // Obviously, there's nothing to draw if we get here. 1783 { // Obviously, there's nothing to draw if we get here.
1771 // Default to 30.0f and break out. 1784 // Default to 30.0f and break out.
1772 setZoom (30.0f); 1785 zoom() = 30.0;
1773 break; 1786 break;
1774 } 1787 }
1775 1788
1776 zoomNotch (inward); 1789 zoomNotch (inward);
1777 1790
1819 lastfilled = filled; 1832 lastfilled = filled;
1820 } 1833 }
1821 1834
1822 setBackground(); 1835 setBackground();
1823 m_picking = false; 1836 m_picking = false;
1837 }
1838
1839 // =============================================================================
1840 // -----------------------------------------------------------------------------
1841 void GLRenderer::zoomAllToFit()
1842 { Camera oldcam = camera();
1843
1844 for (int i = 0; i < 7; ++i)
1845 { setCamera ((Camera) i);
1846 zoomToFit();
1847 }
1848
1849 setCamera (oldcam);
1824 } 1850 }
1825 1851
1826 // ============================================================================= 1852 // =============================================================================
1827 // ----------------------------------------------------------------------------- 1853 // -----------------------------------------------------------------------------
1828 void GLRenderer::updateRectVerts() 1854 void GLRenderer::updateRectVerts()

mercurial