add a transpose method for 4x4

and a transpose3x3 to transpose only orthogonal part of a mat4x4
This commit is contained in:
Julien Valentin 2017-08-23 19:06:25 +02:00
parent f97b1626b3
commit 3b03699fbc
3 changed files with 52 additions and 5 deletions

View File

@ -242,6 +242,12 @@ class OSG_EXPORT Matrixd
/** full 4x4 matrix invert. */
bool invert_4x4( const Matrixd& rhs);
/** transpose a matrix */
bool transpose(const Matrixd&rhs);
/** transpose orthogonal part of the matrix **/
bool transpose3x3(const Matrixd&rhs);
/** ortho-normalize the 3x3 rotation & scale matrix */
void orthoNormalize(const Matrixd& rhs);

View File

@ -242,6 +242,12 @@ class OSG_EXPORT Matrixf
/** full 4x4 matrix invert. */
bool invert_4x4( const Matrixf& rhs);
/** transpose matrix **/
bool transpose(const Matrixf&rhs);
/** transpose orthogonal part of the matrix **/
bool transpose3x3(const Matrixf&rhs);
/** ortho-normalize the 3x3 rotation & scale matrix */
void orthoNormalize(const Matrixf& rhs);

View File

@ -742,6 +742,41 @@ inline T SGL_ABS(T a)
#define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
#endif
bool Matrix_implementation::transpose(const Matrix_implementation&mat){
if (&mat==this) {
Matrix_implementation tm(mat);
return transpose(tm);
}
_mat[0][1]=mat._mat[1][0];
_mat[0][2]=mat._mat[2][0];
_mat[0][3]=mat._mat[3][0];
_mat[1][0]=mat._mat[0][1];
_mat[1][2]=mat._mat[2][1];
_mat[1][3]=mat._mat[3][1];
_mat[2][0]=mat._mat[0][2];
_mat[2][1]=mat._mat[1][2];
_mat[2][3]=mat._mat[3][2];
_mat[3][0]=mat._mat[0][3];
_mat[3][1]=mat._mat[1][3];
_mat[3][2]=mat._mat[2][3];
return true;
}
bool Matrix_implementation::transpose3x3(const Matrix_implementation&mat){
if (&mat==this) {
Matrix_implementation tm(mat);
return transpose3x3(tm);
}
_mat[0][1]=mat._mat[1][0];
_mat[0][2]=mat._mat[2][0];
_mat[1][0]=mat._mat[0][1];
_mat[1][2]=mat._mat[2][1];
_mat[2][0]=mat._mat[0][2];
_mat[2][1]=mat._mat[1][2];
return true;
}
bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
{
if (&mat==this) {
@ -763,7 +798,7 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
for(i=0;i<4;i++)
{
big=0.0;
for (j=0; j<4; j++)
for (j=0; j<4; ++j)
if (ipiv[j] != 1)
for (k=0; k<4; k++)
{
@ -781,7 +816,7 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
}
++(ipiv[icol]);
if (irow != icol)
for (l=0; l<4; l++) SGL_SWAP(operator()(irow,l),
for (l=0; l<4; ++l) SGL_SWAP(operator()(irow,l),
operator()(icol,l),
temp);
@ -792,13 +827,13 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
pivinv = 1.0/operator()(icol,icol);
operator()(icol,icol) = 1;
for (l=0; l<4; l++) operator()(icol,l) *= pivinv;
for (ll=0; ll<4; ll++)
for (l=0; l<4; ++l) operator()(icol,l) *= pivinv;
for (ll=0; ll<4; ++ll)
if (ll != icol)
{
dum=operator()(ll,icol);
operator()(ll,icol) = 0;
for (l=0; l<4; l++) operator()(ll,l) -= operator()(icol,l)*dum;
for (l=0; l<4; ++l) operator()(ll,l) -= operator()(icol,l)*dum;
}
}
for (int lx=4; lx>0; --lx)