I am trying to make a simple perspective projection in the process of rasterizing a three-dimensional point. Here are all the matrices and other information. All matrices have a number of basic values. The coordinate system has the right.
The camera is at [0,0, -1], and the point is at [0,0,0] (w = 1 for matrix operations)
Model representation matrix (inverse cam matrix ie, 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
equals 1 because the viewport is square. Far = 100 and Near = 0.1 f = 1 / tan (fovDegress * M_PI / 360);
Resulting Matrix:
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 representation 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 coordinates x '= x / w; y '= y / w; and z '= z / w; x 'and y' always lie between [-1,1] while the point is truncated. But the same is true for z '. As the point approaches the camera, z 'values โโincrease exponentially. When the point is at [0,0,0], the value of z is -1.
Now I need to copy some lines, so I need the value of z to be between [1, -1]. I wonder what happened to my procedure. Thanks.