feat: Add X, Y, Z labels to ViewCube axes

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-18 17:44:09 -07:00
parent c0cb427cf1
commit 48b547f4da
2 changed files with 51 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
#include <QScreen> #include <QScreen>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QVector> #include <QVector>
#include <QVector3D>
namespace namespace
{ {
@@ -74,6 +75,35 @@ void ViewCube::paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColor
drawViewCube(viewCubeProjection, viewMatrix, opacity); drawViewCube(viewCubeProjection, viewMatrix, opacity);
drawAxes(simpleShader, simpleShaderColorLoc, viewCubeProjection, viewMatrix); drawAxes(simpleShader, simpleShaderColorLoc, viewCubeProjection, viewMatrix);
QMatrix4x4 mvp = viewCubeProjection * viewMatrix;
const float axisLen = 1.7f;
QVector3D xAxisEnd(axisLen, 0.0f, 0.0f);
QVector3D yAxisEnd(0.0f, 0.0f, axisLen);
QVector3D zAxisEnd(0.0f, axisLen, 0.0f);
QVector3D xAxisNdc = mvp.map(xAxisEnd);
QVector3D yAxisNdc = mvp.map(yAxisEnd);
QVector3D zAxisNdc = mvp.map(zAxisEnd);
const int vpX = width - viewCubeSize;
const int vpY = height - viewCubeSize;
const int vpW = viewCubeSize;
const int vpH = viewCubeSize;
const float dpr = QGuiApplication::primaryScreen()->devicePixelRatio();
m_xAxisLabelPos.setX( (xAxisNdc.x() + 1.0f) * vpW / 2.0f + vpX );
m_xAxisLabelPos.setY( (1.0f - xAxisNdc.y()) * vpH / 2.0f + vpY );
m_xAxisLabelPos /= dpr;
m_yAxisLabelPos.setX( (yAxisNdc.x() + 1.0f) * vpW / 2.0f + vpX );
m_yAxisLabelPos.setY( (1.0f - yAxisNdc.y()) * vpH / 2.0f + vpY );
m_yAxisLabelPos /= dpr;
m_zAxisLabelPos.setX( (zAxisNdc.x() + 1.0f) * vpW / 2.0f + vpX );
m_zAxisLabelPos.setY( (1.0f - zAxisNdc.y()) * vpH / 2.0f + vpY );
m_zAxisLabelPos /= dpr;
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
@@ -229,6 +259,23 @@ void ViewCube::drawAxes(QOpenGLShaderProgram* simpleShader, int colorLoc, const
void ViewCube::paint2D(QPainter& painter, int widgetWidth, int widgetHeight) void ViewCube::paint2D(QPainter& painter, int widgetWidth, int widgetHeight)
{ {
QFont font("Arial", 10, QFont::Bold);
painter.setFont(font);
painter.setPen(Qt::black);
QFontMetrics fm(font);
QRect xRect = fm.boundingRect("X");
xRect.moveCenter(m_xAxisLabelPos);
painter.drawText(xRect, Qt::AlignCenter, "X");
QRect yRect = fm.boundingRect("Y");
yRect.moveCenter(m_yAxisLabelPos);
painter.drawText(yRect, Qt::AlignCenter, "Y");
QRect zRect = fm.boundingRect("Z");
zRect.moveCenter(m_zAxisLabelPos);
painter.drawText(zRect, Qt::AlignCenter, "Z");
if (!m_isHovered) { if (!m_isHovered) {
return; return;
} }

View File

@@ -34,6 +34,10 @@ private:
QRect m_homeButtonRect; QRect m_homeButtonRect;
QSvgRenderer* m_homeButtonRenderer = nullptr; QSvgRenderer* m_homeButtonRenderer = nullptr;
QPoint m_xAxisLabelPos;
QPoint m_yAxisLabelPos;
QPoint m_zAxisLabelPos;
QOpenGLTexture* m_faceTextures[6]; QOpenGLTexture* m_faceTextures[6];
QOpenGLShaderProgram* m_textureShaderProgram = nullptr; QOpenGLShaderProgram* m_textureShaderProgram = nullptr;