src/glcamera.cpp

Mon, 04 Jun 2018 23:22:52 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 04 Jun 2018 23:22:52 +0300
changeset 1392
0541d9b21968
parent 1326
69a90bd2dba2
child 1404
16eb4257e662
permissions
-rw-r--r--

fix compiler warnings

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
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1324
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
1129
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 #include "glcamera.h"
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: 1151
diff changeset
20 #include "glrenderer.h"
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 #include "grid.h"
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 * Constructs a fixed camera from parameters.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 */
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
26 GLCamera::GLCamera(QString name, FixedCameraParameters&& bag) :
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
27 m_name {name},
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
28 m_rotationMatrix {bag.rotationMatrix},
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
29 m_localX {bag.localX},
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
30 m_localY {bag.localY},
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
31 m_negatedX {bag.negatedX},
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
32 m_negatedY {bag.negatedY},
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
33 m_negatedDepth {bag.negatedZ} {}
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 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 * Constructs a free camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 */
1140
c5791a3aa1ba Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents: 1134
diff changeset
38 GLCamera::GLCamera(QString name, decltype(FreeCamera)) :
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
39 m_name {name},
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 m_isFree {true} {}
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 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 * Returns whether or not the given axis is negated on this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 bool GLCamera::isAxisNegated(Axis axis) const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 switch (axis)
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 case X:
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 return m_negatedX;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 case Y:
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 return m_negatedY;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 case Z:
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 return m_negatedDepth;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 default:
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 return false;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 * Returns the 3D axis that is on the X axis in this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 Axis GLCamera::axisX() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 return m_localX;
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
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 * Returns the 3D axis that is on the Y axis in this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 Axis GLCamera::axisY() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 return m_localY;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 * Returns the 3D axis that is on the Z axis in this camera (inwards).
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
81 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 Axis GLCamera::axisZ() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 return static_cast<Axis>(3 - m_localX - m_localY);
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
86
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 * This converts a 2D point on the screen to a 3D point in the model. If 'snap' is true, the 3D point will snap to the current grid.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 Vertex GLCamera::convert2dTo3d(const QPoint& position2d, Grid* grid) const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
92 if (m_isFree)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94 return {0, 0, 0};
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 else
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 Vertex position3d;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 int signX = m_negatedX ? -1 : 1;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 int signY = m_negatedY ? -1 : 1;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 // Calculate cx and cy - these are the LDraw unit coords the cursor is at.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 double cx = -m_virtualSize.width() + (2 * position2d.x() * m_virtualSize.width() / m_size.width()) - m_panningX;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 double cy = m_virtualSize.height() - (2 * position2d.y() * m_virtualSize.height() / m_size.height()) - m_panningY;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 // If a grid was passed, snap coordinates to it.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 if (grid)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108 {
1180
2005e4147ad6 Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents: 1179
diff changeset
109 QPointF snapped = grid->snap({cx, cy});
2005e4147ad6 Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents: 1179
diff changeset
110 cx = snapped.x();
2005e4147ad6 Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents: 1179
diff changeset
111 cy = snapped.y();
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113
1324
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
114 cx = roundToDecimals(cx, 4);
563a9b65777b roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
115 cy = roundToDecimals(cy, 4);
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
117 // Create the vertex from the coordinates
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 position3d.setCoordinate(axisX(), cx * signX);
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 position3d.setCoordinate(axisY(), cy * signY);
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 position3d.setCoordinate(axisZ(), m_depth);
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 return position3d;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
122 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
125 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
126 * Inverse operation for the above - convert a 3D position to a 2D screen position.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
127 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 QPoint GLCamera::convert3dTo2d(const Vertex& position3d) const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130 if (m_isFree)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
131 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 return {0, 0};
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
134 else
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
135 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
136 int signX = m_negatedX ? -1 : 1;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137 int signY = m_negatedY ? -1 : 1;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
138 int rx = (position3d[axisX()] * signX + m_virtualSize.width() + m_panningX) * m_size.width() / 2 / m_virtualSize.width();
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
139 int ry = (position3d[axisY()] * signY - m_virtualSize.height() + m_panningY) * m_size.height() / 2 / m_virtualSize.height();
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 return {rx, -ry};
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
141 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
144 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 * Resizes the camera when the renderer is resized.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
146 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 void GLCamera::rendererResized(int width, int height)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
149 m_size = {width, height};
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 m_virtualSize = {m_zoom, height * m_zoom / width};
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
151 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
152
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
153 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
154 * Returns the "virtual size" of the camera. Used to zoom in while keeping proportions.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
155 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
156 const QSizeF& GLCamera::virtualSize() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
158 return m_virtualSize;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
159 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162 * Returns the "z depth" of the camera. Since the camera provides 2D editing, this value fills in the value for the
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
163 * third dimension for 3D vertices.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
164 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
165 double GLCamera::depth() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
166 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
167 return m_depth;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
168 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
169
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
170 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
171 * Returns the X-panning of this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
172 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
173 double GLCamera::panningX() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
174 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
175 return m_panningX;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
176 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
177
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
178 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
179 * Returns the Y-panning of this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
180 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
181 double GLCamera::panningY() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
183 return m_panningY;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
185
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187 * Returns the zoom level of this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
188 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
189 double GLCamera::zoom() const
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
190 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
191 return m_zoom;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
192 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
193
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
194 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195 * Explicitly sets the panning of this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
196 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
197 void GLCamera::setPanning(double x, double y)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
198 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
199 m_panningX = x;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
200 m_panningY = y;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
201 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
202
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
203 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
204 * Makes the camera pan by the provided mouse move input.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
205 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
206 void GLCamera::pan(int xMove, int yMove)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
207 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
208 m_panningX += 0.03f * xMove * zoom() / 7.5f;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
209 m_panningY -= 0.03f * yMove * zoom() / 7.5f;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
210 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
211
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
212 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
213 * Zooms the camera in one notch (e.g. by mousewheel).
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
214 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
215 void GLCamera::zoomNotch (bool inward)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
216 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
217 m_zoom *= inward ? 0.833f : 1.2f;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
218 m_zoom = qBound(0.01, zoom(), 10000.0);
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
219 rendererResized(m_size.width(), m_size.height());
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
220 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
221
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
222 /*
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
223 * Explicitly sets the zoom of this camera.
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
224 */
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
225 void GLCamera::setZoom(double zoom)
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
226 {
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
227 m_zoom = zoom;
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
228 rendererResized(m_size.width(), m_size.height());
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
229 }
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
230
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
231 /*
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
232 * Returns the name of the camera
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
233 */
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
234 const QString& GLCamera::name() const
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
235 {
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
236 return m_name;
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
237 }
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
238
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
239 const GLRotationMatrix& GLCamera::transformationMatrix() const
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
240 {
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
241 return m_rotationMatrix;
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
242 }
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
243
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
244 /*
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
245 * Returns the camera's transformation matrix, scaled by the given scale value.
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
246 */
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
247 GLRotationMatrix GLCamera::transformationMatrix(double scale) const
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
248 {
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
249 GLRotationMatrix matrix = m_rotationMatrix;
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
250
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
251 for (int i = 0; i < 4; ++i)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
252 for (int j = 0; j < 4; ++j)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
253 matrix(i, j) *= scale;
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
254
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1140
diff changeset
255 return matrix;
1134
daa9808d626e Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
256 }
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: 1151
diff changeset
257
1178
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
258 static const GLRotationMatrix ldrawToIdealAdapterMatrix = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1};
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: 1151
diff changeset
259
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: 1151
diff changeset
260 /*
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: 1151
diff changeset
261 * Converts from rea co-ordinates to ideal co-ordinates.
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: 1151
diff changeset
262 * In ideal co-ordinates, X and Y axes correspond to the 2D X and Y as seen in the camera, and +Z is "outwards" from the screen.
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: 1151
diff changeset
263 */
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: 1151
diff changeset
264 Vertex GLCamera::idealize(const Vertex& realCoordinates) 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: 1151
diff changeset
265 {
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: 1151
diff changeset
266 return realCoordinates.transformed(m_rotationMatrix).transformed(ldrawToIdealAdapterMatrix);
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: 1151
diff changeset
267 }
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: 1151
diff changeset
268
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: 1151
diff changeset
269 /*
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: 1151
diff changeset
270 * Converts from ideal co-ordinates to real co-ordinates.
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: 1151
diff changeset
271 */
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: 1151
diff changeset
272 Vertex GLCamera::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: 1151
diff changeset
273 {
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: 1151
diff changeset
274 // The adapter matrix would be inverted here, but it is its own inverse so let's not bother.
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: 1151
diff changeset
275 return idealCoordinates.transformed(ldrawToIdealAdapterMatrix).transformed(m_rotationMatrix.inverted());
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: 1151
diff changeset
276 }
1237
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
277
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
278 GLRotationMatrix GLCamera::realMatrix() const
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
279 {
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
280 /* glOrtho(-virtualSize.width(), virtualSize.width(),
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
281 -virtualSize.height(), virtualSize.height(),
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
282 -1000.0f, 1000.0f); */
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
283 GLRotationMatrix ortho {
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
284 1 / float(m_virtualSize.width()), 0, 0, 0,
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
285 0, 1 / float(m_virtualSize.height()), 0, 0,
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
286 0, 0, -0.0001, 0,
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
287 0, 0, 0, 1
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
288 };
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
289
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
290 GLRotationMatrix panningMatrix {
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
291 1, 0, 0, float(m_panningX),
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
292 0, 1, 0, float(m_panningY),
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
293 0, 0, 1, 0,
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
294 0, 0, 0, 1
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
295 };
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
296
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
297 return ortho * panningMatrix * m_rotationMatrix;
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1180
diff changeset
298 }

mercurial