One question on normalization

Suppose, window has dimension (W X H X D) where H = max (W, H, D)
Center (Cx, Cy and Cz)
Now for parallel projection, which of the following would be the transformation matrix for normalization?

|2/W 0 0 -2Cx/W|
|0 2/H 0 -2Cy/H|
|0 0 2/D -2Cz/D|
|0 0 0 1 |


|2/H 0 0 -2Cx/H|
|0 2/H 0 -2Cy/H|
|0 0 2/H -2Cz/H|
|0 0 0 1 |

As I understand the bottom one will produce the undeformed result of objects inside the window. But I found in all cases normalization is performed using the top matrix.

Could anyone clarify me? Thanks in advance.

The transformation from eye space to window space has two components: the projection matrix and the viewport transformation.

A projection matrix created with glOrtho() maps the given cuboid in eye coordinates to the signed unit cube (-1 to +1) in normalised device coordinates. The viewport transformation then maps the signed unit cube in normalised device coordinates to the bounds of the viewport in window coordinates (technically, the viewport transformation only maps the X and Y coordinates, the depth transformation given by glDepthRange() maps the Z coordinate).

In order to construct a projection which preserves aspect ratio, it’s necessary for the cuboid passed to glOrtho() to have the same aspect ratio as the viewport. This results in something similar to the top-most of the two matrices you give.

A glOrtho() call of the form

glOrtho(Cx-W/2, Cx+W/2, Cy-H/2, Cy+H/2, Cz-D/2,  Cz+D/2);

will generate the matrix

[ 2/W   0    0 -2.Cx/W ]
[   0 2/H    0 -2.Cy/H ]
[   0   0 -2/D -2.Cz/D ]
[   0   0    0       1 ]

Note that the entry corresponding to the scale factor for the Z coordinate is negative (eye space has +Z pointing toward the viewer, while clip space and normalised device space have +Z pointing away from the viewer).

Similarly, a glViewport() call of the form

glViewport(X, Y, W, H);

will generate the matrix

[ W/2   0   0 X+W/2 ]
[   0 H/2   0 Y+H/2 ]
[   0   0   1     0 ]
[   0   0   0     1 ]

If W and H are the same in both the glOrtho() and glViewport() calls, the combination of these two transformations will result in the X and Y scale factors both being 1. Similarly, if W and H have the same ratio in both calls, the X and Y scale factors will be equal.