I'm reading along in my book about the 3d pipeline and I can't quite figure out how the perspective matrix transforms 3d coordinates into a unit cube. From my gathering of what the perspective matrix does I believe it should do this
1) Multiply the x coordinate so it lays between [-1,1]
2) Multiply the y coordinate so it lays between [-1,1]
3) Multiply the z coordinate so it lays between [-1,1]
4) Set w = z
From that I would believe the perspective matrix would look like this(row major form)
(2/r-l) 0 0 0
0 (2/b-t) 0 0
0 0 (2/f-n) 1
0 0 0 0
That would multiply the x value by 1 over half the width of the screen, the y value by 1 over half the screen's height and the z value by 1 over half the depth. Also it would multiply w*z which would effectively set w = z. All the conditions would be fufilled I believe. But this is not the matrix that my book gives me and unfortunatly it doesn't give an explaniation of the math it just says "The perspective transform matrix that transforms the frutum into a unit cube is given as follows." I transposed the matrix because they had it in column major form, but here it is in row major form hopefully i transposed correctly.
(2n/r-l) 0 0 0
0 (2n/t-b) 0 0
(r+l/r-l)(t+b/t-b) (f/f-n) 1
0 0 -(fn/f-n) 0
Here is what I don't understand about this matrix.
1) They not only divide x and y by half the screen's width and height which i understand, but they also multiply by the near plane, why?
2) The y's value has t-b instead of b-t, t-b would give a negative value, is that so they flip the axis?
3) For x and y's value the formula works out like follows
x' = x*(2n/r-l) + y*0 +
z*(r+l/r-l) + w*0
So r+l/r-l simplifies to -1 and -z gets effectively added on to x's value. If z was 13 for instance, then -13 would get added on to x's unit value. x and y would never have a chance of being put into a unit cube if z was greater then 1.
4) z's value is multipled by f, I have no idea why? also z's value has w*-(fn/f-n) added on to it. Also I have no idea why
thanks for reading a lot of questions hopefully someone can answer a few.
[edited by - Whoknewb on December 16, 2003 11:21:30 AM]