src/glRenderer.cpp

Thu, 09 Feb 2017 20:44:36 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Feb 2017 20:44:36 +0200
changeset 1113
5f3139c802bf
parent 1111
471572db2fe1
child 1116
3b1d2cc6603e
permissions
-rw-r--r--

Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1072
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1070
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
19 #define GL_GLEXT_PROTOTYPES
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
20 #include <GL/glu.h>
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
21 #include <GL/glext.h>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QContextMenuEvent>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QToolTip>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QTimer>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <GL/glu.h>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "main.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "glRenderer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "colors.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
30 #include "mainwindow.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "miscallenous.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "editHistory.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "dialogs.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
34 #include "glCompiler.h"
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
35 #include "primitives.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
36 #include "documentmanager.h"
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
37 #include "grid.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
39 const CameraInfo g_cameraInfo[EnumLimits<Camera>::Count] =
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
742
f10de1bf22e7 - vertex snapping is now smarter, does a depth compare to favor vertices closer to camera and does a short-range 2d check + out-of-range 2d check
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
41 {{ 1, 0, 0 }, X, Z, false, false, false }, // top
f10de1bf22e7 - vertex snapping is now smarter, does a depth compare to favor vertices closer to camera and does a short-range 2d check + out-of-range 2d check
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
42 {{ 0, 0, 0 }, X, Y, false, true, false }, // front
f10de1bf22e7 - vertex snapping is now smarter, does a depth compare to favor vertices closer to camera and does a short-range 2d check + out-of-range 2d check
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
43 {{ 0, 1, 0 }, Z, Y, true, true, false }, // left
f10de1bf22e7 - vertex snapping is now smarter, does a depth compare to favor vertices closer to camera and does a short-range 2d check + out-of-range 2d check
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
44 {{ -1, 0, 0 }, X, Z, false, true, true }, // bottom
f10de1bf22e7 - vertex snapping is now smarter, does a depth compare to favor vertices closer to camera and does a short-range 2d check + out-of-range 2d check
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
45 {{ 0, 0, 0 }, X, Y, true, true, true }, // back
f10de1bf22e7 - vertex snapping is now smarter, does a depth compare to favor vertices closer to camera and does a short-range 2d check + out-of-range 2d check
Santeri Piippo <crimsondusk64@gmail.com>
parents: 741
diff changeset
46 {{ 0, -1, 0 }, Z, Y, false, true, true }, // right
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
47 {{ 1, 0, 0 }, X, Z, false, false, false }, // free (defensive dummy data)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
973
c1b60c7d5135 Change color config types into actual colors now that I can do that
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
50 ConfigOption (QColor BackgroundColor = "#FFFFFF")
c1b60c7d5135 Change color config types into actual colors now that I can do that
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
51 ConfigOption (QColor MainColor = "#A0A0A0")
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
52 ConfigOption (float MainColorAlpha = 1.0)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
53 ConfigOption (int LineThickness = 2)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
54 ConfigOption (bool BfcRedGreenView = false)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
55 ConfigOption (int Camera = 6)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
56 ConfigOption (bool BlackEdges = false)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
57 ConfigOption (bool DrawAxes = false)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
58 ConfigOption (bool DrawWireframe = false)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
59 ConfigOption (bool UseLogoStuds = false)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
60 ConfigOption (bool AntiAliasedLines = true)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
61 ConfigOption (bool RandomColors = false)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
62 ConfigOption (bool HighlightObjectBelowCursor = true)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
63 ConfigOption (bool DrawSurfaces = true)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
64 ConfigOption (bool DrawEdgeLines = true)
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
65 ConfigOption (bool DrawConditionalLines = true)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66
1106
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
67 const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin};
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
68
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 //
1109
a55b2608a395 Made GLRenderer's Model pointer const
Teemu Piippo <teemu@hecknology.net>
parents: 1108
diff changeset
71 GLRenderer::GLRenderer(const Model* model, QWidget* parent) :
1097
9a9e6ce0c5dc Made a new renderer be created for each document, instead of reusing the same renderer for all documents.
Teemu Piippo <teemu@hecknology.net>
parents: 1096
diff changeset
72 QGLWidget {parent},
9a9e6ce0c5dc Made a new renderer be created for each document, instead of reusing the same renderer for all documents.
Teemu Piippo <teemu@hecknology.net>
parents: 1096
diff changeset
73 HierarchyElement {parent},
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
74 m_model {model}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
76 m_camera = (Camera) m_config->camera();
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
77 m_compiler = new GLCompiler (this);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 m_toolTipTimer = new QTimer (this);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 m_toolTipTimer->setSingleShot (true);
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
80 setAcceptDrops (true);
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
81 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer()));
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
82 resetAllAngles();
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
83 m_needZoomToFit = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 // Init camera icons
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
86 for (Camera camera : iterateEnum<Camera>())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 {
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
88 const char* cameraIconNames[EnumLimits<Camera>::Count] =
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
89 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
90 "camera-top", "camera-front", "camera-left",
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
91 "camera-bottom", "camera-back", "camera-right",
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
92 "camera-free"
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
93 };
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
94
1035
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
95 CameraIcon* info = &m_cameraIcons[camera];
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
96 info->image = GetIcon (cameraIconNames[camera]);
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
97 info->camera = camera;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 calcCameraIcons();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 GLRenderer::~GLRenderer()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
107 m_compiler->setRenderer (nullptr);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
108 delete m_compiler;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
109 glDeleteBuffers (1, &m_axesVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
110 glDeleteBuffers (1, &m_axesColorVbo);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 // Calculates the "hitboxes" of the camera icons so that we can tell when the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 // cursor is pointing at the camera icon.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 void GLRenderer::calcCameraIcons()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 int i = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 for (CameraIcon& info : m_cameraIcons)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 // MATH
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
124 int x1 = (width() - (info.camera != FreeCamera ? 48 : 16)) + ((i % 3) * 16) - 1;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
125 int y1 = ((i / 3) * 16) + 1;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
127 info.sourceRect = QRect (0, 0, 16, 16);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
128 info.targetRect = QRect (x1, y1, 16, 16);
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
129 info.hitRect = QRect (
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
130 info.targetRect.x(),
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
131 info.targetRect.y(),
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
132 info.targetRect.width() + 1,
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
133 info.targetRect.height() + 1
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 );
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 ++i;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 void GLRenderer::initGLData()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 glEnable (GL_BLEND);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 glEnable (GL_POLYGON_OFFSET_FILL);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 glPolygonOffset (1.0f, 1.0f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 glEnable (GL_DEPTH_TEST);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 glShadeModel (GL_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 glEnable (GL_MULTISAMPLE);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
152 if (m_config->antiAliasedLines())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 glEnable (GL_LINE_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 glEnable (GL_POLYGON_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
158 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
159 else
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 glDisable (GL_LINE_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 glDisable (GL_POLYGON_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
166 bool GLRenderer::isDrawOnly() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
167 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
168 return m_isDrawOnly;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
169 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
170
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
171 void GLRenderer::setDrawOnly (bool value)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
172 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
173 m_isDrawOnly = value;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
174 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
175
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
176 GLCompiler* GLRenderer::compiler() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
177 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
178 return m_compiler;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
179 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
180
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
181 LDObject* GLRenderer::objectAtCursor() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
182 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
183 return m_objectAtCursor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
184 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
185
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 //
738
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
188 void GLRenderer::needZoomToFit()
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
189 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
190 m_needZoomToFit = true;
738
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
191 }
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
192
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
193 // =============================================================================
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
194 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 void GLRenderer::resetAngles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 {
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
197 if (m_initialized)
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
198 {
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
199 // Why did I even bother trying to compute this by pen and paper? Let GL figure it out...
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
200 glMatrixMode(GL_MODELVIEW);
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
201 glPushMatrix();
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
202 glLoadIdentity();
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
203 glRotatef(30, 1, 0, 0);
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
204 glRotatef(330, 0, 1, 0);
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
205 glGetFloatv(GL_MODELVIEW_MATRIX, m_rotationMatrix.data());
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
206 glPopMatrix();
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
207 }
1092
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
208 panning(X) = panning(Y) = 0.0f;
738
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
209 needZoomToFit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 void GLRenderer::resetAllAngles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
216 Camera oldcam = camera();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 for (int i = 0; i < 7; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
220 setCamera ((Camera) i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 resetAngles();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 setCamera (oldcam);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 void GLRenderer::initializeGL()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
231 initializeOpenGLFunctions();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 setBackground();
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
233 glLineWidth (m_config->lineThickness());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
234 glLineStipple (1, 0x6666);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 setAutoFillBackground (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 setMouseTracking (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 setFocusPolicy (Qt::WheelFocus);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
238 compiler()->initialize();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
239 initializeAxes();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
240 m_initialized = true;
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
241 // Now that GL is initialized, we can reset angles.
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
242 resetAllAngles();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
243 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
244
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
245 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
246 //
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
247 void GLRenderer::initializeAxes()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
248 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
249 // Definitions for visual axes, drawn on the screen
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
250 struct
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
251 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
252 QColor color;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
253 Vertex extrema;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
254 } axisInfo[3] =
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
255 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
256 { QColor {192, 96, 96}, Vertex {10000, 0, 0} }, // X
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
257 { QColor {48, 192, 48}, Vertex {0, 10000, 0} }, // Y
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
258 { QColor {48, 112, 192}, Vertex {0, 0, 10000} }, // Z
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
259 };
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
260
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
261 float axisdata[18];
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
262 float colorData[18];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
263 memset (axisdata, 0, sizeof axisdata);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
264
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
265 for (int i = 0; i < 3; ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
266 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
267 const auto& data = axisInfo[i];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
268
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
269 for (Axis axis : axes)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
270 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
271 axisdata[(i * 6) + axis] = data.extrema[axis];
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
272 axisdata[(i * 6) + 3 + axis] = -data.extrema[axis];
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
273 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
274
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
275 int offset = i * 6;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
276 colorData[offset + 0] = colorData[offset + 3] = data.color.red();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
277 colorData[offset + 1] = colorData[offset + 4] = data.color.green();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
278 colorData[offset + 2] = colorData[offset + 5] = data.color.blue();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
279 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
280
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
281 glGenBuffers (1, &m_axesVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
282 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
283 glBufferData (GL_ARRAY_BUFFER, sizeof axisdata, axisdata, GL_STATIC_DRAW);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
284 glGenBuffers (1, &m_axesColorVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
285 glBindBuffer (GL_ARRAY_BUFFER, m_axesColorVbo);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
286 glBufferData (GL_ARRAY_BUFFER, sizeof colorData, colorData, GL_STATIC_DRAW);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
287 glBindBuffer (GL_ARRAY_BUFFER, 0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
291 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 void GLRenderer::setBackground()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 {
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
294 if (not m_isDrawingSelectionScene)
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
295 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
296 // Otherwise use the background that the user wants.
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
297 QColor color = m_config->backgroundColor();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
299 if (color.isValid())
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
300 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
301 color.setAlpha(255);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
302 m_useDarkBackground = luma(color) < 80;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
303 m_backgroundColor = color;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
304 qglClearColor(color);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
305 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
306 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
307 else
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
308 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
309 // The picking scene requires a black background.
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
310 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
311 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
312 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
313
1106
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
314 QColor GLRenderer::backgroundColor() const
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
315 {
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
316 return m_backgroundColor;
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
317 }
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
318
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 void GLRenderer::refresh()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323 update();
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
324
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
325 if (isVisible())
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
326 swapBuffers();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 //
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
331 void GLRenderer::resizeGL (int width, int height)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333 calcCameraIcons();
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
334 glViewport (0, 0, width, height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 glMatrixMode (GL_PROJECTION);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 glLoadIdentity();
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
337 gluPerspective (45.0f, (double) width / (double) height, 1.0f, 10000.0f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338 glMatrixMode (GL_MODELVIEW);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343 void GLRenderer::drawGLScene()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
345 if (m_needZoomToFit)
737
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
346 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
347 m_needZoomToFit = false;
737
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
348 zoomAllToFit();
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
349 }
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
350
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
351 m_virtualWidth = zoom();
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
352 m_virtualHeight = (height() * m_virtualWidth) / width();
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
353
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
354 if (m_config->drawWireframe() and not m_isDrawingSelectionScene)
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
355 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
357 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
358 glEnable(GL_DEPTH_TEST);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
360 if (camera() != FreeCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 glMatrixMode (GL_PROJECTION);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363 glPushMatrix();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 glLoadIdentity();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
366 glOrtho (-m_virtualWidth, m_virtualWidth, -m_virtualHeight, m_virtualHeight, -100.0f, 100.0f);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
367 glTranslatef(panning (X), panning (Y), 0.0f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
369 if (camera() != FrontCamera and camera() != BackCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
371 glRotatef(90.0f, g_cameraInfo[camera()].glrotate[0],
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
372 g_cameraInfo[camera()].glrotate[1],
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
373 g_cameraInfo[camera()].glrotate[2]);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
374 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
375
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376 // Back camera needs to be handled differently
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
377 if (camera() == BackCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
379 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
380 glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
384 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
385 glMatrixMode(GL_MODELVIEW);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 glPushMatrix();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 glLoadIdentity();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
388 glTranslatef(0.0f, 0.0f, -2.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
389 glTranslatef(panning (X), panning (Y), -zoom());
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
390 glMultMatrixf(m_rotationMatrix.constData());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
393 glEnableClientState (GL_VERTEX_ARRAY);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
394 glEnableClientState (GL_COLOR_ARRAY);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
396 if (m_isDrawingSelectionScene)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
397 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
398 drawVbos (TrianglesVbo, PickColorsVboComplement, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
399 drawVbos (QuadsVbo, PickColorsVboComplement, GL_QUADS);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
400 drawVbos (LinesVbo, PickColorsVboComplement, GL_LINES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
401 drawVbos (ConditionalLinesVbo, PickColorsVboComplement, GL_LINES);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
405 if (m_config->bfcRedGreenView())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
406 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
407 glEnable (GL_CULL_FACE);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
408 glCullFace (GL_BACK);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
409 drawVbos (TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
410 drawVbos (QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
411 glCullFace (GL_FRONT);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
412 drawVbos (TrianglesVbo, BfcBackColorsVboComplement, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
413 drawVbos (QuadsVbo, BfcBackColorsVboComplement, GL_QUADS);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
414 glDisable (GL_CULL_FACE);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
415 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
416 else
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
418 ComplementVboType colors;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
419
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
420 if (m_config->randomColors())
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
421 colors = RandomColorsVboComplement;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
422 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
423 colors = NormalColorsVboComplement;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
424
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
425 drawVbos (TrianglesVbo, colors, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
426 drawVbos (QuadsVbo, colors, GL_QUADS);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
427 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
428
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
429 drawVbos (LinesVbo, NormalColorsVboComplement, GL_LINES);
722
61e2d0ca0018 - conditional lines are now rendered with stippled lines again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 720
diff changeset
430 glEnable (GL_LINE_STIPPLE);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
431 drawVbos (ConditionalLinesVbo, NormalColorsVboComplement, GL_LINES);
722
61e2d0ca0018 - conditional lines are now rendered with stippled lines again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 720
diff changeset
432 glDisable (GL_LINE_STIPPLE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
434 if (m_config->drawAxes())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
435 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
436 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
437 glVertexPointer (3, GL_FLOAT, 0, NULL);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
438 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
439 glColorPointer (3, GL_FLOAT, 0, NULL);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
440 glDrawArrays (GL_LINES, 0, 6);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
441 CHECK_GL_ERROR();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
442 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
443 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
444
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
445 glPopMatrix();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
446 glBindBuffer (GL_ARRAY_BUFFER, 0);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
447 glDisableClientState (GL_VERTEX_ARRAY);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
448 glDisableClientState (GL_COLOR_ARRAY);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
449 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
450 glDisable (GL_CULL_FACE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
451 glMatrixMode (GL_MODELVIEW);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
452 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 //
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
457 void GLRenderer::drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
458 {
815
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
459 // Filter this through some configuration options
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
460 if ((isOneOf (surface, QuadsVbo, TrianglesVbo) and m_config->drawSurfaces() == false)
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
461 or (surface == LinesVbo and m_config->drawEdgeLines() == false)
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
462 or (surface == ConditionalLinesVbo and m_config->drawConditionalLines() == false))
815
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
463 {
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
464 return;
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
465 }
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
466
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
467 int surfaceVboNumber = m_compiler->vboNumber(surface, SurfacesVboComplement);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
468 int colorVboNumber = m_compiler->vboNumber(surface, colors);
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
469 m_compiler->prepareVBO(surfaceVboNumber, currentDocument());
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
470 m_compiler->prepareVBO(colorVboNumber, currentDocument());
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
471 GLuint surfaceVbo = m_compiler->vbo(surfaceVboNumber);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
472 GLuint colorVbo = m_compiler->vbo(colorVboNumber);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
473 GLsizei count = m_compiler->vboSize(surfaceVboNumber) / 3;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
474
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
475 if (count > 0)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
476 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
477 glBindBuffer(GL_ARRAY_BUFFER, surfaceVbo);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
478 glVertexPointer(3, GL_FLOAT, 0, nullptr);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
479 CHECK_GL_ERROR();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
480 glBindBuffer(GL_ARRAY_BUFFER, colorVbo);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
481 glColorPointer(4, GL_FLOAT, 0, nullptr);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
482 CHECK_GL_ERROR();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
483 glDrawArrays(type, 0, count);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
484 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
485 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
486 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
487
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
488 QPen GLRenderer::textPen() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
489 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
490 return {m_useDarkBackground ? Qt::white : Qt::black};
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
491 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
492
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
493 bool GLRenderer::freeCameraAllowed() const
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
494 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
495 return true;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
496 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
497
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
498 void GLRenderer::paintEvent(QPaintEvent*)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
499 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
500 makeCurrent();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
501 initGLData();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 drawGLScene();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
503
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
504 if (isDrawingSelectionScene())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
505 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
507 QPainter painter {this};
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
508 painter.setRenderHint(QPainter::Antialiasing);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
509 overpaint(painter);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
510 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
511
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
512 void GLRenderer::overpaint(QPainter &painter)
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
513 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
514 // Draw a background for the selected camera
1106
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
515 painter.setPen(thinBorderPen);
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
516 painter.setBrush(QBrush {QColor {0, 128, 160, 128}});
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
517 painter.drawRect(m_cameraIcons[camera()].hitRect);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
518
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
519 // Draw the camera icons
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
520 for (const CameraIcon& info : m_cameraIcons)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
521 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
522 // Don't draw the free camera icon when we can't use the free camera
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
523 if (&info == &m_cameraIcons[FreeCamera] and not freeCameraAllowed())
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
524 continue;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
525
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
526 painter.drawPixmap(info.targetRect, info.image, info.sourceRect);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
529 // Tool tips
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
530 if (m_drawToolTip)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
532 if (not m_cameraIcons[m_toolTipCamera].targetRect.contains (m_mousePosition))
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
533 m_drawToolTip = false;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
534 else
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
535 QToolTip::showText(m_globalpos, currentCameraName());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
536 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
537
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
538 // Draw a label for the current camera in the bottom left corner
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
540 QFontMetrics metrics {QFont {}};
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
541 int margin = 4;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
542 painter.setPen(textPen());
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
543 painter.drawText(QPoint {margin, height() - margin - metrics.descent()}, currentCameraName());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
545 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
546
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
547 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
548 //
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
549 void GLRenderer::mouseReleaseEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
550 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
551 bool wasLeft = (m_lastButtons & Qt::LeftButton) and not (event->buttons() & Qt::LeftButton);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
552 m_panning = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
554 // Check if we selected a camera icon
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
555 if (wasLeft and not mouseHasMoved())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
557 for (CameraIcon& info : m_cameraIcons)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
558 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
559 if (info.targetRect.contains (event->pos()))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
560 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
561 setCamera (info.camera);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
562 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
564 }
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
565 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567 update();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
568 m_totalMouseMove = 0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
569 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
571 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
573 void GLRenderer::mousePressEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
575 m_lastButtons = event->buttons();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
576 m_totalMouseMove = 0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
578
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
579 // =============================================================================
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
580 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
581 void GLRenderer::mouseMoveEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
583 int xMove = event->x() - m_mousePosition.x();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
584 int yMove = event->y() - m_mousePosition.y();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
585 m_totalMouseMove += qAbs(xMove) + qAbs(yMove);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
586 m_isCameraMoving = false;
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
587
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
588 bool left = event->buttons() & Qt::LeftButton;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
589 bool mid = event->buttons() & Qt::MidButton;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
590 bool shift = event->modifiers() & Qt::ShiftModifier;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
592 if (mid or (left and shift))
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
593 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
594 panning(X) += 0.03f * xMove * (zoom() / 7.5f);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
595 panning(Y) -= 0.03f * yMove * (zoom() / 7.5f);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
596 m_panning = true;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
597 m_isCameraMoving = true;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
598 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
599 else if (left and camera() == FreeCamera and (xMove != 0 or yMove != 0))
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
600 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
601 // Apply current rotation input to the rotation matrix
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
602 // ref: https://forums.ldraw.org/thread-22006-post-24426.html#pid24426
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
603 glPushMatrix();
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
604 glLoadIdentity();
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
605 // 0.6 is an arbitrary rotation sensitivity scalar
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
606 glRotatef(0.6 * hypot(xMove, yMove), yMove, xMove, 0);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
607 glMultMatrixf(m_rotationMatrix.constData());
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
608 glGetFloatv(GL_MODELVIEW_MATRIX, m_rotationMatrix.data());
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
609 glPopMatrix();
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
610 m_isCameraMoving = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
611 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
613 // Start the tool tip timer
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
614 if (not m_drawToolTip)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
615 m_toolTipTimer->start (500);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
616
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617 // Update 2d position
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
618 m_mousePosition = event->pos();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
619 m_globalpos = event->globalPos();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
620 m_mousePositionF = event->localPos();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
622 highlightCursorObject();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
623 update();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
624 event->accept();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
628 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
629 void GLRenderer::keyPressEvent(QKeyEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
631 m_currentKeyboardModifiers = event->modifiers();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
636 void GLRenderer::keyReleaseEvent(QKeyEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
637 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
638 m_currentKeyboardModifiers = event->modifiers();
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 869
diff changeset
639 update();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
643 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
644 void GLRenderer::wheelEvent(QWheelEvent* ev)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
646 makeCurrent();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
647 zoomNotch(ev->delta() > 0);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
648 zoom() = qBound(0.01, zoom(), 10000.0);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
649 m_isCameraMoving = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 ev->accept();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
652 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
653
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
654 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
655 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
656 void GLRenderer::leaveEvent(QEvent*)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
657 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
658 m_drawToolTip = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
659 m_toolTipTimer->stop();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
660 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
661 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
662
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
665 void GLRenderer::setCamera(Camera camera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 {
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
667 // The edit mode may forbid the free camera.
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
668 if (freeCameraAllowed() or camera != FreeCamera)
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
669 {
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
670 m_camera = camera;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
671 m_config->setCamera(int {camera});
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
672 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
673 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
674
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
675 /*
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
676 * Returns the set of objects found in the specified pixel area.
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
677 */
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
678 QSet<LDObject*> GLRenderer::pick(const QRect& range)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
679 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
680 makeCurrent();
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
681 QSet<LDObject*> newSelection;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
682
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
683 // Paint the picking scene
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
684 setPicking(true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
685 drawGLScene();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
687 int x0 = range.left();
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
688 int y0 = range.top();
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
689 int x1 = x0 + range.width();
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
690 int y1 = y0 + range.height();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
691
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692 // Clamp the values to ensure they're within bounds
966
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
693 x0 = qMax (0, x0);
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
694 y0 = qMax (0, y0);
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
695 x1 = qMin (x1, width());
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
696 y1 = qMin (y1, height());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
697 const int areawidth = (x1 - x0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
698 const int areaheight = (y1 - y0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
699 const qint32 numpixels = areawidth * areaheight;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
700
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
701 // Allocate space for the pixel data.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
702 QVector<unsigned char> pixelData;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
703 pixelData.resize(4 * numpixels);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
704
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
705 // Read pixels from the color buffer.
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
706 glReadPixels(x0, height() - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
707
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
708 QSet<int32_t> indices;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
709
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
710 // Go through each pixel read and add them to the selection.
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
711 // Each pixel maps to an LDObject index injectively.
753
Santeri Piippo <crimsondusk64@gmail.com>
parents: 752
diff changeset
712 // Note: black is background, those indices are skipped.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
713 for (unsigned char *pixelCursor = pixelData.begin(); pixelCursor < pixelData.end(); pixelCursor += 4)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
714 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
715 int32_t index = pixelCursor[0] * 0x10000 +
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
716 pixelCursor[1] * 0x100 +
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
717 pixelCursor[2] * 0x1;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
718 if (index != 0)
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
719 indices.insert(index);
752
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
720 }
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
721
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
722 // For each index read, resolve the LDObject behind it and add it to the selection.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
723 for (int32_t index : indices)
752
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
724 {
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
725 LDObject* object = LDObject::fromID(index);
958
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
726
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
727 if (object != nullptr)
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
728 newSelection.insert(object);
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
729 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
730
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
731 setPicking(false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 repaint();
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
733 return newSelection;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
734 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
736 /*
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
737 * Simpler version of GLRenderer::pick which simply picks whatever object on the cursor
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
738 */
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
739 LDObject* GLRenderer::pick(int mouseX, int mouseY)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
740 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
741 unsigned char pixel[4];
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
742 makeCurrent();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
743 setPicking(true);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
744 drawGLScene();
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
745 glReadPixels(mouseX, height() - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
746 LDObject* object = LDObject::fromID(pixel[0] * 0x10000 + pixel[1] * 0x100 + pixel[2]);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
747 setPicking(false);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
748 repaint();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
749 return object;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
750 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
751
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
752 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
754 void GLRenderer::setPicking(bool value)
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
755 {
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
756 m_isDrawingSelectionScene = value;
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
757 setBackground();
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
758
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
759 if (m_isDrawingSelectionScene)
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
760 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
761 glDisable(GL_DITHER);
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
762
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
763 // Use particularly thick lines while picking ease up selecting lines.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
764 glLineWidth(qMax<double>(m_config->lineThickness(), 6.5));
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
765 }
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
766 else
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
767 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
768 glEnable(GL_DITHER);
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
769
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
770 // Restore line thickness
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
771 glLineWidth(m_config->lineThickness());
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
772 }
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
773 }
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
774
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
775 // =============================================================================
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
776 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
777 void GLRenderer::forgetObject(LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
778 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 973
diff changeset
779 if (m_objectAtCursor == obj)
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 973
diff changeset
780 m_objectAtCursor = nullptr;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
781 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
782
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
783 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
784 //
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
785 QByteArray GLRenderer::capturePixels()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
786 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
787 QByteArray result;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
788 result.resize (4 * width() * height());
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
789 m_takingScreenCapture = true;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
790 update(); // Smile!
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
791 m_takingScreenCapture = false;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
792 glReadPixels(0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, result.data());
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
793 return result;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
794 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
795
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
798 void GLRenderer::slot_toolTipTimer()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
799 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
800 // We come here if the cursor has stayed in one place for longer than a
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
801 // a second. Check if we're holding it over a camera icon - if so, draw
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
802 // a tooltip.
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
803 for (CameraIcon & icon : m_cameraIcons)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
804 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
805 if (icon.targetRect.contains (m_mousePosition))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
807 m_toolTipCamera = icon.camera;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
808 m_drawToolTip = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
809 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
810 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
812 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
813 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
815 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816 //
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
817 Axis GLRenderer::getCameraAxis (bool y, Camera camid)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
819 if (camid == (Camera) -1)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
820 camid = camera();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
822 const CameraInfo* cam = &g_cameraInfo[camid];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
823 return (y) ? cam->localY : cam->localX;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
824 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
825
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
826 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
827 //
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
828 QString GLRenderer::cameraName (Camera camera) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
829 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
830 switch (camera)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
831 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
832 case TopCamera: return tr ("Top Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
833 case FrontCamera: return tr ("Front Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
834 case LeftCamera: return tr ("Left Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
835 case BottomCamera: return tr ("Bottom Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
836 case BackCamera: return tr ("Back Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
837 case RightCamera: return tr ("Right Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
838 case FreeCamera: return tr ("Free Camera");
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
839 default: break;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
840 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
841
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
842 return "";
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
843 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
844
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
845 QString GLRenderer::currentCameraName() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
846 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
847 return cameraName (camera());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
848 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
849
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
850 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
852 void GLRenderer::zoomNotch (bool inward)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
853 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
854 zoom() *= inward ? 0.833f : 1.2f;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
855 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
856
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
857 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
858 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
859 void GLRenderer::zoomToFit()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
861 zoom() = 30.0f;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
862 bool lastfilled = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
863 bool firstrun = true;
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
864 enum { black = 0xFF000000 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
865 bool inward = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
866 int runaway = 50;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
867
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
868 // Use the pick list while drawing the scene, this way we can tell whether borders
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
869 // are background or not.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870 setPicking (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
872 while (--runaway)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
873 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
874 if (zoom() > 10000.0 or zoom() < 0.0)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
875 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
876 // Nothing to draw if we get here.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
877 zoom() = 30.0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
878 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
879 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
880
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
881 zoomNotch (inward);
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
882 QVector<unsigned char> capture (4 * width() * height());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
883 drawGLScene();
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
884 glReadPixels (0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, capture.data());
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
885 QImage image (capture.constData(), width(), height(), QImage::Format_ARGB32);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
886 bool filled = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
887
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
888 // Check the top and bottom rows
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
889 for (int i = 0; i < image.width(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
890 {
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
891 if (image.pixel (i, 0) != black or image.pixel (i, height() - 1) != black)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
892 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
893 filled = true;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
894 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
895 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
896 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
897
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
898 // Left and right edges
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
899 if (filled == false)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
900 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
901 for (int i = 0; i < image.height(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
902 {
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
903 if (image.pixel (0, i) != black or image.pixel (width() - 1, i) != black)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
904 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
905 filled = true;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
906 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
907 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
908 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
909 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
910
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
911 if (firstrun)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
912 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
913 // If this is the first run, we don't know enough to determine
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
914 // whether the zoom was to fit, so we mark in our knowledge so
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
915 // far and start over.
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
916 inward = not filled;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
917 firstrun = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
918 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
919 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
920 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
921 // If this run filled the screen and the last one did not, the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
922 // last run had ideal zoom - zoom a bit back and we should reach it.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
923 if (filled and not lastfilled)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
924 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
925 zoomNotch (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
926 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
927 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
928
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
929 // If this run did not fill the screen and the last one did, we've
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
930 // now reached ideal zoom so we're done here.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
931 if (not filled and lastfilled)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
932 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
933
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
934 inward = not filled;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
935 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
936
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
937 lastfilled = filled;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
938 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
939
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
940 setPicking (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
941 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
942
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
943 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
944 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
945 void GLRenderer::zoomAllToFit()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
946 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
947 zoomToFit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
948 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
949
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
950 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
951 //
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
952 void GLRenderer::highlightCursorObject()
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
953 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
954 if (not m_config->highlightObjectBelowCursor() and objectAtCursor() == nullptr)
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
955 return;
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
956
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
957 LDObject* newObject = nullptr;
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
958 LDObject* oldObject = objectAtCursor();
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
959 qint32 newIndex;
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
960
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1015
diff changeset
961 if (m_isCameraMoving or not m_config->highlightObjectBelowCursor())
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
962 {
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
963 newIndex = 0;
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
964 }
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
965 else
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
966 {
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
967 setPicking (true);
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
968 drawGLScene();
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
969 setPicking (false);
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
970
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
971 unsigned char pixel[4];
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
972 glReadPixels (m_mousePosition.x(), height() - m_mousePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel[0]);
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
973 newIndex = pixel[0] * 0x10000 | pixel[1] * 0x100 | pixel[2];
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
974 }
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
975
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
976 if (newIndex != (oldObject ? oldObject->id() : 0))
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
977 {
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
978 if (newIndex != 0)
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
979 newObject = LDObject::fromID (newIndex);
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
980
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
981 m_objectAtCursor = newObject;
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
982
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
983 if (oldObject)
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
984 emit objectHighlightingChanged(oldObject);
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
985
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
986 if (newObject)
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
987 emit objectHighlightingChanged(newObject);
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
988 }
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
989
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
990 update();
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
991 }
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
992
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
993 const CameraInfo& GLRenderer::cameraInfo (Camera camera) const
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
994 {
1035
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
995 if (valueInEnum<Camera>(camera))
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
996 return g_cameraInfo[camera];
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
997 else
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
998 return g_cameraInfo[0];
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
999 }
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1000
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1001 bool GLRenderer::mouseHasMoved() const
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1002 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1003 return m_totalMouseMove >= 10;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1004 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1005
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1006 QPoint const& GLRenderer::mousePosition() const
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1007 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1008 return m_mousePosition;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1009 }
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
1010
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1011 QPointF const& GLRenderer::mousePositionF() const
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1012 {
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1013 return m_mousePositionF;
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1014 }
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1015
897
ef9e4469975a - pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
1016 Qt::KeyboardModifiers GLRenderer::keyboardModifiers() const
ef9e4469975a - pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
1017 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1018 return m_currentKeyboardModifiers;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1019 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1020
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1021 Camera GLRenderer::camera() const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1022 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1023 return m_camera;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1024 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1025
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1026 double& GLRenderer::panning (Axis ax)
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1027 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
1028 return (ax == X) ? m_panX[camera()] :
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
1029 m_panY[camera()];
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1030 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1031
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1032 double GLRenderer::panning (Axis ax) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1033 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
1034 return (ax == X) ? m_panX[camera()] :
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
1035 m_panY[camera()];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1036 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1037
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1038 double& GLRenderer::zoom()
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1039 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
1040 return m_zoom[camera()];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1041 }
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1042
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1043 const QGenericMatrix<4, 4, GLfloat>& GLRenderer::rotationMatrix() const
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1044 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1045 return m_rotationMatrix;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1046 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1047
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1048 bool GLRenderer::isDrawingSelectionScene() const
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1049 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1050 return m_isDrawingSelectionScene;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1051 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1052
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1053 Qt::MouseButtons GLRenderer::lastButtons() const
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1054 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1055 return m_lastButtons;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
1056 }
1108
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1057
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1058 double GLRenderer::virtualHeight() const
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1059 {
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1060 return m_virtualHeight;
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1061 }
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1062
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1063 double GLRenderer::virtualWidth() const
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1064 {
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1065 return m_virtualWidth;
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
1066 }
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
1067
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
1068 const Model* GLRenderer::model() const
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
1069 {
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
1070 return m_model;
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
1071 }

mercurial