src/glcamera.h

Tue, 14 Feb 2017 13:02:05 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 14 Feb 2017 13:02:05 +0200
changeset 1140
c5791a3aa1ba
parent 1134
daa9808d626e
child 1151
0eddb5bcf25b
permissions
-rw-r--r--

Removed the GLCamera::FreeToken name

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"
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
22 struct FixedCameraParameters
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
23 {
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
24 int glRotateX;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
25 int glRotateY;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
26 int glRotateZ;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
27 Axis localX;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
28 Axis localY;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
29 bool negatedX;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
30 bool negatedY;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
31 bool negatedZ;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
32 };
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
33
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 * 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
36 * 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
37 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 class GLCamera : public QObject
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 Q_OBJECT
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 public:
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 // This is used to construct the free camera
1140
c5791a3aa1ba Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents: 1134
diff changeset
44 enum { FreeCamera };
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
46 GLCamera(QString name, FixedCameraParameters&& bag);
1140
c5791a3aa1ba Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents: 1134
diff changeset
47 GLCamera(QString name, decltype(FreeCamera));
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 Axis axisX() const;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 Axis axisY() const;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 Axis axisZ() const;
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
52 Vertex convert2dTo3d(const QPoint& pos2d, Grid* grid = nullptr) const;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
53 QPoint convert3dTo2d(const Vertex& pos3d) const;
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 double depth() const;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 int glRotate(Axis axis) 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);
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
64 Matrix transformationMatrix(double scale) const;
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
65 const QSizeF& virtualSize() const;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
66 double zoom() const;
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 void zoomNotch(bool inward);
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;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 int m_glrotate[3] = {0, 0, 0}; // GL model transformation to use
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 };

mercurial