Quote:Original post by Cacks
Also, what is the 4rth element of these vectors used for? And what should it be initialised to?
Thanks!
The 4th element has been introduced to overcome certain difficulties that arise in 3d, like the fact that the origin is invariant under matrix multiplication.
Without getting in the underlying math, if you want to represent a point initialize its 4-th coordinate "w" to 1. If you want to represent a direction of some magnitude (vector), set it to 0. As you can see, 4d vectors with w==0 are not affected by the translation part of the matrices, sums of vectors are vectors, difference of points is vector etc... (just like they should)
Furthermore, all points *must* have w==1. If you transform a 4d vector by such a matrix, its w will generally change. In order for the result to represent a point in the original space, all its components must be divided by its w, thus it must be normalized to its w. Else, it's not a point, it's a set of projective coordinates.
And a clarification on the matrices mentioned by jyk...
Their upper-left 3x3 part must be strictly unit column vectors, mutually perpendicular. The determinant of that sub-matrix is 1, which means geometrically that it preserves the volume of the transformed set.
It is quite often, that these unit vectors are multiplied by a scaling value for that axis (to apply scaling to the model), so make sure to normalize them before using them in any way.
The rest part, the zeros and translation do not affect this property because they do not affect the determinant.
The inverse matrix has the aforementioned form, only if there is no scaling encoded in the matrix.