more polish on temp_hpr_fix and different coordinate systems

This commit is contained in:
David Rose 2003-07-02 21:30:42 +00:00
parent 1bc836605f
commit 8381136b9a
2 changed files with 44 additions and 29 deletions

View File

@ -107,7 +107,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the roll from the axes, and continue. // Unwind the roll from the axes, and continue.
Matrix rot_z; Matrix rot_z;
rot_z = Matrix::rotate_mat_normaxis(-roll, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f), rot_z = Matrix::rotate_mat_normaxis(roll, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f),
CS_yup_right); CS_yup_right);
x = x * rot_z; x = x * rot_z;
@ -531,7 +531,7 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
// Extract the rotation and scale, according to the coordinate // Extract the rotation and scale, according to the coordinate
// system of choice. // system of choice.
bool bMatHasNoShear,bIsLeftHandedMat; bool is_left_handed;
FLOATNAME(LMatrix3) new_mat(mat); FLOATNAME(LMatrix3) new_mat(mat);
@ -539,14 +539,14 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
case CS_zup_right: case CS_zup_right:
{ {
unwind_zup_rotation(new_mat, hpr); unwind_zup_rotation(new_mat, hpr);
bIsLeftHandedMat = false; is_left_handed = false;
} }
break; break;
case CS_yup_right: case CS_yup_right:
{ {
unwind_yup_rotation(new_mat, hpr); unwind_yup_rotation(new_mat, hpr);
bIsLeftHandedMat = false; is_left_handed = false;
} }
break; break;
@ -562,7 +562,9 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
-mat(2, 0), -mat(2, 1), mat(2, 2)); -mat(2, 0), -mat(2, 1), mat(2, 2));
*/ */
unwind_zup_rotation(new_mat, hpr); unwind_zup_rotation(new_mat, hpr);
bIsLeftHandedMat = true; hpr[0] = -hpr[0];
hpr[2] = -hpr[2];
is_left_handed = true;
} }
break; break;
@ -578,7 +580,7 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
-mat(2, 0), -mat(2, 1), mat(2, 2)); -mat(2, 0), -mat(2, 1), mat(2, 2));
*/ */
unwind_yup_rotation(new_mat, hpr); unwind_yup_rotation(new_mat, hpr);
bIsLeftHandedMat = true; is_left_handed = true;
} }
break; break;
@ -593,21 +595,22 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
<< "after unwind, mat is " << new_mat << "\n"; << "after unwind, mat is " << new_mat << "\n";
} }
scale[0] = new_mat._m.m._00;
scale[1] = new_mat._m.m._11;
scale[2] = new_mat._m.m._22; scale[2] = new_mat._m.m._22;
if(bIsLeftHandedMat) { /*
if (is_left_handed) {
scale[0] = -new_mat._m.m._00; scale[0] = -new_mat._m.m._00;
scale[1] = -new_mat._m.m._11; scale[1] = -new_mat._m.m._11;
} else {
scale[0] = new_mat._m.m._00;
scale[1] = new_mat._m.m._11;
} }
*/
bMatHasNoShear = bool has_no_shear =
(fabs(new_mat(0, 1)) + fabs(new_mat(0, 2)) + (fabs(new_mat(0, 1)) + fabs(new_mat(0, 2)) +
fabs(new_mat(1, 0)) + fabs(new_mat(1, 2)) + fabs(new_mat(1, 0)) + fabs(new_mat(1, 2)) +
fabs(new_mat(2, 0)) + fabs(new_mat(2, 1))) < 0.0001; fabs(new_mat(2, 0)) + fabs(new_mat(2, 1))) < 0.0001;
return bMatHasNoShear; return has_no_shear;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -633,9 +636,15 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
cs = default_coordinate_system; cs = default_coordinate_system;
} }
if (linmath_cat.is_debug()) {
linmath_cat.debug()
<< "decomposing " << mat << " via cs " << cs
<< " with roll = " << roll << "\n";
}
// Extract the rotation and scale, according to the coordinate // Extract the rotation and scale, according to the coordinate
// system of choice. // system of choice.
bool bMatHasNoShear,bIsLeftHandedMat; bool is_left_handed;
FLOATNAME(LMatrix3) new_mat(mat); FLOATNAME(LMatrix3) new_mat(mat);
@ -643,14 +652,14 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
case CS_zup_right: case CS_zup_right:
{ {
unwind_zup_rotation(new_mat, hpr, roll); unwind_zup_rotation(new_mat, hpr, roll);
bIsLeftHandedMat = false; is_left_handed = false;
} }
break; break;
case CS_yup_right: case CS_yup_right:
{ {
unwind_yup_rotation(new_mat, hpr, roll); unwind_yup_rotation(new_mat, hpr, roll);
bIsLeftHandedMat = false; is_left_handed = false;
} }
break; break;
@ -666,7 +675,7 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
-mat(2, 0), -mat(2, 1), mat(2, 2)); -mat(2, 0), -mat(2, 1), mat(2, 2));
*/ */
unwind_zup_rotation(new_mat, hpr, roll); unwind_zup_rotation(new_mat, hpr, roll);
bIsLeftHandedMat = true; is_left_handed = true;
} }
break; break;
@ -682,7 +691,7 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
-mat(2, 0), -mat(2, 1), mat(2, 2)); -mat(2, 0), -mat(2, 1), mat(2, 2));
*/ */
unwind_yup_rotation(new_mat, hpr, roll); unwind_yup_rotation(new_mat, hpr, roll);
bIsLeftHandedMat = true; is_left_handed = true;
} }
break; break;
@ -691,21 +700,27 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
<< "Unexpected coordinate system: " << (int)cs << "\n"; << "Unexpected coordinate system: " << (int)cs << "\n";
return false; return false;
} }
scale[2] = new_mat._m.m._22; if (linmath_cat.is_debug()) {
if(bIsLeftHandedMat) { linmath_cat.debug()
scale[0] = -new_mat._m.m._00; << "after unwind, mat is " << new_mat << "\n";
scale[1] = -new_mat._m.m._11;
} else {
scale[0] = new_mat._m.m._00;
scale[1] = new_mat._m.m._11;
} }
bMatHasNoShear = scale[0] = new_mat._m.m._00;
scale[1] = new_mat._m.m._11;
scale[2] = new_mat._m.m._22;
/*
if (is_left_handed) {
scale[0] = -new_mat._m.m._00;
scale[1] = -new_mat._m.m._11;
}
*/
bool has_no_shear =
(fabs(new_mat(0, 1)) + fabs(new_mat(0, 2)) + (fabs(new_mat(0, 1)) + fabs(new_mat(0, 2)) +
fabs(new_mat(1, 0)) + fabs(new_mat(1, 2)) + fabs(new_mat(1, 0)) + fabs(new_mat(1, 2)) +
fabs(new_mat(2, 0)) + fabs(new_mat(2, 1))) < 0.0001; fabs(new_mat(2, 0)) + fabs(new_mat(2, 1))) < 0.0001;
return bMatHasNoShear; return has_no_shear;
} }

View File

@ -46,7 +46,7 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
FLOATNAME(LVecBase3) &scale, FLOATNAME(LVecBase3) &scale,
FLOATNAME(LVecBase3) &hpr, FLOATNAME(LVecBase3) &hpr,
FLOATTYPE roll, FLOATTYPE roll,
CoordinateSystem cs = CS_default); CoordinateSystem cs);
INLINE_LINMATH bool INLINE_LINMATH bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat, decompose_matrix(const FLOATNAME(LMatrix4) &mat,
@ -61,7 +61,7 @@ decompose_matrix(const FLOATNAME(LMatrix4) &mat,
FLOATNAME(LVecBase3) &hpr, FLOATNAME(LVecBase3) &hpr,
FLOATNAME(LVecBase3) &translate, FLOATNAME(LVecBase3) &translate,
FLOATTYPE roll, FLOATTYPE roll,
CoordinateSystem cs = CS_default); CoordinateSystem cs);
INLINE_LINMATH bool INLINE_LINMATH bool
decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATTYPE components[9], decompose_matrix(const FLOATNAME(LMatrix4) &mat, FLOATTYPE components[9],