Thu, 11 Jan 2018 22:21:50 +0200
things
src/glcamera.cpp | file | annotate | diff | comparison | revisions | |
src/glcamera.h | file | annotate | diff | comparison | revisions | |
src/glrenderer.cpp | file | annotate | diff | comparison | revisions |
--- a/src/glcamera.cpp Sun Mar 05 01:57:56 2017 +0200 +++ b/src/glcamera.cpp Thu Jan 11 22:21:50 2018 +0200 @@ -96,7 +96,16 @@ } else { - Vertex position3d; + GLRotationMatrix panningMatrix = { + 1, 0, 0, float(panningX()), + 0, 1, 0, float(panningY()), + 0, 0, 1, float(zoom()), + 0, 0, 0, 1 + }; + GLRotationMatrix matrix = (m_rotationMatrix * panningMatrix).inverted(); + QVector3D position3d = {float(position2d.x()), float(position2d.y()), 0}; + return matrix.map(position3d); + int signX = m_negatedX ? -1 : 1; int signY = m_negatedY ? -1 : 1; @@ -116,9 +125,11 @@ roundToDecimals(cy, 4); // Create the vertex from the coordinates + /* position3d.setCoordinate(axisX(), cx * signX); position3d.setCoordinate(axisY(), cy * signY); position3d.setCoordinate(axisZ(), m_depth); + */ return position3d; } } @@ -275,3 +286,23 @@ // The adapter matrix would be inverted here, but it is its own inverse so let's not bother. return idealCoordinates.transformed(ldrawToIdealAdapterMatrix).transformed(m_rotationMatrix.inverted()); } + +GLRotationMatrix GLCamera::realMatrix() const +{ + GLRotationMatrix result; + glPushMatrix(); + glLoadIdentity(); + glOrtho( + -m_virtualSize.width(), + +m_virtualSize.width(), + -m_virtualSize.height(), + +m_virtualSize.height(), + -1000.0f, + 1000.0f); + glTranslatef(m_panningX, m_panningY, 0.0f); + glMultMatrixf(m_rotationMatrix); + glMultMatrixf(GLRenderer::ldrawToGLAdapterMatrix); + glGetFloatv(GL_MODELVIEW_MATRIX, result.data()); + glPopMatrix(); + return result; +}
--- a/src/glcamera.h Sun Mar 05 01:57:56 2017 +0200 +++ b/src/glcamera.h Thu Jan 11 22:21:50 2018 +0200 @@ -66,6 +66,7 @@ const QSizeF& virtualSize() const; double zoom() const; void zoomNotch(bool inward); + GLRotationMatrix realMatrix() const; private: QString m_name;
--- a/src/glrenderer.cpp Sun Mar 05 01:57:56 2017 +0200 +++ b/src/glrenderer.cpp Thu Jan 11 22:21:50 2018 +0200 @@ -35,18 +35,53 @@ #include "documentmanager.h" #include "grid.h" -const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; +const QPen GLRenderer::thinBorderPen { + QColor {0, 0, 0, 208}, + 1, + Qt::SolidLine, + Qt::RoundCap, + Qt::RoundJoin +}; // Transformation matrices for the fixed cameras. const GLRotationMatrix GLRenderer::topCameraMatrix = GLRotationMatrix {}; -const GLRotationMatrix GLRenderer::frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; -const GLRotationMatrix GLRenderer::leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; -const GLRotationMatrix GLRenderer::bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; -const GLRotationMatrix GLRenderer::backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; -const GLRotationMatrix GLRenderer::rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; + +const GLRotationMatrix GLRenderer::frontCameraMatrix = { + 1, 0, 0, 0, + 0, 0, 1, 0, + 0, -1, 0, 0, + 0, 0, 0, 1}; + +const GLRotationMatrix GLRenderer::leftCameraMatrix = { + 0, -1, 0, 0, + 0, 0, 1, 0, + -1, 0, 0, 0, + 0, 0, 0, 1}; + +const GLRotationMatrix GLRenderer::bottomCameraMatrix = { + 1, 0, 0, 0, + 0, -1, 0, 0, + 0, 0, -1, 0, + 0, 0, 0, 1}; + +const GLRotationMatrix GLRenderer::backCameraMatrix = { + -1, 0, 0, 0, + 0, 0, 1, 0, + 0, 1, 0, 0, + 0, 0, 0, 1}; + +const GLRotationMatrix GLRenderer::rightCameraMatrix = { + 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 0, 0, 0, + 0, 0, 0, 1}; // Conversion matrix from LDraw to OpenGL coordinates. -const GLRotationMatrix GLRenderer::ldrawToGLAdapterMatrix = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; +const GLRotationMatrix GLRenderer::ldrawToGLAdapterMatrix = { + 1, 0, 0, 0, + 0, 0, -1, 0, + 0, 1, 0, 0, + 0, 0, 0, 1}; /* * Constructs a GL renderer.