src/gl/axesprogram.cpp

Mon, 20 Jun 2022 21:49:39 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 20 Jun 2022 21:49:39 +0300
changeset 240
414d392b9ae6
parent 234
87ee9824210b
child 245
a41ccc6924e3
permissions
-rw-r--r--

some improvements to dock widget handling

69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 * Copyright (C) 2020 Teemu Piippo
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
234
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
19 #include <QPainter>
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
20 #include <QPainterPath>
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
21 #include "axesprogram.h"
234
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
22 #include "gl/partrenderer.h"
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
24 static constexpr char vertexShaderSource[] = R"(
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 #version 330 core
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 layout (location = 0) in vec3 in_position;
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 layout (location = 1) in vec3 in_color;
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
29 uniform mat4 mvp;
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 smooth out vec3 ex_color;
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 void main()
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
34 gl_Position = mvp * vec4(in_position, 1.0);
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
35 ex_color = in_color;
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 }
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 )";
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
39 static constexpr char fragmentShaderSource[] = R"(
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 #version 330 core
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 out vec4 color;
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 smooth in vec3 ex_color;
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 void main(void)
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
70
f21b800b02a4 Added axes rendering
Teemu Piippo <teemu@hecknology.net>
parents: 69
diff changeset
47 color = vec4(ex_color, 1);
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 }
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 )";
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
51 void AxesLayer::initializeGL()
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 {
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
53 constexpr struct VertexType
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 {
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 glm::vec3 position;
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 glm::vec3 color;
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
57 } data[] = {
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
58 {{10000, 0, 0}, {1, 0, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
59 {{0, 0, 0}, {1, 0, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
60 {{-10000, 0, 0}, {0.5, 0, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
61 {{0, 0, 0}, {0.5, 0, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
62 {{0, 10000, 0}, {0, 1, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
63 {{0, 0, 0}, {0, 1, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
64 {{0, -10000, 0}, {0, 0.5, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
65 {{0, 0, 0}, {0, 0.5, 0}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
66 {{0, 0, 10000}, {0, 0, 1}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
67 {{0, 0, 0}, {0, 0, 1}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
68 {{0, 0, -10000}, {0, 0, 0.5}},
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
69 {{0, 0, 0}, {0, 0, 0.5}},
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 };
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
71 constexpr int stride = sizeof(VertexType);
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
72 this->shader.initialize(
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
73 ::vertexShaderSource,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
74 ::fragmentShaderSource,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
75 QOpenGLBuffer::StaticDraw,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
76 {
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
77 GLAttributeSpec{
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
78 .type = GL_FLOAT,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
79 .offset = offsetof(VertexType, position),
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
80 .tuplesize = 3,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
81 .stride = stride,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
82 },
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
83 {
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
84 .type = GL_FLOAT,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
85 .offset = offsetof(VertexType, color),
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
86 .tuplesize = 3,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
87 .stride = stride,
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
88 },
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
89 });
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
90 this->shader.bufferData(&data[0], countof(data), sizeof data[0]);
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 }
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92
234
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
93 void drawBorderedText(QPainter* painter, const QPointF& point, const QFont& font, const QString& text)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
94 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
95 QPainterPath path;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
96 path.addText(point, font, text);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
97 painter->save();
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
98 painter->setBrush(Qt::white);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
99 painter->setPen({Qt::black, 0.1 * font.pointSizeF()});
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
100 painter->drawPath(path);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
101 painter->restore();
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
102 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
103
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
104 void AxesLayer::overpaint(QPainter* painter)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
105 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
106 QFont font;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
107 font.setStyle(QFont::StyleItalic);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
108 font.setBold(true);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
109 painter->setFont(font);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
110 QFontMetrics fontMetrics{font};
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
111 const auto renderText = [&](const QString& text, const PointOnRectagle& intersection)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
112 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
113 QPointF position = toQPointF(intersection.position);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
114 const RectangleSide side = intersection.side;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
115 switch (side)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
116 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
117 case RectangleSide::Top:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
118 position += QPointF{0, static_cast<qreal>(fontMetrics.ascent())};
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
119 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
120 case RectangleSide::Left:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
121 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
122 case RectangleSide::Bottom:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
123 position += QPointF{0, static_cast<qreal>(-fontMetrics.descent())};
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
124 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
125 case RectangleSide::Right:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
126 position += QPointF{static_cast<qreal>(-fontMetrics.horizontalAdvance(text)), 0};
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
127 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
128 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
129 drawBorderedText(painter, position, font, text);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
130 };
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
131 const QRectF box {QPointF{0, 0}, sizeToSizeF(this->renderer->size())};
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
132 const QPointF p1 = this->renderer->modelToScreenCoordinates(glm::vec3{0, 0, 0});
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
133 static const struct
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
134 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
135 QString text;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
136 glm::vec3 direction;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
137 } directions[] =
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
138 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
139 {"+x", {1, 0, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
140 {"-x", {-1, 0, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
141 {"+y", {0, 1, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
142 {"-y", {0, -1, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
143 {"+z", {0, 0, 1}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
144 {"-z", {0, 0, -1}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
145 };
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
146 for (const auto& axis : directions)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
147 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
148 const QPointF x_p = this->renderer->modelToScreenCoordinates(axis.direction);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
149 const auto intersection = rayRectangleIntersection(
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
150 rayFromPoints(toVec2(p1), toVec2(x_p)),
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
151 box);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
152 if (intersection.has_value())
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
153 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
154 renderText(axis.text, *intersection);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
155 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
156 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
157 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
158
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
159 void AxesLayer::paintGL()
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160 {
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
161 glLineWidth(5);
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
162 glEnable(GL_LINE_SMOOTH);
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
163 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
164 this->shader.draw(GL_LINES);
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
165 glDisable(GL_LINE_SMOOTH);
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
166 }
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
167
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
168 void AxesLayer::mvpMatrixChanged(const glm::mat4& mvpMatrix)
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
169 {
215
34c6e7bc4ee1 Reimplement the axes program as a layer that can be added to PartRenderer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 118
diff changeset
170 this->shader.setMvpMatrix(mvpMatrix);
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
171 }

mercurial