Sun, 11 Mar 2018 16:13:22 +0200
fixed: LDDocument created one removal connection to the model for each object added, so removing an object from a model of 9 objects added 9 deletion entries to history
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | * |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | * |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #pragma once |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "main.h" |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
21 | #include "glShared.h" |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
23 | struct FixedCameraParameters |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
24 | { |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
25 | GLRotationMatrix rotationMatrix; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
26 | Axis localX; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
27 | Axis localY; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
28 | bool negatedX; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
29 | bool negatedY; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
30 | bool negatedZ; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
31 | }; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
32 | |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | * Models a 2D x/y co-ordinate system that maps to a fixed camera position. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | * Owns camera orientation information and provides 2Dāā3D translation. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | */ |
1234 | 37 | class GLCamera |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | public: |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | // This is used to construct the free camera |
1140
c5791a3aa1ba
Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents:
1134
diff
changeset
|
41 | enum { FreeCamera }; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
43 | GLCamera(QString name, FixedCameraParameters&& bag); |
1140
c5791a3aa1ba
Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents:
1134
diff
changeset
|
44 | GLCamera(QString name, decltype(FreeCamera)); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | Axis axisX() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | Axis axisY() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | Axis axisZ() const; |
1159
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1151
diff
changeset
|
49 | Vertex convert2dTo3d(const QPoint& pos2d, class Grid* grid = nullptr) const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
50 | QPoint convert3dTo2d(const Vertex& pos3d) const; |
1177
8661b9237ed5
Added support for ideal co-ordinates, which should make writing editing tools a lot easier. For some reason they don't yet work with the back and right cameras.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
51 | Vertex realize(const Vertex& idealCoordinates) const; |
8661b9237ed5
Added support for ideal co-ordinates, which should make writing editing tools a lot easier. For some reason they don't yet work with the back and right cameras.
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
52 | Vertex idealize(const Vertex& realCoordinates) const; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | double depth() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | bool isAxisNegated(Axis axis) const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
55 | const QString& name() const; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
56 | void pan(int xMove, int yMove); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | double panningX() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | double panningY() const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
59 | Q_SLOT void rendererResized(int width, int height); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | void setPanning(double x, double y); |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
61 | void setZoom(double zoom); |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
62 | const GLRotationMatrix& transformationMatrix() const; |
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
63 | GLRotationMatrix transformationMatrix(double scale) const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
64 | const QSizeF& virtualSize() const; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
65 | double zoom() const; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | void zoomNotch(bool inward); |
1237
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1234
diff
changeset
|
67 | GLRotationMatrix realMatrix() const; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | private: |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
70 | QString m_name; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
71 | double m_panningX = 0; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | double m_panningY = 0; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | double m_depth = 0; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | double m_zoom = 30; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | QSize m_size; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | QSizeF m_virtualSize; |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
77 | GLRotationMatrix m_rotationMatrix; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | Axis m_localX = X; // Which axis to use for Y |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | Axis m_localY = Y; // Which axis to use for Y |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | bool m_isFree = false; // Is this the free camera? |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | bool m_negatedX = false; // Is +x to the left? |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | bool m_negatedY = false; // Is +y downwards? |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | bool m_negatedDepth = false; // is greater depth value closer to camera? |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | }; |