src/glRenderer.cpp

Thu, 09 Feb 2017 00:43:30 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Feb 2017 00:43:30 +0200
changeset 1098
0b837bed121d
parent 1097
9a9e6ce0c5dc
child 1099
14276e435640
permissions
-rw-r--r--

LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.

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"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "messageLog.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
35 #include "glCompiler.h"
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
36 #include "primitives.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
37 #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
38 #include "grid.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
40 const CameraInfo g_cameraInfo[EnumLimits<Camera>::Count] =
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 {
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
42 {{ 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
43 {{ 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
44 {{ 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
45 {{ -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
46 {{ 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
47 {{ 0, -1, 0 }, Z, Y, false, true, true }, // right
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
48 {{ 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
49 };
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
973
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 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 ConfigOption (bool DrawConditionalLines = true)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 //
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
70 GLRenderer::GLRenderer(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
71 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
72 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
73 m_model {model}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
75 m_camera = (Camera) m_config->camera();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
76 m_currentEditMode = AbstractEditMode::createByType (this, EditModeType::Select);
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);
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
80 m_thinBorderPen = QPen (QColor (0, 0, 0, 208), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 m_thinBorderPen.setWidth (1);
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
82 setAcceptDrops (true);
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
83 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer()));
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
84 initOverlaysFromObjects();
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
85 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
86 m_needZoomToFit = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 // Init camera icons
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
89 for (Camera camera : iterateEnum<Camera>())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
91 const char* cameraIconNames[EnumLimits<Camera>::Count] =
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
92 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
93 "camera-top", "camera-front", "camera-left",
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
94 "camera-bottom", "camera-back", "camera-right",
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
95 "camera-free"
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
96 };
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
97
1035
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
98 CameraIcon* info = &m_cameraIcons[camera];
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
99 info->image = GetIcon (cameraIconNames[camera]);
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
100 info->camera = camera;
655
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 calcCameraIcons();
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 GLRenderer::~GLRenderer()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 981
diff changeset
110 m_compiler->setRenderer (nullptr);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
111 delete m_compiler;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
112 delete m_currentEditMode;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
113 glDeleteBuffers (1, &m_axesVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
114 glDeleteBuffers (1, &m_axesColorVbo);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 }
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 // 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
119 // cursor is pointing at the camera icon.
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 void GLRenderer::calcCameraIcons()
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 int i = 0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 for (CameraIcon& info : m_cameraIcons)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 // MATH
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
128 int x1 = (m_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
129 int y1 = ((i / 3) * 16) + 1;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
131 info.sourceRect = QRect (0, 0, 16, 16);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
132 info.targetRect = QRect (x1, y1, 16, 16);
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
133 info.hitRect = QRect (
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
134 info.targetRect.x(),
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
135 info.targetRect.y(),
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
136 info.targetRect.width() + 1,
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
137 info.targetRect.height() + 1
655
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 ++i;
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 }
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 void GLRenderer::initGLData()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 glEnable (GL_BLEND);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 glEnable (GL_POLYGON_OFFSET_FILL);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 glPolygonOffset (1.0f, 1.0f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 glEnable (GL_DEPTH_TEST);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153 glShadeModel (GL_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 glEnable (GL_MULTISAMPLE);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155
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
156 if (m_config->antiAliasedLines())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 glEnable (GL_LINE_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 glEnable (GL_POLYGON_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
162 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
163 else
655
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 glDisable (GL_LINE_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 glDisable (GL_POLYGON_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
170 bool GLRenderer::isDrawOnly() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
171 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
172 return m_isDrawOnly;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
173 }
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 void GLRenderer::setDrawOnly (bool value)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
176 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
177 m_isDrawOnly = value;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
178 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
179
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
180 Model* GLRenderer::model() const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
181 {
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
182 return m_model;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
183 }
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 GLCompiler* GLRenderer::compiler() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
186 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
187 return m_compiler;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
188 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
189
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
190 LDObject* GLRenderer::objectAtCursor() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
191 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
192 return m_objectAtCursor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
193 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
194
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 //
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
197 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
198 {
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
199 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
200 }
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
201
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
202 // =============================================================================
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
203 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 void GLRenderer::resetAngles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 {
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
206 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
207 {
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
208 // 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
209 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
210 glPushMatrix();
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
211 glLoadIdentity();
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
212 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
213 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
214 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
215 glPopMatrix();
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
216 }
1092
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
217 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
218 needZoomToFit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 // =============================================================================
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 void GLRenderer::resetAllAngles()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
225 Camera oldcam = camera();
655
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 for (int i = 0; i < 7; ++i)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
229 setCamera ((Camera) i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 resetAngles();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 setCamera (oldcam);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 void GLRenderer::initializeGL()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
240 initializeOpenGLFunctions();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 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
242 glLineWidth (m_config->lineThickness());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
243 glLineStipple (1, 0x6666);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 setAutoFillBackground (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 setMouseTracking (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 setFocusPolicy (Qt::WheelFocus);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
247 compiler()->initialize();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
248 initializeAxes();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
249 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
250 // 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
251 resetAllAngles();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
252 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
253
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
254 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
255 //
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
256 void GLRenderer::initializeAxes()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
257 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
258 // Definitions for visual axes, drawn on the screen
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
259 struct
986
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 QColor color;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
262 Vertex extrema;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
263 } axisInfo[3] =
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
264 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
265 { QColor {192, 96, 96}, Vertex {10000, 0, 0} }, // X
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
266 { QColor {48, 192, 48}, Vertex {0, 10000, 0} }, // Y
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
267 { QColor {48, 112, 192}, Vertex {0, 0, 10000} }, // Z
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
268 };
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
269
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
270 float axisdata[18];
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
271 float colorData[18];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
272 memset (axisdata, 0, sizeof axisdata);
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 for (int i = 0; i < 3; ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
275 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
276 const auto& data = axisInfo[i];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
277
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
278 for (Axis axis : axes)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
279 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
280 axisdata[(i * 6) + axis] = data.extrema[axis];
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
281 axisdata[(i * 6) + 3 + axis] = -data.extrema[axis];
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
282 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
283
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
284 int offset = i * 6;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
285 colorData[offset + 0] = colorData[offset + 3] = data.color.red();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
286 colorData[offset + 1] = colorData[offset + 4] = data.color.green();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
287 colorData[offset + 2] = colorData[offset + 5] = data.color.blue();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
288 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
289
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
290 glGenBuffers (1, &m_axesVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
291 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
292 glBufferData (GL_ARRAY_BUFFER, sizeof axisdata, axisdata, GL_STATIC_DRAW);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
293 glGenBuffers (1, &m_axesColorVbo);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
294 glBindBuffer (GL_ARRAY_BUFFER, m_axesColorVbo);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
295 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
296 glBindBuffer (GL_ARRAY_BUFFER, 0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 void GLRenderer::setBackground()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 {
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
303 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
304 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
305 // Otherwise use the background that the user wants.
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
306 QColor color = m_config->backgroundColor();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
308 if (color.isValid())
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
309 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
310 color.setAlpha(255);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
311 m_useDarkBackground = luma(color) < 80;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
312 m_backgroundColor = color;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
313 qglClearColor(color);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
314 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
315 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
316 else
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
317 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
318 // The picking scene requires a black background.
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
319 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
320 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 }
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 void GLRenderer::refresh()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
327 update();
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
328
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
329 if (isVisible())
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
330 swapBuffers();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 }
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 void GLRenderer::hardRefresh()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
337 if (m_initialized)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
338 {
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
339 compiler()->compileModel (currentDocument());
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
340 refresh();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
341 }
655
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
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
344 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 void GLRenderer::resizeGL (int w, int h)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 m_width = w;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 m_height = h;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 calcCameraIcons();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 glViewport (0, 0, w, h);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 glMatrixMode (GL_PROJECTION);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 glLoadIdentity();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 gluPerspective (45.0f, (double) w / (double) h, 1.0f, 10000.0f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 glMatrixMode (GL_MODELVIEW);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 void GLRenderer::drawGLScene()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 {
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
362 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
363 {
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
364 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
365 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
366 }
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
367
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
368 if (m_config->drawWireframe() and not m_isDrawingSelectionScene)
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
369 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
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 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
372 glEnable(GL_DEPTH_TEST);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
374 if (camera() != FreeCamera)
655
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 glMatrixMode (GL_PROJECTION);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
377 glPushMatrix();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
379 glLoadIdentity();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
380 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
381 glTranslatef(panning (X), panning (Y), 0.0f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
383 if (camera() != FrontCamera and camera() != BackCamera)
655
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 glRotatef(90.0f, g_cameraInfo[camera()].glrotate[0],
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
386 g_cameraInfo[camera()].glrotate[1],
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
387 g_cameraInfo[camera()].glrotate[2]);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 // Back camera needs to be handled differently
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
391 if (camera() == BackCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
393 glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
394 glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
399 glMatrixMode(GL_MODELVIEW);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 glPushMatrix();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 glLoadIdentity();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
402 glTranslatef(0.0f, 0.0f, -2.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
403 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
404 glMultMatrixf(m_rotationMatrix.constData());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
405 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
406
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
407 glEnableClientState (GL_VERTEX_ARRAY);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
408 glEnableClientState (GL_COLOR_ARRAY);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
409
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
410 if (m_isDrawingSelectionScene)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
411 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
412 drawVbos (TrianglesVbo, PickColorsVboComplement, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
413 drawVbos (QuadsVbo, PickColorsVboComplement, GL_QUADS);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
414 drawVbos (LinesVbo, PickColorsVboComplement, GL_LINES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
415 drawVbos (ConditionalLinesVbo, PickColorsVboComplement, GL_LINES);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
417 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
418 {
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
419 if (m_config->bfcRedGreenView())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
420 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
421 glEnable (GL_CULL_FACE);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
422 glCullFace (GL_BACK);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
423 drawVbos (TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
424 drawVbos (QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
425 glCullFace (GL_FRONT);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
426 drawVbos (TrianglesVbo, BfcBackColorsVboComplement, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
427 drawVbos (QuadsVbo, BfcBackColorsVboComplement, GL_QUADS);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
428 glDisable (GL_CULL_FACE);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
429 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
430 else
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
431 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
432 ComplementVboType colors;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
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->randomColors())
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
435 colors = RandomColorsVboComplement;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
436 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
437 colors = NormalColorsVboComplement;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
438
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
439 drawVbos (TrianglesVbo, colors, GL_TRIANGLES);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
440 drawVbos (QuadsVbo, colors, GL_QUADS);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
441 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
442
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
443 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
444 glEnable (GL_LINE_STIPPLE);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
445 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
446 glDisable (GL_LINE_STIPPLE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
447
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
448 if (m_config->drawAxes())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
449 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
450 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
451 glVertexPointer (3, GL_FLOAT, 0, NULL);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
452 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
453 glColorPointer (3, GL_FLOAT, 0, NULL);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
454 glDrawArrays (GL_LINES, 0, 6);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
455 CHECK_GL_ERROR();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
457 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 glPopMatrix();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
460 glBindBuffer (GL_ARRAY_BUFFER, 0);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
461 glDisableClientState (GL_VERTEX_ARRAY);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
462 glDisableClientState (GL_COLOR_ARRAY);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
463 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
464 glDisable (GL_CULL_FACE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 glMatrixMode (GL_MODELVIEW);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
466 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
469 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
470 //
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
471 void GLRenderer::drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
472 {
815
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
473 // 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
474 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
475 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
476 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
477 {
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
478 return;
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
479 }
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
480
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
481 int surfaceVboNumber = m_compiler->vboNumber(surface, SurfacesVboComplement);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
482 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
483 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
484 m_compiler->prepareVBO(colorVboNumber, currentDocument());
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
485 GLuint surfaceVbo = m_compiler->vbo(surfaceVboNumber);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
486 GLuint colorVbo = m_compiler->vbo(colorVboNumber);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
487 GLsizei count = m_compiler->vboSize(surfaceVboNumber) / 3;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
488
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
489 if (count > 0)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
490 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
491 glBindBuffer(GL_ARRAY_BUFFER, surfaceVbo);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
492 glVertexPointer(3, GL_FLOAT, 0, nullptr);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
493 CHECK_GL_ERROR();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
494 glBindBuffer(GL_ARRAY_BUFFER, colorVbo);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
495 glColorPointer(4, GL_FLOAT, 0, nullptr);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
496 CHECK_GL_ERROR();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
497 glDrawArrays(type, 0, count);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
498 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
499 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
500 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
501
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
502 // =============================================================================
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
503 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
504 // This converts a 2D point on the screen to a 3D point in the model. If 'snap'
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
505 // is true, the 3D point will snap to the current grid.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
506 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
507 Vertex GLRenderer::convert2dTo3d (const QPoint& position2d, bool snap) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
508 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
509 if (camera() == FreeCamera)
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
510 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
511 return {0, 0, 0};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
512 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
513 else
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
515 Vertex position3d;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
516 const CameraInfo* camera = &g_cameraInfo[this->camera()];
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
517 Axis axisX = camera->localX;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
518 Axis axisY = camera->localY;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
519 int signX = camera->negatedX ? -1 : 1;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
520 int signY = camera->negatedY ? -1 : 1;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
522 // Calculate cx and cy - these are the LDraw unit coords the cursor is at.
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
523 double cx = (-m_virtualWidth + ((2 * position2d.x() * m_virtualWidth) / m_width) - panning(X));
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
524 double cy = (m_virtualHeight - ((2 * position2d.y() * m_virtualHeight) / m_height) - panning(Y));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
525
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
526 if (snap)
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
527 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
528 cx = grid()->snap(cx, Grid::Coordinate);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
529 cy = grid()->snap(cy, Grid::Coordinate);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
530 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
532 cx *= signX;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
533 cy *= signY;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
534 roundToDecimals(cx, 4);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
535 roundToDecimals(cy, 4);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
536
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
537 // Create the vertex from the coordinates
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
538 position3d.setCoordinate(axisX, cx);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
539 position3d.setCoordinate(axisY, cy);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
540 position3d.setCoordinate(static_cast<Axis>(3 - axisX - axisY), getDepthValue());
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
541 return position3d;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
542 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
543 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
544
1096
7cc929d8fc4d Simplified GLRenderer::convert3dTo2d. The multiplication with the modelview matrix is not necessary, it's identity all the time... with that, I think the function makes much more sense now.
Teemu Piippo <teemu@hecknology.net>
parents: 1095
diff changeset
545 /*
7cc929d8fc4d Simplified GLRenderer::convert3dTo2d. The multiplication with the modelview matrix is not necessary, it's identity all the time... with that, I think the function makes much more sense now.
Teemu Piippo <teemu@hecknology.net>
parents: 1095
diff changeset
546 * Inverse operation for the above - convert a 3D position to a 2D screen position.
7cc929d8fc4d Simplified GLRenderer::convert3dTo2d. The multiplication with the modelview matrix is not necessary, it's identity all the time... with that, I think the function makes much more sense now.
Teemu Piippo <teemu@hecknology.net>
parents: 1095
diff changeset
547 */
7cc929d8fc4d Simplified GLRenderer::convert3dTo2d. The multiplication with the modelview matrix is not necessary, it's identity all the time... with that, I think the function makes much more sense now.
Teemu Piippo <teemu@hecknology.net>
parents: 1095
diff changeset
548 QPoint GLRenderer::convert3dTo2d(const Vertex& position3d) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
549 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
550 if (camera() == FreeCamera)
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
551 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
552 return {0, 0};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
553 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
554 else
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
555 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
556 const CameraInfo* camera = &g_cameraInfo[this->camera()];
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
557 Axis axisX = camera->localX;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
558 Axis axisY = camera->localY;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
559 int signX = camera->negatedX ? -1 : 1;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
560 int signY = camera->negatedY ? -1 : 1;
1096
7cc929d8fc4d Simplified GLRenderer::convert3dTo2d. The multiplication with the modelview matrix is not necessary, it's identity all the time... with that, I think the function makes much more sense now.
Teemu Piippo <teemu@hecknology.net>
parents: 1095
diff changeset
561 int rx = (((position3d[axisX] * signX) + m_virtualWidth + panning(X)) * m_width) / (2 * m_virtualWidth);
7cc929d8fc4d Simplified GLRenderer::convert3dTo2d. The multiplication with the modelview matrix is not necessary, it's identity all the time... with that, I think the function makes much more sense now.
Teemu Piippo <teemu@hecknology.net>
parents: 1095
diff changeset
562 int ry = (((position3d[axisY] * signY) - m_virtualHeight + panning(Y)) * m_height) / (2 * m_virtualHeight);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
563 return {rx, -ry};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
564 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
567 QPen GLRenderer::textPen() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
568 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
569 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
570 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
571
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
572 QPen GLRenderer::linePen() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
573 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
574 QPen linepen = m_thinBorderPen;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
575 linepen.setWidth(2);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
576 linepen.setColor(luma(m_backgroundColor) < 40 ? Qt::white : Qt::black);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
577 return linepen;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
578 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
579
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
582 void GLRenderer::paintEvent(QPaintEvent*)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
584 makeCurrent();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
585 m_virtualWidth = zoom();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
586 m_virtualHeight = (m_height * m_virtualWidth) / m_width;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
587 initGLData();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
588 drawGLScene();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
589 QPainter painter {this};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
590 QFontMetrics metrics {QFont {}};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
591 painter.setRenderHint(QPainter::Antialiasing);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 // If we wish to only draw the brick, stop here
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
594 if (isDrawOnly() or m_isDrawingSelectionScene)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
595 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
597 #ifndef RELEASE
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
598 {
1092
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
599 QString text = format("Rotation: %1\nPanning: (%2, %3), Zoom: %4",
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
600 m_rotationMatrix, panning(X), panning(Y), zoom());
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
601 QRect textSize = metrics.boundingRect(0, 0, m_width, m_height, Qt::AlignCenter, text);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
602 painter.setPen(textPen());
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
603 painter.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
604 textSize.height(), Qt::AlignCenter, text);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
605 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
606 #endif
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
607
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
608 if (camera() != FreeCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
609 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
610 // Paint the overlay image if we have one
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
611 const LDGLOverlay& overlay = m_overlays[camera()];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
612
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
613 if (overlay.image)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 {
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
615 QPoint v0 = convert3dTo2d(m_overlays[camera()].v0);
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
616 QPoint v1 = convert3dTo2d(m_overlays[camera()].v1);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
617 QRect targetRect = {v0.x(), v0.y(), qAbs(v1.x() - v0.x()), qAbs(v1.y() - v0.y())};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
618 QRect sourceRect = {0, 0, overlay.image->width(), overlay.image->height()};
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
619 painter.drawImage(targetRect, *overlay.image, sourceRect);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
620 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
622 // Paint the coordinates onto the screen.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
623 QString text = format(tr("X: %1, Y: %2, Z: %3"), m_position3D[X], m_position3D[Y], m_position3D[Z]);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
624 QFontMetrics metrics {font()};
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
625 QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
626 painter.setPen(textPen());
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
627 painter.drawText(m_width - textSize.width(), m_height - 16,
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
628 textSize.width(), textSize.height(), Qt::AlignCenter, text);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
629 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
630
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
631 {
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
632 // Draw edit mode HUD
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
633 m_currentEditMode->render(painter);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
634
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635 // Draw a background for the selected camera
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
636 painter.setPen(m_thinBorderPen);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
637 painter.setBrush(QBrush {QColor {0, 128, 160, 128}});
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
638 painter.drawRect(m_cameraIcons[camera()].hitRect);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
640 // Draw the camera icons
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
641 for (CameraIcon& info : m_cameraIcons)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
643 // Don't draw the free camera icon when we can't use the free camera
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
644 if (&info == &m_cameraIcons[FreeCamera] and not m_currentEditMode->allowFreeCamera())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
646
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
647 painter.drawPixmap(info.targetRect, info.image, info.sourceRect);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
648 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
650 // Draw a label for the current camera in the bottom left corner
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
651 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
652 int margin = 4;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
653 painter.setPen(textPen());
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
654 painter.drawText(QPoint {margin, height() - margin - metrics.descent()}, currentCameraName());
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
655
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
656 // Also render triangle count.
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
657 if (m_model)
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
658 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
659 QPoint renderPoint = {margin, height() - margin - metrics.height() - metrics.descent()};
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
660 painter.drawText(renderPoint, format("â–³ %1", m_model->triangleCount()));
1015
92c6ec099075 Added triangle count to viewport, added compile-time line length check
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
661 }
655
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 // Tool tips
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
665 if (m_drawToolTip)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
667 if (not m_cameraIcons[m_toolTipCamera].targetRect.contains (m_mousePosition))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668 m_drawToolTip = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
669 else
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
670 QToolTip::showText(m_globalpos, currentCameraName());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
671 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
672 }
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 // Message log
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
675 if (m_window->messageLog())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
676 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
677 int y = 0;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
678 int margin = 2;
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
679 QColor penColor = textPen().color();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
680
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
681 for (const MessageManager::Line& line : m_window->messageLog()->getLines())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
682 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
683 penColor.setAlphaF(line.alpha);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
684 painter.setPen(penColor);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
685 painter.drawText(QPoint {margin, y + margin + metrics.ascent()}, line.text);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686 y += metrics.height();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
687 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
688 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
689 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
690
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 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
693 void GLRenderer::drawPoint(QPainter& painter, QPointF pos, QColor color) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
694 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
695 int pointSize = 8;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
696 QPen pen = m_thinBorderPen;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
697 pen.setWidth(1);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
698 painter.setPen(pen);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
699 painter.setBrush(color);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
700 painter.drawEllipse(pos.x() - pointSize / 2, pos.y() - pointSize / 2, pointSize, pointSize);
1008
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
701 }
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
702
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
703 void GLRenderer::drawBlipCoordinates(QPainter& painter, const Vertex& pos3d)
1008
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
704 {
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
705 drawBlipCoordinates (painter, pos3d, convert3dTo2d (pos3d));
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
706 }
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
707
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
708 void GLRenderer::drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos)
1008
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
709 {
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
710 painter.setPen (textPen());
74cb432812d3 Fixed circle, rectangle and line path modes not working anymore. Add blip coordinates to curve and line path modes. Circle mode for now only can show the coordinates of the initial blip
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1000
diff changeset
711 painter.drawText (pos.x(), pos.y() - 8, pos3d.toString (true));
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
712 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
714 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
715 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
716 void GLRenderer::mouseReleaseEvent(QMouseEvent* ev)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
717 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
718 bool wasLeft = (m_lastButtons & Qt::LeftButton) and not (ev->buttons() & Qt::LeftButton);
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
719 Qt::MouseButtons releasedbuttons = m_lastButtons & ~ev->buttons();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
720 m_panning = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
721
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
722 if (wasLeft)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
723 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
724 // Check if we selected a camera icon
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
725 if (not mouseHasMoved())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
727 for (CameraIcon& info : m_cameraIcons)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
728 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
729 if (info.targetRect.contains (ev->pos()))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
730 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
731 setCamera (info.camera);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 goto end;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 }
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 }
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
736 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
738 if (not isDrawOnly())
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
739 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
740 AbstractEditMode::MouseEventData data;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
741 data.ev = ev;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
742 data.mouseMoved = mouseHasMoved();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
743 data.keymods = m_currentKeyboardModifiers;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
744 data.releasedButtons = releasedbuttons;
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
745
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
746 if (m_currentEditMode->mouseReleased (data))
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
747 goto end;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
749
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
750 end:
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
751 update();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
752 m_totalMouseMove = 0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
753 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
754
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
755 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
757 void GLRenderer::mousePressEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
759 m_totalMouseMove = 0;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
760 m_lastButtons = event->buttons();
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
761
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
762 if (m_currentEditMode->mousePressed(event))
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
763 event->accept();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
764 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
765
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766 // =============================================================================
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
767 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
768 void GLRenderer::mouseMoveEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
769 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
770 int xMove = event->x() - m_mousePosition.x();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
771 int yMove = event->y() - m_mousePosition.y();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
772 m_totalMouseMove += qAbs(xMove) + qAbs(yMove);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
773 m_isCameraMoving = false;
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
774
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
775 if (not m_currentEditMode->mouseMoved (event))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
776 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
777 bool left = event->buttons() & Qt::LeftButton;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
778 bool mid = event->buttons() & Qt::MidButton;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
779 bool shift = event->modifiers() & Qt::ShiftModifier;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
780
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
781 if (mid or (left and shift))
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
782 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
783 panning(X) += 0.03f * xMove * (zoom() / 7.5f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
784 panning(Y) -= 0.03f * yMove * (zoom() / 7.5f);
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
785 m_panning = true;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
786 m_isCameraMoving = true;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
787 }
1092
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
788 else if (left and camera() == FreeCamera and (xMove != 0 or yMove != 0))
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
789 {
1092
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
790 // Apply current rotation input to the rotation matrix
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
791 // ref: https://forums.ldraw.org/thread-22006-post-24426.html#pid24426
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
792 glPushMatrix();
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
793 glLoadIdentity();
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
794 // 0.6 is an arbitrary rotation sensitivity scalar
1094
8a419cead363 Changed from GLdouble to GLfloat. Apparently the performance difference is greater on the GPU..? It doesn't really matter but let's be consistent.
Teemu Piippo <teemu@hecknology.net>
parents: 1093
diff changeset
795 glRotatef(0.6 * hypot(xMove, yMove), yMove, xMove, 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
796 glMultMatrixf(m_rotationMatrix.constData());
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
797 glGetFloatv(GL_MODELVIEW_MATRIX, m_rotationMatrix.data());
1092
7a50a7f6b492 Switched from euler angle rotation to matrix rotation. Gimbal lock is now broken.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
798 glPopMatrix();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
799 m_isCameraMoving = true;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
800 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
801 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
802
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
803 // 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
804 if (not m_drawToolTip)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
805 m_toolTipTimer->start (500);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
807 // Update 2d position
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
808 m_mousePosition = event->pos();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
809 m_globalpos = event->globalPos();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
810 m_mousePositionF = event->localPos();
655
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 // Calculate 3d position of the cursor
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
813 m_position3D = (camera() != FreeCamera) ? convert2dTo3d (m_mousePosition, true) : Origin;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814
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
815 highlightCursorObject();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816 update();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
817 event->accept();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
820 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
821 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
822 void GLRenderer::keyPressEvent(QKeyEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
823 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
824 m_currentKeyboardModifiers = event->modifiers();
655
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 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
828 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
829 void GLRenderer::keyReleaseEvent(QKeyEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
830 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
831 m_currentKeyboardModifiers = event->modifiers();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
832 m_currentEditMode->keyReleased(event);
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 869
diff changeset
833 update();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
834 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
835
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
836 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
837 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
838 void GLRenderer::wheelEvent(QWheelEvent* ev)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
839 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
840 makeCurrent();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
841 zoomNotch(ev->delta() > 0);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
842 zoom() = qBound(0.01, zoom(), 10000.0);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
843 m_isCameraMoving = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
844 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
845 ev->accept();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
846 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
847
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 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
850 void GLRenderer::leaveEvent(QEvent*)
655
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 m_drawToolTip = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
853 m_toolTipTimer->stop();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
854 update();
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 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
859 void GLRenderer::contextMenuEvent(QContextMenuEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
860 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
861 m_window->spawnContextMenu(event->globalPos());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
862 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
863
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
864 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
865 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
866 void GLRenderer::setCamera(Camera camera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
867 {
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
868 // The edit mode may forbid the free camera.
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
869 if (m_currentEditMode->allowFreeCamera() 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
870 {
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
871 m_camera = camera;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
872 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
873 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
874 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
875
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
876 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
877 //
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
878 void GLRenderer::pick (int mouseX, int mouseY, bool additive)
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
879 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
880 pick (QRect (mouseX, mouseY, mouseX + 1, mouseY + 1), additive);
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
881 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
882
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
883 // =============================================================================
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
884 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
885 void GLRenderer::pick(const QRect& range, bool additive)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
886 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
887 makeCurrent();
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
888 QSet<LDObject*> priorSelection = selectedObjects();
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
889 QSet<LDObject*> newSelection;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
890
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
891 // If we're doing an additive selection, we start off with the existing selection.
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
892 // Otherwise we start selecting from scratch.
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
893 if (additive)
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
894 newSelection = priorSelection;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
895
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
896 // Paint the picking scene
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
897 setPicking(true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
898 drawGLScene();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
899
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
900 int x0 = range.left();
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
901 int y0 = range.top();
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
902 int x1 = x0 + range.width();
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
903 int y1 = y0 + range.height();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
904
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
905 // 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
906 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
907 y0 = qMax (0, y0);
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
908 x1 = qMin (x1, m_width);
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
909 y1 = qMin (y1, m_height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
910 const int areawidth = (x1 - x0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
911 const int areaheight = (y1 - y0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
912 const qint32 numpixels = areawidth * areaheight;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
913
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
914 // Allocate space for the pixel data.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
915 QVector<unsigned char> pixelData;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
916 pixelData.resize(4 * numpixels);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
917
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
918 // Read pixels from the color buffer.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
919 glReadPixels(x0, m_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
920
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
921 QSet<int32_t> indices;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
922
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
923 // 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
924 // Each pixel maps to an LDObject index injectively.
753
Santeri Piippo <crimsondusk64@gmail.com>
parents: 752
diff changeset
925 // Note: black is background, those indices are skipped.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
926 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
927 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
928 int32_t index = pixelCursor[0] * 0x10000 +
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
929 pixelCursor[1] * 0x100 +
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
930 pixelCursor[2] * 0x1;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
931 if (index != 0)
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
932 indices.insert(index);
752
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
933 }
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
934
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
935 // 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
936 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
937 {
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
938 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
939
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
940 if (object != nullptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
941 {
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
942 // If this is an additive single pick and the object is currently selected,
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
943 // we remove it from selection instead.
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
944 if (additive and newSelection.contains(object))
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
945 newSelection.remove(object);
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
946 else
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
947 newSelection.insert(object);
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
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
951 // Select all objects that we now have selected that were not selected before.
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
952 for (LDObject* object : newSelection - priorSelection)
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
953 {
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
954 currentDocument()->addToSelection(object);
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
955 compileObject(object);
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
956 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
957
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
958 // Likewise, deselect whatever was selected that isn't anymore.
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
959 for (LDObject* object : priorSelection - newSelection)
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
960 {
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
961 currentDocument()->removeFromSelection(object);
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
962 compileObject(object);
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
963 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
964
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
965 m_window->updateSelection();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
966 setPicking(false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
967 repaint();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
968 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
969
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
970 //
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
971 // Simpler version of GLRenderer::pick which simply picks whatever object on the cursor
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
972 //
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
973 LDObject* GLRenderer::pickOneObject (int mouseX, int mouseY)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
974 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
975 unsigned char pixel[4];
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
976 makeCurrent();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
977 setPicking(true);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
978 drawGLScene();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
979 glReadPixels(mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
980 LDObject* object = LDObject::fromID(pixel[0] * 0x10000 +
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
981 pixel[1] * 0x100 +
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
982 pixel[2] * 0x1);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
983 setPicking(false);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
984 repaint();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
985 return object;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
986 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
987
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
988 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
989 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
990 void GLRenderer::setEditMode(EditModeType a)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
991 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
992 if (m_currentEditMode and m_currentEditMode->type() == a)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
993 return;
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
994
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
995 delete m_currentEditMode;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
996 m_currentEditMode = AbstractEditMode::createByType(this, a);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
997
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
998 // If we cannot use the free camera, use the top one instead.
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
999 if (camera() == FreeCamera and not m_currentEditMode->allowFreeCamera())
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1000 setCamera(TopCamera);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1001
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
1002 m_window->updateEditModeActions();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1003 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1004 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1005
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1006 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1007 //
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1008 EditModeType GLRenderer::currentEditModeType() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1009 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1010 return m_currentEditMode->type();
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1011 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1012
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1013 // =============================================================================
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1014 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1015 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
1016 {
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
1017 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
1018 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
1019
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
1020 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
1021 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1022 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
1023
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
1024 // 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
1025 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
1026 }
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
1027 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
1028 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1029 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
1030
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
1031 // Restore line thickness
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1032 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
1033 }
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
1034 }
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
1035
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
1036 // =============================================================================
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
1037 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1038 void GLRenderer::getRelativeAxes(Axis& relativeX, Axis& relativeY) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1039 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1040 const CameraInfo* camera = &g_cameraInfo[this->camera()];
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1041 relativeX = camera->localX;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1042 relativeY = camera->localY;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1043 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1044
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1045 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1046 //
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
1047 Axis GLRenderer::getRelativeZ() const
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
1048 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1049 const CameraInfo* camera = &g_cameraInfo[this->camera()];
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1050 return static_cast<Axis>(3 - camera->localX - camera->localY);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1051 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1052
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1053 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1054 //
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
1055 void GLRenderer::compileObject (LDObject* obj)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1056 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1057 compiler()->stageForCompilation (obj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1058 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1059
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1060 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1061 //
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1062 void GLRenderer::forgetObject(LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1063 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1064 compiler()->dropObjectInfo(obj);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1065 compiler()->unstage(obj);
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 973
diff changeset
1066
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 973
diff changeset
1067 if (m_objectAtCursor == obj)
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 973
diff changeset
1068 m_objectAtCursor = nullptr;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1069 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1070
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1071 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1072 //
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1073 QByteArray GLRenderer::capturePixels()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1074 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1075 QByteArray result;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1076 result.resize (4 * width() * height());
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1077 m_takingScreenCapture = true;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1078 update(); // Smile!
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1079 m_takingScreenCapture = false;
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
1080 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
1081 return result;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1082 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1083
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1084 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1085 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1086 void GLRenderer::slot_toolTipTimer()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1087 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1088 // 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
1089 // 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
1090 // a tooltip.
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1091 for (CameraIcon & icon : m_cameraIcons)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1092 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1093 if (icon.targetRect.contains (m_mousePosition))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1094 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1095 m_toolTipCamera = icon.camera;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1096 m_drawToolTip = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1097 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1098 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1099 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1100 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1101 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1102
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1103 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1104 //
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1105 Axis GLRenderer::getCameraAxis (bool y, Camera camid)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1106 {
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1107 if (camid == (Camera) -1)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1108 camid = camera();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1109
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1110 const CameraInfo* cam = &g_cameraInfo[camid];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1111 return (y) ? cam->localY : cam->localX;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1112 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1113
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1114 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1115 //
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1116 bool GLRenderer::setupOverlay (Camera camera, QString fileName, int x, int y, int w, int h)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1117 {
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1118 QImage* image = new QImage (QImage (fileName).convertToFormat (QImage::Format_ARGB32));
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1119 LDGLOverlay& info = getOverlay (camera);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1120
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1121 if (image->isNull())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1122 {
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 875
diff changeset
1123 Critical (tr ("Failed to load overlay image!"));
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
1124 m_overlays[camera].invalid = true;
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1125 delete image;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1126 return false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1127 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1128
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1129 delete info.image; // delete the old image
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1130
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1131 info.fileName = fileName;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1132 info.width = w;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1133 info.height = h;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1134 info.offsetX = x;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1135 info.offsetY = y;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1136 info.image = image;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1137 info.invalid = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1138
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1139 if (info.width == 0)
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1140 info.width = (info.height * image->width()) / image->height();
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1141 else if (info.height == 0)
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1142 info.height = (info.width * image->height()) / image->width();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1143
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1144 Axis localX = getCameraAxis (false, camera);
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1145 Axis localY = getCameraAxis (true, camera);
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1146 int signX = g_cameraInfo[camera].negatedX ? -1 : 1;
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1147 int signY = g_cameraInfo[camera].negatedY ? -1 : 1;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1148
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
1149 info.v0 = info.v1 = Origin;
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1150 info.v0.setCoordinate (localX, -(info.offsetX * info.width * signX) / image->width());
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1151 info.v0.setCoordinate (localY, (info.offsetY * info.height * signY) / image->height());
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1152 info.v1.setCoordinate (localX, info.v0[localX] + info.width);
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1153 info.v1.setCoordinate (localY, info.v0[localY] + info.height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1154
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1155 // Set alpha of all pixels to 0.5
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1156 for (int i = 0; i < image->width(); ++i)
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1157 for (int j = 0; j < image->height(); ++j)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1158 {
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1159 uint32 pixel = image->pixel (i, j);
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1160 image->setPixel (i, j, 0x80000000 | (pixel & 0x00FFFFFF));
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1161 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1162
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1163 updateOverlayObjects();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1164 return true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1165 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1166
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1167 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1168 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1169 void GLRenderer::clearOverlay()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1170 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1171 if (camera() == FreeCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1172 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1173
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
1174 LDGLOverlay& info = m_overlays[camera()];
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1175 delete info.image;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1176 info.image = nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1177
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1178 updateOverlayObjects();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1179 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1180
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1181 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1182 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1183 void GLRenderer::setDepthValue (double depth)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1184 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1185 if (camera() < FreeCamera)
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
1186 m_depthValues[camera()] = depth;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1187 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1188
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1189 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1190 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1191 double GLRenderer::getDepthValue() const
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1192 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1193 if (camera() < FreeCamera)
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
1194 return m_depthValues[camera()];
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
1195 else
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
1196 return 0.0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1197 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1198
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1199 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1200 //
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1201 QString GLRenderer::cameraName (Camera camera) const
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1202 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1203 switch (camera)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1204 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1205 case TopCamera: return tr ("Top Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1206 case FrontCamera: return tr ("Front Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1207 case LeftCamera: return tr ("Left Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1208 case BottomCamera: return tr ("Bottom Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1209 case BackCamera: return tr ("Back Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1210 case RightCamera: return tr ("Right Camera");
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1211 case FreeCamera: return tr ("Free Camera");
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1212 default: break;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1213 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1214
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1215 return "";
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1216 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1217
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1218 QString GLRenderer::currentCameraName() const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1219 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1220 return cameraName (camera());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1221 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1222
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1223 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1224 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1225 LDGLOverlay& GLRenderer::getOverlay (int newcam)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1226 {
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
1227 return m_overlays[newcam];
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1228 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1229
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1230 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1231 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1232 void GLRenderer::zoomNotch (bool inward)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1233 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1234 zoom() *= inward ? 0.833f : 1.2f;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1235 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1236
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1237 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1238 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1239 void GLRenderer::zoomToFit()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1240 {
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1241 zoom() = 30.0f;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1242
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
1243 if (model() == nullptr or m_width == -1 or m_height == -1)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1244 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1245
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1246 bool lastfilled = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1247 bool firstrun = true;
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1248 enum { black = 0xFF000000 };
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1249 bool inward = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1250 int runaway = 50;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1251
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1252 // 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
1253 // are background or not.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1254 setPicking (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1255
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1256 while (--runaway)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1257 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
1258 if (zoom() > 10000.0 or zoom() < 0.0)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1259 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1260 // Nothing to draw if we get here.
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1261 zoom() = 30.0;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1262 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1263 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1264
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1265 zoomNotch (inward);
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1266 QVector<unsigned char> capture (4 * m_width * m_height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1267 drawGLScene();
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1268 glReadPixels (0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, capture.data());
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1269 QImage image (capture.constData(), m_width, m_height, QImage::Format_ARGB32);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1270 bool filled = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1271
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1272 // 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
1273 for (int i = 0; i < image.width(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1274 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1275 if (image.pixel (i, 0) != black or image.pixel (i, m_height - 1) != black)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1276 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1277 filled = true;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1278 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1279 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1280 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1281
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1282 // Left and right edges
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1283 if (filled == false)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1284 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1285 for (int i = 0; i < image.height(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1286 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1287 if (image.pixel (0, i) != black or image.pixel (m_width - 1, i) != black)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1288 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1289 filled = true;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1290 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
1291 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1292 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1293 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1294
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1295 if (firstrun)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1296 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1297 // 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
1298 // 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
1299 // 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
1300 inward = not filled;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1301 firstrun = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1302 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1303 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1304 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1305 // 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
1306 // 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
1307 if (filled and not lastfilled)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1308 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1309 zoomNotch (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1310 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1311 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1312
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1313 // 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
1314 // 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
1315 if (not filled and lastfilled)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1316 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1317
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
1318 inward = not filled;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1319 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1320
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1321 lastfilled = filled;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1322 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1323
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1324 setPicking (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1325 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1326
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1327 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1328 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1329 void GLRenderer::zoomAllToFit()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1330 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
1331 zoomToFit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1332 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1333
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1334 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1335 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1336 void GLRenderer::mouseDoubleClickEvent (QMouseEvent* ev)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1337 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1338 if (m_currentEditMode->mouseDoubleClicked (ev))
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
1339 ev->accept();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1340 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1341
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1342 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1343 //
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1344 LDOverlay* GLRenderer::findOverlayObject (Camera cam)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1345 {
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
1346 for (LDObject* obj : model()->objects())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1347 {
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
1348 LDOverlay* overlay = dynamic_cast<LDOverlay*> (obj);
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1349
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
1350 if (overlay and overlay->camera() == cam)
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
1351 return overlay;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1352 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1353
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
1354 return nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1355 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1356
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1357 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1358 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1359 // Read in overlays from the current file and update overlay info accordingly.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1360 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1361 void GLRenderer::initOverlaysFromObjects()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1362 {
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
1363 for (Camera camera : iterateEnum<Camera>())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1364 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1365 if (camera == FreeCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1366 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1367
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
1368 LDGLOverlay& meta = m_overlays[camera];
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1369 LDOverlay* overlay = findOverlayObject (camera);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1370
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1371 if (overlay == nullptr and meta.image)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1372 {
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1373 // The document doesn't have an overlay for this camera but we have an image for it, delete the image.
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1374 delete meta.image;
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1375 meta.image = nullptr;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1376 }
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1377 else if (overlay
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1378 and (meta.image == nullptr or meta.fileName != overlay->fileName())
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1379 and not meta.invalid)
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1380 {
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1381 // Found a valid overlay definition for this camera, set it up for use.
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1382 setupOverlay (camera, overlay->fileName(), overlay->x(),
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1383 overlay->y(), overlay->width(), overlay->height());
768
29e6c5552388 - initial overhaul with smart pointers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 767
diff changeset
1384 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1385 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1386 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1387
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1388 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1389 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1390 void GLRenderer::updateOverlayObjects()
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1391 {
1036
993c46d7eb75 Replaced the ugly for_enum macro with a generator class
Teemu Piippo <teemu@compsta2.com>
parents: 1035
diff changeset
1392 for (Camera camera : iterateEnum<Camera>())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1393 {
1035
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
1394 if (camera == FreeCamera)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1395 continue;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1396
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
1397 LDGLOverlay& meta = m_overlays[camera];
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1398 LDOverlay* overlayObject = findOverlayObject (camera);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1399
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1400 if (meta.image == nullptr and overlayObject)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1401 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1402 // If this is the last overlay image, we need to remove the empty space after it as well.
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1403 LDObject* nextobj = overlayObject->next();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1404
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
1405 if (nextobj and nextobj->type() == OBJ_Empty)
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
1406 model()->remove(nextobj);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1407
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1408 // If the overlay object was there and the overlay itself is
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1409 // not, remove the object.
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
1410 model()->remove(overlayObject);
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1411 overlayObject = nullptr;
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
1412 }
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1413 else if (meta.image and overlayObject == nullptr)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1414 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1415 // Inverse case: image is there but the overlay object is
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1416 // not, thus create the object.
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1417 //
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1418 // Find a suitable position to place this object. We want to place
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1419 // this into the header, which is everything up to the first scemantic
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1420 // object. If we find another overlay object, place this object after
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1421 // the last one found. Otherwise, place it before the first schemantic
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1422 // object and put an empty object after it (though don't do this if
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1423 // there was no schemantic elements at all)
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1424 int i;
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1425 int lastOverlayPosition = -1;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1426 bool found = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1427
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
1428 for (i = 0; i < model()->size(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1429 {
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
1430 LDObject* object = model()->getObject (i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1431
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1432 if (object->isScemantic())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1433 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1434 found = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1435 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1436 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1437
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1438 if (object->type() == OBJ_Overlay)
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1439 lastOverlayPosition = i;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1440 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1441
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1442 if (lastOverlayPosition != -1)
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1443 {
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
1444 overlayObject = model()->emplaceAt<LDOverlay>(lastOverlayPosition + 1);
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1445 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1446 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1447 {
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
1448 overlayObject = model()->emplaceAt<LDOverlay>(i);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1449
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1450 if (found)
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
1451 model()->emplaceAt<LDEmpty>(i + 1);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1452 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1453 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1454
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1455 if (meta.image and overlayObject)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1456 {
1079
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1457 overlayObject->setCamera (camera);
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1458 overlayObject->setFileName (meta.fileName);
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1459 overlayObject->setX (meta.offsetX);
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1460 overlayObject->setY (meta.offsetY);
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1461 overlayObject->setWidth (meta.width);
67c6e5d32e68 More rework on model stuff, removals of LDSpawn calls. Most importantly, the LDraw code parsing function was moved to Model.
Teemu Piippo <teemu@hecknology.net>
parents: 1075
diff changeset
1462 overlayObject->setHeight (meta.height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1463 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1464 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1465
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
1466 if (m_window->renderer() == this)
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
1467 m_window->refresh();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1468 }
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
1469
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
1470 // =============================================================================
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
1471 //
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
1472 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
1473 {
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
1474 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
1475 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
1476
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
1477 LDObject* newObject = nullptr;
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
1478 LDObject* oldObject = objectAtCursor();
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1479 qint32 newIndex;
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1480
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
1481 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
1482 {
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1483 newIndex = 0;
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1484 }
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1485 else
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1486 {
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1487 setPicking (true);
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1488 drawGLScene();
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1489 setPicking (false);
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1490
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1491 unsigned char pixel[4];
766
df2a48223e53 - renamed some renderer members
Santeri Piippo <crimsondusk64@gmail.com>
parents: 763
diff changeset
1492 glReadPixels (m_mousePosition.x(), m_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
1493 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
1494 }
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
1495
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
1496 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
1497 {
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
1498 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
1499 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
1500
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1501 m_objectAtCursor = newObject;
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
1502
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
1503 if (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
1504 compileObject (oldObject);
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
1505
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
1506 if (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
1507 compileObject (newObject);
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
1508 }
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
1509
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
1510 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
1511 }
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
1512
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1513 void GLRenderer::dragEnterEvent (QDragEnterEvent* ev)
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1514 {
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
1515 if (m_window and ev->source() == m_window->getPrimitivesTree() and m_window->getPrimitivesTree()->currentItem())
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1516 ev->acceptProposedAction();
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1517 }
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1518
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1519 void GLRenderer::dropEvent (QDropEvent* ev)
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1520 {
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
1521 if (m_window and ev->source() == m_window->getPrimitivesTree())
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1522 {
1010
969b48eddd6b A bit more cleanup. Finally removed the PROPERTY macro. (now let's see about making a new one sometime that isn't so terrible?)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1008
diff changeset
1523 PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*> (m_window->getPrimitivesTree()->currentItem());
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1524 QString primitiveName = item->primitive()->name;
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
1525 LDSubfileReference* ref = currentDocument()->emplaceAt<LDSubfileReference>(m_window->suggestInsertPoint());
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
1526 ref->setFileInfo (m_documents->getDocumentByName (primitiveName));
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
1527 currentDocument()->addToSelection(ref);
981
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
1528 m_window->buildObjectList();
5d5d84ab2c48 Refactor MainWindow's API
Teemu Piippo <crimsondusk64@gmail.com>
parents: 978
diff changeset
1529 m_window->renderer()->refresh();
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1530 ev->acceptProposedAction();
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1531 }
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
1532 }
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1533
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1534 Vertex const& GLRenderer::position3D() const
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1535 {
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1536 return m_position3D;
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1537 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1538
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1539 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
1540 {
1035
8a60250175ba Further improved enum handling
Teemu Piippo <teemu@compsta2.com>
parents: 1034
diff changeset
1541 if (valueInEnum<Camera>(camera))
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1542 return g_cameraInfo[camera];
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1543 else
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1544 return g_cameraInfo[0];
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
1545 }
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1546
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1547 bool GLRenderer::mouseHasMoved() const
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1548 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1549 return m_totalMouseMove >= 10;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1550 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1551
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1552 QPoint const& GLRenderer::mousePosition() const
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1553 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1554 return m_mousePosition;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
1555 }
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
1556
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1557 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
1558 {
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1559 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
1560 }
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1561
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
1562 void GLRenderer::makeCurrent()
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
1563 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
1564 QGLWidget::makeCurrent();
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
1565 initializeOpenGLFunctions();
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
1566 }
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1567
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1568 int GLRenderer::depthNegateFactor() const
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1569 {
1034
a05fc8256a3a Enum stuff
Teemu Piippo <teemu@compsta2.com>
parents: 1033
diff changeset
1570 return g_cameraInfo[camera()].negatedDepth ? -1 : 1;
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1571 }
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
1572
897
ef9e4469975a - pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
1573 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
1574 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1575 return m_currentKeyboardModifiers;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1576 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1577
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1032
diff changeset
1578 Camera GLRenderer::camera() const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1579 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1580 return m_camera;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1581 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1582
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1583 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
1584 {
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
1585 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
1586 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
1587 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1588
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1589 double GLRenderer::panning (Axis ax) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1590 {
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
1591 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
1592 m_panY[camera()];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1593 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1594
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1595 double& GLRenderer::zoom()
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1596 {
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
1597 return m_zoom[camera()];
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
1598 }
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1599
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1600
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1601 //
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1602 // ---------------------------------------------------------------------------------------------------------------------
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1603 //
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1604
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1605 LDGLOverlay::~LDGLOverlay()
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1606 {
1032
376db8dd6a42 Unabbreviated overlay member names
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
1607 delete image;
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
1608 }

mercurial