Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multiplying Matrices

Started by Esap1 Jun 25, 2000 at 1:24 PM 4 replies 300+ views
Original Post
Esap1
Esap1
I tried this to Multiply the Matricies: for(int i=0;i<4;i++) { float sum =0; for(int j=0;j<4;j++) { sum += M1[j] * M2[j][i] } M3[i][j] = sum; } And I made my rotation Matrix and tried to Multiply it by a Idenity Matrix and it doesnt come out the same. Are you sure that will work. Because I know the rotation matrix is right, Ive tested it, but when I use that code above, and multiply it by an Idenity Matrix, it doesnt come out the same, and ideas?
acw83
acw83
Why doesn''t M1 have and variable?

---
www.crazycrackerz.org
acw83
acw83
Oh, now I know, the board messed it up (italics) [ i ] w/o space is waht I meant...

---
www.crazycrackerz.org
Shannon Barber
Shannon Barber
The code I gave you eariler worked perfectly wrong

try this
    
Matrix& Matrix_Mult(const Matrix& M1, const Matrix& M2)
{
Matrix* M3;
M3 = new Matrix;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
float sum=0;
for(int k=0;k<4;k++)
{
sum += M1[ i ][j] * M2[j][ i ];
}
}
M3[ i ][j] = sum;
}
return(*M3);
}



Edited by - Magmai Kai Holmlor on June 25, 2000 2:49:07 PM
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Esap1
Esap1
Are you sure that right(I mean the code), wouldnt:
for(int k=0;k<4;k++)
{
sum += M1[ i ][j] * M2[j][ i ];
}

be the same as

sum+=M1[j] * M2[j][i];
sum*=4;


It doesnt seem to work either?(I tried multiplying my working Rotation Matrix with an Idenity Matrix, and it spat a garbage matrix).
Shannon Barber
Shannon Barber
quote:
Original post by Esap1

Are you sure that right(I mean the code), wouldnt:
for(int k=0;k<4;k++)
{
sum += M1[ i ][j] * M2[j][ i ];
}

be the same as

sum+=M1[ i ][j] * M2[j][ i ];
sum*=4;



Good Lord no!

[1,2,3] * [1,0,0] = [1*1+2*0+3*0, 1*0+2*1+3*0, 1*0+2*0+3*1]
[4,5,6] * [0,1,0] = [4*1+5*0+6*0, 4*0+5*1+6*0, 4*0+5*0+6*1]
[7,8,9] * [0,0,1] = [7*1+8*0+9*1, 7*0+8*1+9*0, 7*0+8*0+9*1]

= [1,2,3]
= [4,5,6]
= [7,8,9]


the [1,2,3] get multipled by
[1]
[0]
[0]
for the first cell of the new matrix

for row 1 column 2...
[1,2,3]
*
[0]
[1]
[0]


Edited by - Magmai Kai Holmlor on June 25, 2000 4:10:43 PM

Edited by - Magmai Kai Holmlor on June 25, 2000 4:11:23 PM

Edited by - Magmai Kai Holmlor on June 25, 2000 4:12:44 PM
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.