- Xsp (proj to screen transform)
- Xpi (image to projection transform)
- Xiw (world to image transform)
I'm rendering to a 256x256 frame buffer, so my Xsp matrix looks like this:
128 0 0 128
0 -128 0 128
0 0 1 0
0 0 0 1
My Xpi matrix has m[3][2] set to tan(fov / 2) where my fov = 35. (In the matrix .32 was just rounded for easier viewing)
1 0 0 0
0 1 0 0
0 0 1 0
0 0 .32 0
Lastly my Xiw matrix is just the inverse of my camera transform. The camera is at 0,0,-15, looking at 0,0,0 with an up-vector of 0,1,0
1 0 0 0
0 1 0 0
0 0 1 15
0 0 0 1
Using just these three matrices I can multiply them against a coordinate and get it transformed into screen space just fine. The catch is when I want them to be perspective correct. I've tried figuring out what 'w' is, but I cannot find a solid definition of how to calculate it. Some places are saying that the final Z value is used to divide X and Y by, but it doesn't look right. Some places are saying the W coord that is calculated by multiplying the matrix with the coordinate (assuming 1.0 for the 4th coord) is the W to divide by. I can't seem to get either method to work.
My question is what is W and how is it calculated?
Thank you so much in advance!
-Adam