Wed, 07 Mar 2018 19:30:29 +0200
fixed object deleting not triggering the proper renderer updates
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 | #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 | #include "miscallenous.h" |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | * Constructs a fixed camera from parameters. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | */ |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
27 | GLCamera::GLCamera(QString name, FixedCameraParameters&& bag) : |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
28 | m_name {name}, |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
29 | m_rotationMatrix {bag.rotationMatrix}, |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
30 | m_localX {bag.localX}, |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
31 | m_localY {bag.localY}, |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
32 | m_negatedX {bag.negatedX}, |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
33 | m_negatedY {bag.negatedY}, |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
34 | m_negatedDepth {bag.negatedZ} {} |
1129
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | * Constructs a free camera. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | */ |
1140
c5791a3aa1ba
Removed the GLCamera::FreeToken name
Teemu Piippo <teemu@hecknology.net>
parents:
1134
diff
changeset
|
39 | GLCamera::GLCamera(QString name, decltype(FreeCamera)) : |
1130
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
40 | m_name {name}, |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | m_isFree {true} {} |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | * 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
|
45 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | bool GLCamera::isAxisNegated(Axis axis) const |
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 | switch (axis) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | case X: |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | return m_negatedX; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | case Y: |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | return m_negatedY; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | case Z: |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | return m_negatedDepth; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | default: |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | return false; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | * 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
|
66 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | Axis GLCamera::axisX() const |
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 | return m_localX; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
73 | * 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
|
74 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | Axis GLCamera::axisY() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | return m_localY; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | * 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
|
82 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | Axis GLCamera::axisZ() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | 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
|
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | * 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
|
90 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | 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
|
92 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | if (m_isFree) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | return {0, 0, 0}; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | } |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
97 | else |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | Vertex position3d; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
100 | int signX = m_negatedX ? -1 : 1; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | int signY = m_negatedY ? -1 : 1; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
102 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
103 | // 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
|
104 | 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
|
105 | 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
|
106 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | // 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
|
108 | if (grid) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | { |
1180
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
110 | QPointF snapped = grid->snap({cx, cy}); |
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
111 | cx = snapped.x(); |
2005e4147ad6
Grid::snap now snaps points.
Teemu Piippo <teemu@hecknology.net>
parents:
1179
diff
changeset
|
112 | cy = snapped.y(); |
1129
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
113 | } |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
114 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
115 | roundToDecimals(cx, 4); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
116 | roundToDecimals(cy, 4); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
117 | |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
118 | // Create the vertex from the coordinates |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
119 | position3d.setCoordinate(axisX(), cx * signX); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
120 | position3d.setCoordinate(axisY(), cy * signY); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
121 | position3d.setCoordinate(axisZ(), m_depth); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
122 | return position3d; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
127 | * 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
|
128 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
129 | QPoint GLCamera::convert3dTo2d(const Vertex& position3d) const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
130 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
131 | if (m_isFree) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
132 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
133 | return {0, 0}; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
134 | } |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
135 | else |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
136 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
137 | int signX = m_negatedX ? -1 : 1; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
138 | int signY = m_negatedY ? -1 : 1; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
139 | 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
|
140 | 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
|
141 | return {rx, -ry}; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
146 | * 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
|
147 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
148 | void GLCamera::rendererResized(int width, int height) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
149 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
150 | m_size = {width, height}; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
151 | 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
|
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
155 | * 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
|
156 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
157 | const QSizeF& GLCamera::virtualSize() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
158 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
159 | return m_virtualSize; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
163 | * 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
|
164 | * third dimension for 3D vertices. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
165 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
166 | double GLCamera::depth() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
167 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
168 | return m_depth; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
172 | * Returns the X-panning of this camera. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
173 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
174 | double GLCamera::panningX() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
175 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
176 | return m_panningX; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
180 | * Returns the Y-panning of this camera. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
181 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
182 | double GLCamera::panningY() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
183 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
184 | return m_panningY; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
188 | * Returns the zoom level of this camera. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
189 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
190 | double GLCamera::zoom() const |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
191 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
192 | return m_zoom; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
196 | * Explicitly sets the panning of this camera. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
197 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
198 | void GLCamera::setPanning(double x, double y) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
199 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
200 | m_panningX = x; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
201 | m_panningY = y; |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
205 | * 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
|
206 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
207 | void GLCamera::pan(int xMove, int yMove) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
208 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
209 | 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
|
210 | 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
|
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
214 | * 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
|
215 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
216 | void GLCamera::zoomNotch (bool inward) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
217 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
218 | m_zoom *= inward ? 0.833f : 1.2f; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
219 | 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
|
220 | rendererResized(m_size.width(), m_size.height()); |
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 | /* |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
224 | * Explicitly sets the zoom of this camera. |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
225 | */ |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
226 | void GLCamera::setZoom(double zoom) |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
227 | { |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
228 | m_zoom = zoom; |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
229 | rendererResized(m_size.width(), m_size.height()); |
2b20261dc511
Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
230 | } |
1130
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 | /* |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
233 | * Returns the name of the camera |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
234 | */ |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
235 | const QString& GLCamera::name() const |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
236 | { |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
237 | return m_name; |
17f92eb2a30c
Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents:
1129
diff
changeset
|
238 | } |
1134
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
239 | |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
240 | const GLRotationMatrix& GLCamera::transformationMatrix() const |
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
241 | { |
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
242 | return m_rotationMatrix; |
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
243 | } |
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
244 | |
1134
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
245 | /* |
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
246 | * 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
|
247 | */ |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
248 | GLRotationMatrix GLCamera::transformationMatrix(double scale) const |
1134
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
249 | { |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
250 | GLRotationMatrix matrix = m_rotationMatrix; |
1134
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
251 | |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
252 | 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
|
253 | 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
|
254 | matrix(i, j) *= scale; |
1134
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
255 | |
1151
0eddb5bcf25b
Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents:
1140
diff
changeset
|
256 | return matrix; |
1134
daa9808d626e
Moved more stuff to GLCamera
Teemu Piippo <teemu@hecknology.net>
parents:
1130
diff
changeset
|
257 | } |
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
|
258 | |
1178
3a88e7a60b63
At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents:
1177
diff
changeset
|
259 | 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
|
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 | /* |
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 | * 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
|
263 | * 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
|
264 | */ |
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 | 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
|
266 | { |
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 | 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
|
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 | /* |
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 | * 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
|
272 | */ |
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 | 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
|
274 | { |
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 | // 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
|
276 | 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
|
277 | } |
1237
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
278 | |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
279 | GLRotationMatrix GLCamera::realMatrix() const |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
280 | { |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
281 | /* glOrtho(-virtualSize.width(), virtualSize.width(), |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
282 | -virtualSize.height(), virtualSize.height(), |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
283 | -1000.0f, 1000.0f); */ |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
284 | GLRotationMatrix ortho { |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
285 | 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
|
286 | 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
|
287 | 0, 0, -0.0001, 0, |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
288 | 0, 0, 0, 1 |
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 | |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
291 | GLRotationMatrix panningMatrix { |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
292 | 1, 0, 0, float(m_panningX), |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
293 | 0, 1, 0, float(m_panningY), |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
294 | 0, 0, 1, 0, |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
295 | 0, 0, 0, 1 |
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 | |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
298 | return ortho * panningMatrix * m_rotationMatrix; |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1180
diff
changeset
|
299 | } |