This is how you decide:
- You add
1
if your vector represents a position, and thus should be translated (which is the case of the point).
- You add
0
for common vectors (which makes sense for the axis, or any
direction vector).
Adding 1
is the most common case, because the bulk of data that we need to transform are vertex positions.
The idea behind this is that the fourth component of the vector will be multiplied with the part of the transformation matrix that encodes a translation. And thus using a 0
in the fourth component will nullify the translation.
It might be easier to imagine if you consider a transformation that only has translation. For example, let us say the transformation moves 1 unit along the x axis. And you have your axis vector (-1, 0, 0)
, after the transformation should it be (0, 0, 0)
(moved 1 unit on the x axis) or (-1, 0, 0)
(unaffected by translation)? Well, the axis continues to be the same axis, so it is the latter, thus when transforming the latter you augment it with a 0
. Of course, it still makes sense to have it affected by mirroring, rotation, shearing, and scaling.
Since there might be scaling, another related decision is if you will normalize the vector after the translation. For example, a direction (such as a surface normal) should be a unit vector, so you will normalize it after you translate it. But for other vectors - despite not representing position - their length is important. For example, if you transformed a velocity vector, it does not make sense to normalize it after the transformation (in this case the scaling could be considered a change in length units).
Addendum
Dividing by the fourth component results in foreshortening (things appearing smaller due to perspective), which - again - only make sense for points.
Furthermore, the view matrix shouldn't affect the fourth component (or you are doing something odd). Which means that for the view matrix you can skip the step of dividing by the fourth component altogether.
And thus, you shouldn't have to deal with the case of dividing by 0
from the fourth component.