src/glcamera.cpp

changeset 1134
daa9808d626e
parent 1130
17f92eb2a30c
child 1140
c5791a3aa1ba
equal deleted inserted replaced
1133:47f6db5ea24d 1134:daa9808d626e
240 */ 240 */
241 const QString& GLCamera::name() const 241 const QString& GLCamera::name() const
242 { 242 {
243 return m_name; 243 return m_name;
244 } 244 }
245
246 /*
247 * Returns the camera's transformation matrix, scaled by the given scale value.
248 */
249 Matrix GLCamera::transformationMatrix(double scale) const
250 {
251 // Matrix templates. 2 is substituted with the scale value, 1 is inverted to -1 if needed.
252 static const Matrix templates[3] =
253 {
254 { 2, 0, 0, 0, 1, 0, 0, 0, 2 },
255 { 2, 0, 0, 0, 0, 2, 0, 1, 0 },
256 { 0, 1, 0, 2, 0, 0, 0, 0, 2 },
257 };
258
259 Matrix transform;
260
261 if (m_localX == X and m_localY == Z)
262 transform = templates[0];
263 else if (m_localX == X and m_localY == Y)
264 transform = templates[1];
265 if (m_localX == Y and m_localY == Z)
266 transform = templates[2];
267
268 for (double& value : transform)
269 {
270 if (value == 2)
271 value = scale;
272 else if (value == 1 and (glRotate(X) + glRotate(Y) + glRotate(Z)) < 0)
273 value = -1;
274 }
275
276 return transform;
277 }

mercurial