15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #include "glcamera.h" |
19 #include "glcamera.h" |
|
20 #include "glrenderer.h" |
20 #include "grid.h" |
21 #include "grid.h" |
21 #include "miscallenous.h" |
22 #include "miscallenous.h" |
22 |
23 |
23 /* |
24 /* |
24 * Constructs a fixed camera from parameters. |
25 * Constructs a fixed camera from parameters. |
251 for (int j = 0; j < 4; ++j) |
252 for (int j = 0; j < 4; ++j) |
252 matrix(i, j) *= scale; |
253 matrix(i, j) *= scale; |
253 |
254 |
254 return matrix; |
255 return matrix; |
255 } |
256 } |
|
257 |
|
258 static const GLRotationMatrix ldrawToIdealAdapterMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; |
|
259 |
|
260 /* |
|
261 * Converts from rea co-ordinates to ideal co-ordinates. |
|
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. |
|
263 */ |
|
264 Vertex GLCamera::idealize(const Vertex& realCoordinates) const |
|
265 { |
|
266 return realCoordinates.transformed(m_rotationMatrix).transformed(ldrawToIdealAdapterMatrix); |
|
267 } |
|
268 |
|
269 /* |
|
270 * Converts from ideal co-ordinates to real co-ordinates. |
|
271 */ |
|
272 Vertex GLCamera::realize(const Vertex& idealCoordinates) const |
|
273 { |
|
274 // The adapter matrix would be inverted here, but it is its own inverse so let's not bother. |
|
275 return idealCoordinates.transformed(ldrawToIdealAdapterMatrix).transformed(m_rotationMatrix.inverted()); |
|
276 } |