I'm going right to the point. I already did some reasearch and I still didn't figure out this.
I have a program that draws a cube each face with a color. Then I rotate this cube in the Y-axis and also in the X-axis (-45 and +45 respectively).
The problem is that it's not rendering as I was expecting, the cube is getting clipped at some point.
projection = glm::ortho(-1.0f, +1.0f, -1.0f, +1.0f, +1.0f, -1.0f); camera = glm::lookAt( glm::vec3(+0.0f,+0.0f,+1.0f), glm::vec3(0.0f,0.0f,0.0f), glm::vec3(0.0f,1.0f,0.0f) ); model = glm::mat4(1.0f); model = glm::rotate(model, -45.0f, glm::vec3(0.0f, 1.0f, 0.0f)); model = glm::rotate(model, +45.0f, glm::vec3(1.0f, 0.0f, 0.0f)); mvp = projection * camera * model;
All the vertices I am defining are made with ±0.25. So I thought at least that with my these values of zNear and zFar they would still fit in the volume, but when I change the line
projection = glm::ortho(-1.0f, +1.0f, -1.0f, +1.0f, +1.0f, -1.0f);
projection = glm::ortho(-1.0f, +1.0f, -1.0f, +1.0f, +2.0f, -1.0f);
it works just fine
But it doesn't work with
projection = glm::ortho(-1.0f, +1.0f, -1.0f, +1.0f, +1.0f, -2.0f);
Can someone explain me why? I mean, I know that if I put more values the projection cube will have bigger volume so it will render just fine. I knowthe the bottom right vertex is outside the cube with zNear and zFar to +1.0 and -1.0 (the vertex value is something like 1.76 after the application of the matrix) but if I extend the zFar cube to -2.0f it should fit just right, shouldn't?
I tried to read something on the Red Book and also Peter Shirley book Fundamentals of Computer Graphics. And even made the matrix by myself, but with the same results.
Anyway, thanks in advance!