Ok, it seems I am still missing some fundamental part of full understanding of the projection matrix.
For starters, I have watched Chili's 3D fundamentals video on the subject, and have also read many good book's take on it.
It is the preperspective divide parts that are giving me trouble, so this question is gonna be the same for both perspective and orthographic projections.
Ok, I'm basically gonna step through the math here for just the x coordinate. Please tell me where I get things wrong.
Let's arbitrarily decide that in viewspace , the left edge is 30, and the right edge is 60. I purposely using fairly random numbers here, because it may help expose where I'm wrong on matters.
Let's say the FOV is 100°.
In the matrix Chili, and all my books show, x is multiplied by:
2n/rightleft.
Using 1/tan(FOV/2), I get an n of .84
2*.84 is 1.68
1.68/(6030) is .056.
Thus, the value in [0][0] of the matrix will be .056
Let's say my coordinate to be transformed is at x=45 in viewspace.
It should map to 0 in NDC space.
.056*45 is 2.52. Clearly I'm missing something.
What's weird to me, is that in my books, they usually start out with a nonreduced version of the equation that works for me, so I always feel they omit explaining properly how they get from the non simplified equation, to the one in the matrix.
Help with projection matrix (again :) )
Re: Help with projection matrix (again :) )
Ok, update: if I make sure my viewspace origin is at 0, it works. So, in my example, it would go from 15 to 15. Math works out now.
What got me confused, is that my books seem to have a translation to a zero centred viewport as part of the initial, unreduced equation. In actual code, I would have used a 0 centred viewport anyway. The offset one in my first post was just to force the math to deal with what I thought was a strange, but valid input. Guess only the "strange" part was true.
What got me confused, is that my books seem to have a translation to a zero centred viewport as part of the initial, unreduced equation. In actual code, I would have used a 0 centred viewport anyway. The offset one in my first post was just to force the math to deal with what I thought was a strange, but valid input. Guess only the "strange" part was true.

 Posts: 4373
 Joined: February 28th, 2013, 3:23 am
 Location: Oklahoma, United States
Re: Help with projection matrix (again :) )
Normally, you'd "move" the camera around following some target ( maybe the player ) while everything else is in World coordinates. So, if your player is at { 100, 0, 200 } and your camera is at { 100, 0, 100 } then one of the transformations in the View transform matrix is the negated translation. This subtracts the camera's position from the players position yielding { 0, 0, 100 }. The projection matrix would then scale the X, Y and Z to fit the FOV and aspect ratio of the screen as well as the depth of the view frustum.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves.  gameprogrammingpatterns.com
Re: Help with projection matrix (again :) )
Here is a dumb question. As I understand, the near plane z is defined completely by the FOV. In my example, with a FOV of 100°, I got a distance of 1/tan(50) = .84
I am getting it correct to use that .84 as my 'n' variable, yes? Thus, objects at z=0 in viewspace would get translated .84 by the projection, and would be invisible (after clipping of course)?
All of this assumes I'm using a system with the NDC near plane at 0.
Finally, I assume the far plane z value in viewspace is completely up to me, and will be chosen on a performance/distance object visibility tradeoff?
I am getting it correct to use that .84 as my 'n' variable, yes? Thus, objects at z=0 in viewspace would get translated .84 by the projection, and would be invisible (after clipping of course)?
All of this assumes I'm using a system with the NDC near plane at 0.
Finally, I assume the far plane z value in viewspace is completely up to me, and will be chosen on a performance/distance object visibility tradeoff?