Wed, 08 Mar 2017 22:09:48 +0200
Whoops
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 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | class GLCamera : public QObject |
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 | Q_OBJECT |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | public: |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | // This is used to construct the free camera |
1140
c5791a3aa1ba
Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents:
1134
diff
changeset
|
43 | enum { FreeCamera }; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
45 | GLCamera(QString name, FixedCameraParameters&& bag); |
1140
c5791a3aa1ba
Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents:
1134
diff
changeset
|
46 | GLCamera(QString name, decltype(FreeCamera)); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | Axis axisX() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | Axis axisY() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | Axis axisZ() const; |
1199
613a981223a6
Grid is now a namespace.
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
51 | Vertex convert2dTo3d(const QPoint& pos2d, bool snapToGrid = false) const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
52 | 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
|
53 | 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
|
54 | Vertex idealize(const Vertex& realCoordinates) const; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | double depth() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | bool isAxisNegated(Axis axis) const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
57 | const QString& name() const; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
58 | void pan(int xMove, int yMove); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | double panningX() const; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | double panningY() const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
61 | 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
|
62 | void setPanning(double x, double y); |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
63 | void setZoom(double zoom); |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
64 | const GLRotationMatrix& transformationMatrix() const; |
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
65 | GLRotationMatrix transformationMatrix(double scale) const; |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
66 | const QSizeF& virtualSize() const; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
67 | double zoom() const; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | void zoomNotch(bool inward); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
69 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
70 | private: |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
71 | QString m_name; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
72 | double m_panningX = 0; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | double m_panningY = 0; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
74 | double m_depth = 0; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | double m_zoom = 30; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | QSize m_size; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | QSizeF m_virtualSize; |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
78 | GLRotationMatrix m_rotationMatrix; |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | 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
|
80 | 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
|
81 | 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
|
82 | 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
|
83 | bool m_negatedY = false; // Is +y downwards? |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | 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
|
85 | }; |