I'm trying to do a simple perspective projection in the process of rasterizing a 3D point. Here are all the matrices and other info. All Matrices are row major. The coordinate system is Right Handed.
The Camera is at [0,0,-1] and the point is at [0,0,0] (w=1 for matrix operations)
Model View Matrix(Inverse of Cam Matrix i.e, tx = 0;ty = 0; tz = 1):
[1 0 0 tx]
[0 1 0 ty]
[0 0 1 tz]
[0 0 0 1 ]
Perspective Matrix:
[f/aspect,0,0,0]
0,f,0,0
0,0,-(near+far)/(near-far),2*far*near/(near-far)
0,0,1,0]
aspect is equal to 1 since the viewport is square. Far = 100 and Near = 0.1 f = 1/tan(fovDegress*M_PI/360);
The resultant Matrix is:
1.94445, 0, 0, 0
0, 1.944445, 0, 0
0, 0, 1.020202, -2.020202
0, 0, 1, 0
Now I apply the Model View Matrix and then the Projection Matrix to the point vector and then I get a new point Pv = {x,y,z,w} Then I get the normalized co-ordinates x' = x/w ; y' = y/w; and z' = z/w; x' and y' always lie in between [-1,1] as long as the point is in the frustum. But the same isn't the case for z'. As the point approaches near the camera, the z' values increases exponentially. When the point is at [0,0,0] z' value equals -1.
Now, I need to clip some lines, so I need z' value to be in between [1,-1]. I am wondering what's wrong with my procedure. Thank you.