A similar question/explanation at:

http://www.flipcode.com/cgi-bin/msg.cgi?showThread=18June2001-PlottingA3DPointOnA2DScreen&forum=askmid&id=-1

W is the scaling factor for the viewport. Dividing by it will get you into screen-relative space. 1.0/W is pre-calculating the inverse so that a multiply can be used -- it is only used twice, but still faster to calculate the inverseW once and multiply against it, rather than dividing twice (yes, division is THAT BAD).

The - is because the 0,0 in 3D screen coords is usually the BOTTOM left, need to flip Y to get it to the TOP left.

As you say, generated view coordinates will be in the range of [-1,1] so for x:

1 + [-1,1] => [0,2] * 0.5 => [0,1]

and for y:

1 - [-1,1] => [2,0] * 0.5 => [1,0]

thus flipping the Y axis on the screen properly.

Multiplying by height/width then gets into screen pixels.

d

http://www.flipcode.com/cgi-bin/msg.cgi?showThread=18June2001-PlottingA3DPointOnA2DScreen&forum=askmid&id=-1

W is the scaling factor for the viewport. Dividing by it will get you into screen-relative space. 1.0/W is pre-calculating the inverse so that a multiply can be used -- it is only used twice, but still faster to calculate the inverseW once and multiply against it, rather than dividing twice (yes, division is THAT BAD).

The - is because the 0,0 in 3D screen coords is usually the BOTTOM left, need to flip Y to get it to the TOP left.

As you say, generated view coordinates will be in the range of [-1,1] so for x:

1 + [-1,1] => [0,2] * 0.5 => [0,1]

and for y:

1 - [-1,1] => [2,0] * 0.5 => [1,0]

thus flipping the Y axis on the screen properly.

Multiplying by height/width then gets into screen pixels.

d