108 m_panning = false; |
108 m_panning = false; |
109 m_compiler = new GLCompiler (this); |
109 m_compiler = new GLCompiler (this); |
110 setDrawOnly (false); |
110 setDrawOnly (false); |
111 setMessageLog (null); |
111 setMessageLog (null); |
112 m_width = m_height = -1; |
112 m_width = m_height = -1; |
113 m_position3D = g_origin; |
113 m_position3D = Origin; |
114 m_toolTipTimer = new QTimer (this); |
114 m_toolTipTimer = new QTimer (this); |
115 m_toolTipTimer->setSingleShot (true); |
115 m_toolTipTimer->setSingleShot (true); |
116 m_isCameraMoving = false; |
116 m_isCameraMoving = false; |
117 m_thinBorderPen = QPen (QColor (0, 0, 0, 208), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); |
117 m_thinBorderPen = QPen (QColor (0, 0, 0, 208), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); |
118 m_thinBorderPen.setWidth (1); |
118 m_thinBorderPen.setWidth (1); |
146 |
146 |
147 m_compiler->setRenderer (null); |
147 m_compiler->setRenderer (null); |
148 delete m_compiler; |
148 delete m_compiler; |
149 delete m_editmode; |
149 delete m_editmode; |
150 |
150 |
151 glDeleteBuffers (1, &_axesVBO); |
151 glDeleteBuffers (1, &m_axesVBO); |
152 glDeleteBuffers (1, &_axesColorVBO); |
152 glDeleteBuffers (1, &m_axesColorVBO); |
153 } |
153 } |
154 |
154 |
155 // ============================================================================= |
155 // ============================================================================= |
156 // Calculates the "hitboxes" of the camera icons so that we can tell when the |
156 // Calculates the "hitboxes" of the camera icons so that we can tell when the |
157 // cursor is pointing at the camera icon. |
157 // cursor is pointing at the camera icon. |
278 colordata[(i * 6) + (j * 3) + 1] = g_GLAxes[i].col.green(); |
278 colordata[(i * 6) + (j * 3) + 1] = g_GLAxes[i].col.green(); |
279 colordata[(i * 6) + (j * 3) + 2] = g_GLAxes[i].col.blue(); |
279 colordata[(i * 6) + (j * 3) + 2] = g_GLAxes[i].col.blue(); |
280 } |
280 } |
281 } |
281 } |
282 |
282 |
283 glGenBuffers (1, &_axesVBO); |
283 glGenBuffers (1, &m_axesVBO); |
284 glBindBuffer (GL_ARRAY_BUFFER, _axesVBO); |
284 glBindBuffer (GL_ARRAY_BUFFER, m_axesVBO); |
285 glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW); |
285 glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW); |
286 glGenBuffers (1, &_axesColorVBO); |
286 glGenBuffers (1, &m_axesColorVBO); |
287 glBindBuffer (GL_ARRAY_BUFFER, _axesColorVBO); |
287 glBindBuffer (GL_ARRAY_BUFFER, m_axesColorVBO); |
288 glBufferData (GL_ARRAY_BUFFER, sizeof colordata, colordata, GL_STATIC_DRAW); |
288 glBufferData (GL_ARRAY_BUFFER, sizeof colordata, colordata, GL_STATIC_DRAW); |
289 glBindBuffer (GL_ARRAY_BUFFER, 0); |
289 glBindBuffer (GL_ARRAY_BUFFER, 0); |
290 } |
290 } |
291 |
291 |
292 // ============================================================================= |
292 // ============================================================================= |
458 drawVBOs (VBOSF_CondLines, VBOCM_NormalColors, GL_LINES); |
458 drawVBOs (VBOSF_CondLines, VBOCM_NormalColors, GL_LINES); |
459 glDisable (GL_LINE_STIPPLE); |
459 glDisable (GL_LINE_STIPPLE); |
460 |
460 |
461 if (cfg::DrawAxes) |
461 if (cfg::DrawAxes) |
462 { |
462 { |
463 glBindBuffer (GL_ARRAY_BUFFER, _axesVBO); |
463 glBindBuffer (GL_ARRAY_BUFFER, m_axesVBO); |
464 glVertexPointer (3, GL_FLOAT, 0, NULL); |
464 glVertexPointer (3, GL_FLOAT, 0, NULL); |
465 glBindBuffer (GL_ARRAY_BUFFER, _axesVBO); |
465 glBindBuffer (GL_ARRAY_BUFFER, m_axesVBO); |
466 glColorPointer (3, GL_FLOAT, 0, NULL); |
466 glColorPointer (3, GL_FLOAT, 0, NULL); |
467 glDrawArrays (GL_LINES, 0, 6); |
467 glDrawArrays (GL_LINES, 0, 6); |
468 checkGLError(); |
468 CHECK_GL_ERROR(); |
469 } |
469 } |
470 } |
470 } |
471 |
471 |
472 glPopMatrix(); |
472 glPopMatrix(); |
473 glBindBuffer (GL_ARRAY_BUFFER, 0); |
473 glBindBuffer (GL_ARRAY_BUFFER, 0); |
474 glDisableClientState (GL_VERTEX_ARRAY); |
474 glDisableClientState (GL_VERTEX_ARRAY); |
475 glDisableClientState (GL_COLOR_ARRAY); |
475 glDisableClientState (GL_COLOR_ARRAY); |
476 checkGLError(); |
476 CHECK_GL_ERROR(); |
477 glDisable (GL_CULL_FACE); |
477 glDisable (GL_CULL_FACE); |
478 glMatrixMode (GL_MODELVIEW); |
478 glMatrixMode (GL_MODELVIEW); |
479 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
479 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); |
480 } |
480 } |
481 |
481 |
482 // ============================================================================= |
482 // ============================================================================= |
483 // |
483 // |
484 void GLRenderer::drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type) |
484 void GLRenderer::drawVBOs (EVBOSurface surface, EVBOComplement colors, GLenum type) |
485 { |
485 { |
486 // Filter this through some configuration options |
486 // Filter this through some configuration options |
487 if ((eq (surface, VBOSF_Quads, VBOSF_Triangles) and cfg::DrawSurfaces == false) or |
487 if ((Eq (surface, VBOSF_Quads, VBOSF_Triangles) and cfg::DrawSurfaces == false) or |
488 (surface == VBOSF_Lines and cfg::DrawEdgeLines == false) or |
488 (surface == VBOSF_Lines and cfg::DrawEdgeLines == false) or |
489 (surface == VBOSF_CondLines and cfg::DrawConditionalLines == false)) |
489 (surface == VBOSF_CondLines and cfg::DrawConditionalLines == false)) |
490 { |
490 { |
491 return; |
491 return; |
492 } |
492 } |
501 |
501 |
502 if (count > 0) |
502 if (count > 0) |
503 { |
503 { |
504 glBindBuffer (GL_ARRAY_BUFFER, surfacevbo); |
504 glBindBuffer (GL_ARRAY_BUFFER, surfacevbo); |
505 glVertexPointer (3, GL_FLOAT, 0, null); |
505 glVertexPointer (3, GL_FLOAT, 0, null); |
506 checkGLError(); |
506 CHECK_GL_ERROR(); |
507 glBindBuffer (GL_ARRAY_BUFFER, colorvbo); |
507 glBindBuffer (GL_ARRAY_BUFFER, colorvbo); |
508 glColorPointer (4, GL_FLOAT, 0, null); |
508 glColorPointer (4, GL_FLOAT, 0, null); |
509 checkGLError(); |
509 CHECK_GL_ERROR(); |
510 glDrawArrays (type, 0, count); |
510 glDrawArrays (type, 0, count); |
511 checkGLError(); |
511 CHECK_GL_ERROR(); |
512 } |
512 } |
513 } |
513 } |
514 |
514 |
515 // ============================================================================= |
515 // ============================================================================= |
516 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |
516 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' |
632 if (overlay.img != null) |
632 if (overlay.img != null) |
633 { |
633 { |
634 QPoint v0 = coordconv3_2 (currentDocumentData().overlays[camera()].v0), |
634 QPoint v0 = coordconv3_2 (currentDocumentData().overlays[camera()].v0), |
635 v1 = coordconv3_2 (currentDocumentData().overlays[camera()].v1); |
635 v1 = coordconv3_2 (currentDocumentData().overlays[camera()].v1); |
636 |
636 |
637 QRect targRect (v0.x(), v0.y(), abs (v1.x() - v0.x()), abs (v1.y() - v0.y())), |
637 QRect targRect (v0.x(), v0.y(), Abs (v1.x() - v0.x()), Abs (v1.y() - v0.y())), |
638 srcRect (0, 0, overlay.img->width(), overlay.img->height()); |
638 srcRect (0, 0, overlay.img->width(), overlay.img->height()); |
639 paint.drawImage (targRect, *overlay.img, srcRect); |
639 paint.drawImage (targRect, *overlay.img, srcRect); |
640 } |
640 } |
641 |
641 |
642 // Paint the coordinates onto the screen. |
642 // Paint the coordinates onto the screen. |
792 // |
792 // |
793 void GLRenderer::mouseMoveEvent (QMouseEvent* ev) |
793 void GLRenderer::mouseMoveEvent (QMouseEvent* ev) |
794 { |
794 { |
795 int dx = ev->x() - m_mousePosition.x(); |
795 int dx = ev->x() - m_mousePosition.x(); |
796 int dy = ev->y() - m_mousePosition.y(); |
796 int dy = ev->y() - m_mousePosition.y(); |
797 m_totalmove += abs (dx) + abs (dy); |
797 m_totalmove += Abs (dx) + Abs (dy); |
798 setCameraMoving (false); |
798 setCameraMoving (false); |
799 |
799 |
800 if (not m_editmode->mouseMoved (ev)) |
800 if (not m_editmode->mouseMoved (ev)) |
801 { |
801 { |
802 const bool left = ev->buttons() & Qt::LeftButton, |
802 const bool left = ev->buttons() & Qt::LeftButton, |
828 // Update 2d position |
828 // Update 2d position |
829 m_mousePosition = ev->pos(); |
829 m_mousePosition = ev->pos(); |
830 m_globalpos = ev->globalPos(); |
830 m_globalpos = ev->globalPos(); |
831 |
831 |
832 // Calculate 3d position of the cursor |
832 // Calculate 3d position of the cursor |
833 m_position3D = (camera() != EFreeCamera) ? coordconv2_3 (m_mousePosition, true) : g_origin; |
833 m_position3D = (camera() != EFreeCamera) ? coordconv2_3 (m_mousePosition, true) : Origin; |
834 |
834 |
835 highlightCursorObject(); |
835 highlightCursorObject(); |
836 update(); |
836 update(); |
837 ev->accept(); |
837 ev->accept(); |
838 } |
838 } |
925 int y0 = range.top(); |
925 int y0 = range.top(); |
926 int x1 = x0 + range.width(); |
926 int x1 = x0 + range.width(); |
927 int y1 = y0 + range.height(); |
927 int y1 = y0 + range.height(); |
928 |
928 |
929 // Clamp the values to ensure they're within bounds |
929 // Clamp the values to ensure they're within bounds |
930 x0 = max (0, x0); |
930 x0 = Max (0, x0); |
931 y0 = max (0, y0); |
931 y0 = Max (0, y0); |
932 x1 = min (x1, m_width); |
932 x1 = Min (x1, m_width); |
933 y1 = min (y1, m_height); |
933 y1 = Min (y1, m_height); |
934 const int areawidth = (x1 - x0); |
934 const int areawidth = (x1 - x0); |
935 const int areaheight = (y1 - y0); |
935 const int areaheight = (y1 - y0); |
936 const qint32 numpixels = areawidth * areaheight; |
936 const qint32 numpixels = areawidth * areaheight; |
937 |
937 |
938 // Allocate space for the pixel data. |
938 // Allocate space for the pixel data. |
1220 const Axis x2d = getCameraAxis (false, cam), |
1220 const Axis x2d = getCameraAxis (false, cam), |
1221 y2d = getCameraAxis (true, cam); |
1221 y2d = getCameraAxis (true, cam); |
1222 const double negXFac = g_FixedCameras[cam].negX ? -1 : 1, |
1222 const double negXFac = g_FixedCameras[cam].negX ? -1 : 1, |
1223 negYFac = g_FixedCameras[cam].negY ? -1 : 1; |
1223 negYFac = g_FixedCameras[cam].negY ? -1 : 1; |
1224 |
1224 |
1225 info.v0 = info.v1 = g_origin; |
1225 info.v0 = info.v1 = Origin; |
1226 info.v0.setCoordinate (x2d, -(info.ox * info.lw * negXFac) / img->width()); |
1226 info.v0.setCoordinate (x2d, -(info.ox * info.lw * negXFac) / img->width()); |
1227 info.v0.setCoordinate (y2d, (info.oy * info.lh * negYFac) / img->height()); |
1227 info.v0.setCoordinate (y2d, (info.oy * info.lh * negYFac) / img->height()); |
1228 info.v1.setCoordinate (x2d, info.v0[x2d] + info.lw); |
1228 info.v1.setCoordinate (x2d, info.v0[x2d] + info.lw); |
1229 info.v1.setCoordinate (y2d, info.v0[y2d] + info.lh); |
1229 info.v1.setCoordinate (y2d, info.v0[y2d] + info.lh); |
1230 |
1230 |
1486 } |
1486 } |
1487 elif (meta.img != null and ovlobj == null) |
1487 elif (meta.img != null and ovlobj == null) |
1488 { |
1488 { |
1489 // Inverse case: image is there but the overlay object is |
1489 // Inverse case: image is there but the overlay object is |
1490 // not, thus create the object. |
1490 // not, thus create the object. |
1491 ovlobj = spawn<LDOverlay>(); |
1491 ovlobj = LDSpawn<LDOverlay>(); |
1492 |
1492 |
1493 // Find a suitable position to place this object. We want to place |
1493 // Find a suitable position to place this object. We want to place |
1494 // this into the header, which is everything up to the first scemantic |
1494 // this into the header, which is everything up to the first scemantic |
1495 // object. If we find another overlay object, place this object after |
1495 // object. If we find another overlay object, place this object after |
1496 // the last one found. Otherwise, place it before the first schemantic |
1496 // the last one found. Otherwise, place it before the first schemantic |
1591 void GLRenderer::dropEvent (QDropEvent* ev) |
1591 void GLRenderer::dropEvent (QDropEvent* ev) |
1592 { |
1592 { |
1593 if (g_win != null and ev->source() == g_win->getPrimitivesTree()) |
1593 if (g_win != null and ev->source() == g_win->getPrimitivesTree()) |
1594 { |
1594 { |
1595 QString primName = static_cast<SubfileListItem*> (g_win->getPrimitivesTree()->currentItem())->primitive()->name; |
1595 QString primName = static_cast<SubfileListItem*> (g_win->getPrimitivesTree()->currentItem())->primitive()->name; |
1596 LDSubfilePtr ref = spawn<LDSubfile>(); |
1596 LDSubfilePtr ref = LDSpawn<LDSubfile>(); |
1597 ref->setColor (maincolor()); |
1597 ref->setColor (MainColor()); |
1598 ref->setFileInfo (getDocument (primName)); |
1598 ref->setFileInfo (GetDocument (primName)); |
1599 ref->setPosition (g_origin); |
1599 ref->setPosition (Origin); |
1600 ref->setTransform (g_identity); |
1600 ref->setTransform (IdentityMatrix); |
1601 LDDocument::current()->insertObj (g_win->getInsertionPoint(), ref); |
1601 LDDocument::current()->insertObj (g_win->getInsertionPoint(), ref); |
1602 ref->select(); |
1602 ref->select(); |
1603 g_win->buildObjList(); |
1603 g_win->buildObjList(); |
1604 g_win->R()->refresh(); |
1604 g_win->R()->refresh(); |
1605 ev->acceptProposedAction(); |
1605 ev->acceptProposedAction(); |