Commit 203f9424 authored by Frédéric Larue's avatar Frédéric Larue

GLViewer::reframedProjection function now use near and far planes extracted...

GLViewer::reframedProjection function now use near and far planes extracted from the projection matrix itself instead of zNear() and zFar().
parent 46eb78f3
......@@ -2019,20 +2019,24 @@ QMatrix4x4 GLViewer::reframedProjection( float viewportX, float viewportY, float
{
QMatrix4x4 projMat = projectionMatrix();
double frustumL, frustumR, frustumB, frustumT;
double frustumL, frustumR, frustumB, frustumT, frustumN, frustumF;
if( isProjectionOrthographic() )
{
frustumL = -(projMat(0,3) + 1.0f) / projMat(0,0);
frustumR = -(projMat(0,3) - 1.0f) / projMat(0,0);
frustumB = -(projMat(1,3) + 1.0f) / projMat(1,1);
frustumT = -(projMat(1,3) - 1.0f) / projMat(1,1);
frustumN = (projMat(2,3) + 1.0) / projMat(2,2);
frustumF = (projMat(2,3) - 1.0) / projMat(2,2);
frustumL = -(1.0 + projMat(0,3)) / projMat(0,0);
frustumR = (1.0 - projMat(0,3)) / projMat(0,0);
frustumB = -(1.0 + projMat(1,3)) / projMat(1,1);
frustumT = (1.0 - projMat(1,3)) / projMat(1,1);
}
else
{
frustumL = zNear() * (projMat(0,2)-1.0f) / projMat(0,0);
frustumR = zNear() * (projMat(0,2)+1.0f) / projMat(0,0);
frustumB = zNear() * (projMat(1,2)-1.0f) / projMat(1,1);
frustumT = zNear() * (projMat(1,2)+1.0f) / projMat(1,1);
frustumN = projMat(2,3) / (projMat(2,2) - 1.0);
frustumF = projMat(2,3) / (projMat(2,2) + 1.0);
frustumL = frustumN * (projMat(0,2) - 1.0) / projMat(0,0);
frustumR = frustumN * (projMat(0,2) + 1.0) / projMat(0,0);
frustumB = frustumN * (projMat(1,2) - 1.0) / projMat(1,1);
frustumT = frustumN * (projMat(1,2) + 1.0) / projMat(1,1);
}
double newFrustumL = frustumL + (frustumR-frustumL) * (viewportX+0.5f)/width();
......@@ -2047,18 +2051,18 @@ QMatrix4x4 GLViewer::reframedProjection( float viewportX, float viewportY, float
projMat(0,3) = -(newFrustumR + newFrustumL) / (newFrustumR - newFrustumL);
projMat(1,1) = 2.0f / (newFrustumT - newFrustumB);
projMat(1,3) = -(newFrustumT + newFrustumB) / (newFrustumT - newFrustumB);
projMat(2,2) = -2.0f / (zFar() - zNear());
projMat(2,3) = -(zFar() + zNear()) / (zFar() - zNear());
projMat(2,2) = -2.0f / (frustumF - frustumN);
projMat(2,3) = -(frustumF + frustumN) / (frustumF - frustumN);
projMat(3,3) = 1.0f;
}
else
{
projMat(0,0) = 2.0f * zNear() / (newFrustumR - newFrustumL);
projMat(0,0) = 2.0f * frustumN / (newFrustumR - newFrustumL);
projMat(0,2) = (newFrustumR + newFrustumL) / (newFrustumR - newFrustumL);
projMat(1,1) = 2.0f * zNear() / (newFrustumT - newFrustumB);
projMat(1,1) = 2.0f * frustumN / (newFrustumT - newFrustumB);
projMat(1,2) = (newFrustumT + newFrustumB) / (newFrustumT - newFrustumB);
projMat(2,2) = (zNear() + zFar()) / (zNear() - zFar());
projMat(2,3) = 2.0f * zNear() * zFar() / (zNear() - zFar());
projMat(2,2) = (frustumN + frustumF) / (frustumN - frustumF);
projMat(2,3) = 2.0f * frustumN * frustumF / (frustumN - frustumF);
projMat(3,2) = -1.0f;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment