Fri, 03 Mar 2017 23:08:04 +0200
At long last, the grid is finally now rendered onto the viewport. Woop!
src/basics.h | file | annotate | diff | comparison | revisions | |
src/canvas.cpp | file | annotate | diff | comparison | revisions | |
src/canvas.h | file | annotate | diff | comparison | revisions | |
src/glShared.h | file | annotate | diff | comparison | revisions | |
src/glcamera.cpp | file | annotate | diff | comparison | revisions | |
src/glrenderer.cpp | file | annotate | diff | comparison | revisions | |
src/glrenderer.h | file | annotate | diff | comparison | revisions |
--- a/src/basics.h Fri Mar 03 00:35:43 2017 +0200 +++ b/src/basics.h Fri Mar 03 23:08:04 2017 +0200 @@ -315,3 +315,15 @@ { return ring.size(); } + +/* + * Extracts the sign of x. + */ +template<typename T> +T sign(T x) +{ + if (isZero(x)) + return {}; + else + return x / qAbs(x); +}
--- a/src/canvas.cpp Fri Mar 03 00:35:43 2017 +0200 +++ b/src/canvas.cpp Fri Mar 03 23:08:04 2017 +0200 @@ -90,6 +90,59 @@ } } +/* + * Assuming we're currently viewing from a fixed camera, draw a backdrop into it. Currently this means drawing the grid. + */ +void Canvas::drawFixedCameraBackdrop() +{ + // Find the top left corner of the grid + Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); + Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); + qreal gridSize = grid()->coordinateSnap(); + qreal x0 = sign(topLeft.x()) * (fabs(topLeft.x()) - fmod(fabs(topLeft.x()), gridSize)); + qreal y0 = sign(topLeft.y()) * (fabs(topLeft.y()) - fmod(fabs(topLeft.y()), gridSize)); + glEnable(GL_LINE_STIPPLE); + glBegin(GL_LINES); + + static const auto prepareGridLine = [](qreal value) -> bool + { + if (not isZero(value)) + { + if (isZero(fmod(value, 10.0))) + glColor4f(0, 0, 0, 0.6); + else + glColor4f(0, 0, 0, 0.25); + + return true; + } + else + { + return false; + } + }; + + for (qreal x = x0; x < bottomRight.x(); x += gridSize) + { + if (prepareGridLine(x)) + { + glVertex(currentCamera().realize({x, -10000, 999})); + glVertex(currentCamera().realize({x, 10000, 999})); + } + } + + for (qreal y = y0; y < bottomRight.y(); y += gridSize) + { + if (prepareGridLine(y)) + { + glVertex(currentCamera().realize({-10000, y, 999})); + glVertex(currentCamera().realize({10000, y, 999})); + } + } + + glEnd(); + glDisable(GL_LINE_STIPPLE); +} + bool Canvas::freeCameraAllowed() const { return m_currentEditMode->allowFreeCamera();
--- a/src/canvas.h Fri Mar 03 00:35:43 2017 +0200 +++ b/src/canvas.h Fri Mar 03 23:08:04 2017 +0200 @@ -43,6 +43,7 @@ protected: void contextMenuEvent(QContextMenuEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; + void drawFixedCameraBackdrop() override; void dropEvent(QDropEvent* event) override; bool freeCameraAllowed() const override; void keyReleaseEvent(QKeyEvent* event) override;
--- a/src/glShared.h Fri Mar 03 00:35:43 2017 +0200 +++ b/src/glShared.h Fri Mar 03 23:08:04 2017 +0200 @@ -27,6 +27,11 @@ glMultMatrixf(matrix.constData()); } +inline void glVertex(const Vertex& vertex) +{ + glVertex3f(vertex.x(), vertex.y(), vertex.z()); +} + class LDObject; struct LDPolygon
--- a/src/glcamera.cpp Fri Mar 03 00:35:43 2017 +0200 +++ b/src/glcamera.cpp Fri Mar 03 23:08:04 2017 +0200 @@ -255,7 +255,7 @@ return matrix; } -static const GLRotationMatrix ldrawToIdealAdapterMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; +static const GLRotationMatrix ldrawToIdealAdapterMatrix = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; /* * Converts from rea co-ordinates to ideal co-ordinates.
--- a/src/glrenderer.cpp Fri Mar 03 00:35:43 2017 +0200 +++ b/src/glrenderer.cpp Fri Mar 03 23:08:04 2017 +0200 @@ -381,10 +381,11 @@ glLoadIdentity(); const QSizeF& virtualSize = currentCamera().virtualSize(); - glOrtho(-virtualSize.width(), virtualSize.width(), -virtualSize.height(), virtualSize.height(), -100.0f, 100.0f); + glOrtho(-virtualSize.width(), virtualSize.width(), -virtualSize.height(), virtualSize.height(), -1000.0f, 1000.0f); glTranslatef(panning (X), panning (Y), 0.0f); glMultMatrixf(currentCamera().transformationMatrix()); glMultMatrixf(ldrawToGLAdapterMatrix); + drawFixedCameraBackdrop(); } else { @@ -1028,3 +1029,9 @@ { return m_model; } + +/* + * This virtual function lets derivative classes render something to the fixed camera + * before the main brick is rendered. + */ +void GLRenderer::drawFixedCameraBackdrop() {}
--- a/src/glrenderer.h Fri Mar 03 00:35:43 2017 +0200 +++ b/src/glrenderer.h Fri Mar 03 23:08:04 2017 +0200 @@ -87,6 +87,7 @@ protected: void initializeGL(); + virtual void drawFixedCameraBackdrop(); void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); void leaveEvent(QEvent* event);