Use an orthographic projection matrix for rendering the scene

Rather than a perspective matrix, which is rather unexpected when coming
from something like QtQuick. Generally, when doing 2D you want an
orthographic matrix so Z values do not matter.

Apparently this was originally done for 3D effects, but there are only
two of those remaining (glide and sheet) and for those, the effects
themselves can set up a perspective projection matrix.
This commit is contained in:
Arjen Hiemstra 2022-07-13 18:00:23 +02:00
parent 085e44cdf9
commit 695cc7c010

View file

@ -411,28 +411,8 @@ void Scene::postPaint()
static QMatrix4x4 createProjectionMatrix(const QRect &rect)
{
// Create a perspective projection with a 60° field-of-view,
// and an aspect ratio of 1.0.
QMatrix4x4 ret;
ret.setToIdentity();
const float fovY = std::tan(qDegreesToRadians(60.0f) / 2);
const float aspect = 1.0f;
const float zNear = 0.1f;
const float zFar = 100.0f;
const float yMax = zNear * fovY;
const float yMin = -yMax;
const float xMin = yMin * aspect;
const float xMax = yMax * aspect;
ret.frustum(xMin, xMax, yMin, yMax, zNear, zFar);
const float scaleFactor = 1.1 * fovY / yMax;
ret.translate(xMin * scaleFactor, yMax * scaleFactor, -1.1);
ret.scale((xMax - xMin) * scaleFactor / rect.width(),
-(yMax - yMin) * scaleFactor / rect.height(),
0.001);
ret.translate(-rect.x(), -rect.y());
ret.ortho(QRectF(rect.left(), rect.top(), rect.width(), rect.height()));
return ret;
}