I'm trying to set the far clipping plane to a higher value, but I'm a bit lost.
I'm looking at a complex object using a QMatrix4x4 camera persepective like that:
glMatrixMode(GL_MODELVIEW);
m_view = QMatrix4x4();
m_view.lookAt(QVector3D(17.f, 36.f, 36.f), // eye
QVector3D(17.f, 0.f, 19.f), // center
QVector3D( 0.f, 0.f, -1.f)); // up
glLoadMatrixf(m_view.data());
Now, looking from this perspective, my object is being clipped by the far plane.
I've tried to increase the far plane distance by using a frustum matrix operation with a huge value. All I want is to modify the back clipping plane:
m_view.frustum(1.f, 1.f, 1.f, 1.f, 1.f, 200000.f);
But this does not show any difference, modifying the farPlane
parameter does not change anything. The same applies to ortho:
m_view.ortho(1.f, 1.f, 1.f, 1.f, 1.f, 200000.f);
Or perspective:
m_view.perspective(0.f, 1.f, 1.f, 200000.f);
What's wrong with my approach? How to modify the far clipping plane?
I've extended the code snippets above as the problem was not visible. Obviously my mistake was modifying the GL_MODELVIEW
instead of the GL_PROJECTION
.
Working code should look like that:
// Projection
m_projection = QMatrix4x4();
m_projection.perspective(20.f, m_width / m_height, 0.01f, 2000.f); // note the far plane
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(m_projection.data());
// Model view
m_view = QMatrix4x4();
m_view.lookAt(QVector3D(17.f, 36.f, 36.f), // eye
QVector3D(17.f, 0.f, 19.f), // center
QVector3D( 0.f, 0.f, -1.f)); // up
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(m_view.data());
2 issues:
You are mixing modelview (lookat) and projection (frustum) operations on the same matrix. You need 2 different matrices.
You define the left and right values as both 1.f in ::frustum(). It cannot work, they need to be different. Same for the top and bottom values.
Here is an extract of the definition of QMatrix4x4::frustum():
if (left == right || bottom == top || nearPlane == farPlane)
return *this;
So your call to frustum does not do anything.
Once you have good values for top/left/top/bottom, try playing with the near plane distance too, as it might be it that clips your object and not the far plane.