src/layers/axeslayer.cpp

Sat, 08 Apr 2023 21:48:49 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Sat, 08 Apr 2023 21:48:49 +0300
changeset 356
65b4741b302d
parent 264
76a025db4948
child 377
e1c5e4310f8b
permissions
-rw-r--r--

Made editor font configurable
Add grid matrix editor

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>
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 263
diff changeset
21 #include "src/gl/partrenderer.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 263
diff changeset
22 #include "src/layers/axeslayer.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 AxesLayer::overpaint(QPainter* painter)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
94 {
245
a41ccc6924e3 improve text rendering
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 234
diff changeset
95 painter->save();
234
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
96 QFont font;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
97 font.setStyle(QFont::StyleItalic);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
98 font.setBold(true);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
99 painter->setFont(font);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
100 QFontMetrics fontMetrics{font};
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
101 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
102 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
103 QPointF position = toQPointF(intersection.position);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
104 const RectangleSide side = intersection.side;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
105 switch (side)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
106 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
107 case RectangleSide::Top:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
108 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
109 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
110 case RectangleSide::Left:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
111 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
112 case RectangleSide::Bottom:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
113 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
114 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
115 case RectangleSide::Right:
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
116 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
117 break;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
118 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
119 drawBorderedText(painter, position, font, text);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
120 };
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
121 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
122 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
123 static const struct
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
124 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
125 QString text;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
126 glm::vec3 direction;
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
127 } directions[] =
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 {"+x", {1, 0, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
130 {"-x", {-1, 0, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
131 {"+y", {0, 1, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
132 {"-y", {0, -1, 0}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
133 {"+z", {0, 0, 1}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
134 {"-z", {0, 0, -1}},
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
135 };
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
136 for (const auto& axis : directions)
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
137 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
138 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
139 const auto intersection = rayRectangleIntersection(
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
140 rayFromPoints(toVec2(p1), toVec2(x_p)),
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
141 box);
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
142 if (intersection.has_value())
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
143 {
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
144 renderText(axis.text, *intersection);
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 }
245
a41ccc6924e3 improve text rendering
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 234
diff changeset
147 painter->restore();
234
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
148 }
87ee9824210b Readd axis labels, fix antialiasing
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 216
diff changeset
149
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
150 void AxesLayer::paintGL()
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 {
216
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
152 glLineWidth(5);
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
153 glEnable(GL_LINE_SMOOTH);
c7241f504117 Reworked grid program into a render layer
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 215
diff changeset
154 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
155 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
156 glDisable(GL_LINE_SMOOTH);
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 }
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
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::mvpMatrixChanged(const glm::mat4& mvpMatrix)
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160 {
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
161 this->shader.setMvpMatrix(mvpMatrix);
69
a36913fc552a begin work on axes program
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162 }

mercurial