Matrix maths...

Started by
6 comments, last by Lethe 23 years, 5 months ago
Does anyone know the maths that is behind a 4x4 matrix - I can do the 3x3 part, and transilate a position, but the extra 7 values that are around the edge are beyond me, I know they apply a position transformation, and can also apply perspective from the DX SDK, but it won''t give me the formula it uses. So what are they?
Advertisement
quote:Original post by Lethe

Does anyone know the maths that is behind a 4x4 matrix - I can do the 3x3 part, and transilate a position, but the extra 7 values that are around the edge are beyond me, I know they apply a position transformation, and can also apply perspective from the DX SDK, but it won't give me the formula it uses. So what are they?


The way this works is through the understanding that the vectors are really homogenous 1x4 vectors rather than 1x3. Rather than just [x y z] you have [x y z w]. For most operations you will keep w == 1, so w is usually not explicitly stated.

When you add a fourth parameter to a 3 dimensional space, you duplicate points (ie, it provides multiple ways to specify the same point). So [1 2 3 4] equals [2 4 6 2] equals [4 8 12 1]. [x y z w] == [x/w y/w z/w 1].

Try multiplying out a homogenous vector [x y z 1] by your 4x4 matrices and experiment to find which parts are rotation, scale, translation, perspective, and other.



---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
---- --- -- -
New York. New York. New York. Texas. Texas. New York. New York. Canada.
---- --- -- -

Edited by - mossmoss on December 5, 2000 9:00:24 AM
The above plus a file I found has explained how to do the transformation. Now next Q. How do you multiply 2 of these matrixies? I can do matrix multipication in general, but I expect it's different with all those 'weird' values Formula anybody?
-Lethe

Edited by - Lethe on December 6, 2000 3:45:43 AM
Matrix multiplication works the same. Take the first column of one times the first row of the other, add up the products and that becomes the entry in 1,1 in the product matrix. Then the second column in one times the second row of the other and that becomes the element under that first value. etc.

In code
for (r = 0; r < 4; r++) {  for (c = 0; c < 4; c++) {    product[c][r] = 0.0;    for (k = 0; k < 4; k++) {      product[c][r] += first[k][r] * second[c][k];    }  }} 
Really? Some cleaver maths nut must of worked out how to get that working. Thanks.
-Lethe
if u want really fast MatrixMultiplies, you can even unroll the whole loop, and have a MultMat3 and MultMat4 function


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have no name that you may call me. I am merely Succinct.
~Succinct Demos Online~
"Hey, where''d that display list rotate off to now?"
-(Drop me a line here)-

-- Succinct(Don't listen to me)
Lethe: Surely that name should be banned. I thought this board has censorship for profanities.
Huh? Profanity? I''ve re-read the thread like three times now and I didn''t see any. Unless the name, Lethe itself, is profane? Isn''t it the name of the river of forgetfulness in Greek myth?

This topic is closed to new replies.

Advertisement