Jump to content
  • Advertisement

Archived

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

evil_ash

Matix inverse

This topic is 5729 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

Can someone please explain a way to find the inverse of a 4x4 matrix other than useing adjoints....since i wrote this based on the adjoint method and it doesnt seem to work Matrix Matrix::Inverse() { Matrix Cofactors,Adjoint; Cofactors.Set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); Adjoint.Set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); int row=0,column=0; float subMatrix[4][4]={0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; for(int r=0;r<4;r++) { for(int c=0;c<4;c++) { for(int xr=0;xr<4;xr++) { if(xr==r) continue; for(int xc=0;xc<4;xc++) { if(xc==c) { continue; } else { subMatrix[row][column]=Entry[xr][xc]; column++; } } row++;column=0; } if((r+c)%2) Cofactors.Entry[r][c]-=Determinant(subMatrix,3); else Cofactors.Entry[r][c]+=Determinant(subMatrix,3); row=0;column=0; } } Adjoint=Cofactors.Transpose(); float Det=Determinant(Entry,4); return Matrix(Adjoint.Entry[0][0]/Det,Adjoint.Entry[0][1]/Det,Adjoint.Entry[0][2]/Det,Adjoint.Entry[0][3]/Det, Adjoint.Entry[1][0]/Det,Adjoint.Entry[1][1]/Det,Adjoint.Entry[1][2]/Det,Adjoint.Entry[1][3]/Det, Adjoint.Entry[2][0]/Det,Adjoint.Entry[2][1]/Det,Adjoint.Entry[2][2]/Det,Adjoint.Entry[2][3]/Det, Adjoint.Entry[3][0]/Det,Adjoint.Entry[3][1]/Det,Adjoint.Entry[3][2]/Det,Adjoint.Entry[3][3]/Det); } Matrix Matrix::Transpose() { return Matrix(Entry[0][0],Entry[1][0],Entry[2][0],Entry[3][0], Entry[0][1],Entry[1][1],Entry[2][1],Entry[3][1], Entry[0][2],Entry[1][2],Entry[2][2],Entry[3][2], Entry[0][3],Entry[1][3],Entry[2][3],Entry[3][3]); } float Matrix::Determinant(float Matrix[4][4],int Dimen) { if (Dimen==2) return ((Matrix[0][0]*Matrix[1][1])-(Matrix[1][0]*Matrix[0][1])); float det=0; int row=0,column=0; float subMatrix[4][4]={0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}; for(int c=0;c

Share this post


Link to post
Share on other sites
Advertisement

  • 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!