• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Multiplying Matrices

This topic is 6779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
Why doesn''t M1 have and variable?

---
www.crazycrackerz.org

##### Share on other sites
Oh, now I know, the board messed it up (italics) [ i ] w/o space is waht I meant...

---
www.crazycrackerz.org

##### Share on other sites
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

##### Share on other sites
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).

##### Share on other sites
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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634047
• Total Posts
3015226
×