Jump to content
  • Advertisement

Archived

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

Esap1

Multiplying Matrices

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

If you intended to correct an error in the post then please contact us.

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 this post


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

---
www.crazycrackerz.org

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!