Thu, 07 Feb 2019 15:43:18 +0200
reworked selection model handling
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
740
dbf9f1294d94
- apply #pragma once to glShared.h
Santeri Piippo <crimsondusk64@gmail.com>
parents:
739
diff
changeset
|
19 | #pragma once |
1049
71946fed475a
Removed the USE_QT5 macro now that we're Qt5 only.
Teemu Piippo <teemu@hecknology.net>
parents:
1036
diff
changeset
|
20 | #include <QOpenGLFunctions> |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1123
diff
changeset
|
21 | #include <QGenericMatrix> |
1023
9450ac3cd930
Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1014
diff
changeset
|
22 | #include "basics.h" |
1400 | 23 | #include "colors.h" |
24 | #include "generics/enums.h" | |
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
1313
diff
changeset
|
25 | #include "types/vertex.h" |
856
6bdc03091441
- and fixed compilation on linux systems too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
855
diff
changeset
|
26 | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | class LDObject; |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
1437
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
29 | namespace gl |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
30 | { |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
31 | enum CameraType |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
32 | { |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
33 | TopCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
34 | FrontCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
35 | LeftCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
36 | BottomCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
37 | BackCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
38 | RightCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
39 | FreeCamera, |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
40 | _End |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
41 | }; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
42 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
43 | struct CameraIcon |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
44 | { |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
45 | QPixmap image; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
46 | QRect sourceRect; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
47 | QRect targetRect; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
48 | QRect hitRect; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
49 | CameraType camera; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
50 | }; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
51 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
52 | class Renderer; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
53 | class Compiler; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
54 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
55 | static const QPen thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
56 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
57 | // Transformation matrices for the fixed cameras. |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
58 | static const QMatrix4x4 topCameraMatrix = {}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
59 | static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
60 | static const QMatrix4x4 leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
61 | static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
62 | static const QMatrix4x4 backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
63 | static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
64 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
65 | // Conversion matrix from LDraw to OpenGL coordinates. |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
66 | static const QMatrix4x4 ldrawToGLAdapterMatrix = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
67 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
68 | enum { BlackRgb = 0xff000000 }; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
69 | static constexpr GLfloat near = 1.0f; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
70 | static constexpr GLfloat far = 10000.0f; |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
71 | } |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
72 | |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
73 | MAKE_ITERABLE_ENUM(gl::CameraType) |
1a77c6156db7
commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents:
1405
diff
changeset
|
74 | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | struct LDPolygon |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | { |
1400 | 77 | enum class Type : qint8 { InvalidPolygon, EdgeLine, Triangle, Quadrilateral, ConditionalEdge }; |
78 | Type type = Type::InvalidPolygon; | |
79 | Vertex vertices[4]; | |
80 | LDColor color; | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
1305
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1278
diff
changeset
|
82 | inline int numPolygonVertices() const |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1278
diff
changeset
|
83 | { |
1400 | 84 | if (type == Type::ConditionalEdge) |
85 | return 2; | |
86 | else | |
87 | return numVertices(); | |
1305
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1278
diff
changeset
|
88 | } |
31627acdd4b5
Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents:
1278
diff
changeset
|
89 | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | inline int numVertices() const |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | { |
1400 | 92 | switch (type) |
93 | { | |
94 | case Type::EdgeLine: | |
95 | return 2; | |
96 | ||
97 | case Type::Triangle: | |
98 | return 3; | |
99 | ||
100 | case Type::ConditionalEdge: | |
101 | case Type::Quadrilateral: | |
102 | return 4; | |
103 | ||
104 | case Type::InvalidPolygon: | |
105 | return 0; | |
106 | } | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | bool isValid() const | |
112 | { | |
113 | return type != Type::InvalidPolygon; | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | }; |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
1245 | 117 | Q_DECLARE_METATYPE(LDPolygon) |
118 | ||
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
119 | enum class VboClass |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
121 | Lines, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
122 | Triangles, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
123 | Quads, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
124 | ConditionalLines, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
125 | _End |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | }; |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
128 | MAKE_ITERABLE_ENUM(VboClass) |
1033 | 129 | |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
130 | enum class VboSubclass |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
132 | Surfaces, |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1151
diff
changeset
|
133 | RegularColors, |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
134 | PickColors, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
135 | BfcFrontColors, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
136 | BfcBackColors, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
137 | RandomColors, |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
138 | Normals, |
1237
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1178
diff
changeset
|
139 | InvertedNormals, |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
140 | _End |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | }; |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
143 | MAKE_ITERABLE_ENUM(VboSubclass) |
1033 | 144 | |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
145 | enum |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
146 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1119
diff
changeset
|
147 | NumVbos = EnumLimits<VboClass>::Count * EnumLimits<VboSubclass>::Count |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
148 | }; |