Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL custom rendering pipeline: Perspective matrix
    primarykey
    data
    text
    <p>I am attempting to work in LWJGL to display a simple quad using my own matrices. I've been looking around for awhile and have found a few perspective matrix implementations, these two in particular:</p> <pre><code>[cot(fov/2)/a 0 0 0] [0 cot(fov/2) 0 0] [0 0 -f/(f-n) -1] [0 0 -f*n/(f-n) 0] </code></pre> <p>and:</p> <pre><code>[cot(fov/2)/a 0 0 0] [0 cot(fov/2) 0 0] [0 0 -(f+n)/(f-n) -1] [0 0 -(2*f*n)/(f-n) 0] </code></pre> <p>Both of these provide the same effect, as expected (got them from <a href="http://www.scratchapixel.com/lessons/3d-advanced-lessons/perspective-and-orthographic-projection-matrix/perspective-projection-matrix/" rel="nofollow">here</a> and <a href="http://www.lwjgl.org/wiki/index.php?title=The_Quad_with_Projection,_View_and_Model_matrices#Projection_matrix" rel="nofollow">here</a>, respectively). The issue is in my understanding of how multiplying this by the modelview matrix, then a vertex, then dividing each x, y, and z value by its w value gives a screen coordinate. More specifically, if I multiply either of these by the modelview matrix then by a vertex (10, 10, 0, 1), it gives a w=0. That in itself is a big smack in the face. I conclude either the matrices are wrong, or I am missing something completely. In my actual test program, the vertices don't even end up on screen even though the camera position at (0,0,0) and no rotation would make it so. I even have tried many different z values, positive and negative, to see if it was just a clipping plane. Am I missing something here?</p> <p>EDIT: After a lot of checking over, I've narrowed down the problem I am facing. The biggest issue is that the z-axis does not appear to be remapped to the range I specify (n to f). Any object just zooms in or out a little bit when I translate it along the z-axis then pops out of existence as it moves past the range [-1, 1]. I think this is also making me more confused. I set my far plane to 100 and my near to 0.1, and it behaves like anything but.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload