debug messages

This commit is contained in:
David Rose 2003-07-02 19:30:54 +00:00
parent 90918d5f6c
commit 1bc836605f

View File

@ -27,19 +27,20 @@ compose_matrix(FLOATNAME(LMatrix3) &mat,
const FLOATNAME(LVecBase3) &hpr, const FLOATNAME(LVecBase3) &hpr,
CoordinateSystem cs) { CoordinateSystem cs) {
// temp_hpr_fix blocks use the correct way. need to keep other way as default until // temp_hpr_fix blocks use the correct way. need to keep other way
// legacy tools are fixed to work with correct way // as default until legacy tools are fixed to work with correct way
if (temp_hpr_fix) { if (temp_hpr_fix) {
mat.scale_multiply(scale, mat.scale_multiply(scale,
FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[2], FLOATNAME(LVector3)::forward(cs), cs) * FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[2], FLOATNAME(LVector3)::forward(cs), cs) *
FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[1], FLOATNAME(LVector3)::right(cs), cs) * FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[1], FLOATNAME(LVector3)::right(cs), cs) *
FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[0], FLOATNAME(LVector3)::up(cs), cs)); FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[0], FLOATNAME(LVector3)::up(cs), cs));
} else { } else {
mat.scale_multiply(scale, mat.scale_multiply(scale,
FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[1], FLOATNAME(LVector3)::right(cs), cs) * FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[1], FLOATNAME(LVector3)::right(cs), cs) *
FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[0], FLOATNAME(LVector3)::up(cs), cs) * FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[0], FLOATNAME(LVector3)::up(cs), cs) *
FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[2], FLOATNAME(LVector3)::back(cs), cs)); FLOATNAME(LMatrix3)::rotate_mat_normaxis(hpr[2], FLOATNAME(LVector3)::back(cs), cs));
} }
} }
@ -75,7 +76,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the heading, and continue. // Unwind the heading, and continue.
Matrix rot_y; Matrix rot_y;
rot_y = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f), rot_y = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f),
CS_yup_right); CS_yup_right);
x = x * rot_y; x = x * rot_y;
y = y * rot_y; y = y * rot_y;
@ -91,7 +92,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the pitch. // Unwind the pitch.
Matrix rot_x; Matrix rot_x;
rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f), rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f),
CS_yup_right); CS_yup_right);
x = x * rot_x; x = x * rot_x;
y = y * rot_x; y = y * rot_x;
@ -107,7 +108,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;
y = y * rot_z; y = y * rot_z;
@ -140,7 +141,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;
y = y * rot_z; y = y * rot_z;
@ -157,7 +158,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the heading, and continue. // Unwind the heading, and continue.
Matrix rot_y; Matrix rot_y;
rot_y = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f), rot_y = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f),
CS_yup_right); CS_yup_right);
x = x * rot_y; x = x * rot_y;
y = y * rot_y; y = y * rot_y;
@ -173,7 +174,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the pitch. // Unwind the pitch.
Matrix rot_x; Matrix rot_x;
rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f), rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f),
CS_yup_right); CS_yup_right);
x = x * rot_x; x = x * rot_x;
y = y * rot_x; y = y * rot_x;
@ -220,7 +221,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;
y = y * rot_z; y = y * rot_z;
@ -237,7 +238,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// Unwind the heading, and continue. // Unwind the heading, and continue.
Matrix rot_y; Matrix rot_y;
rot_y = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f), rot_y = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f),
CS_yup_right); CS_yup_right);
x = x * rot_y; x = x * rot_y;
y = y * rot_y; y = y * rot_y;
@ -253,7 +254,7 @@ unwind_yup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// Unwind the pitch. // Unwind the pitch.
Matrix rot_x; Matrix rot_x;
rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f), rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f),
CS_yup_right); CS_yup_right);
x = x * rot_x; x = x * rot_x;
y = y * rot_x; y = y * rot_x;
@ -301,7 +302,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the heading, and continue. // Unwind the heading, and continue.
Matrix rot_z; Matrix rot_z;
rot_z = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f), rot_z = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f),
CS_zup_right); CS_zup_right);
x = x * rot_z; x = x * rot_z;
y = y * rot_z; y = y * rot_z;
@ -317,7 +318,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the pitch. // Unwind the pitch.
Matrix rot_x; Matrix rot_x;
rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f), rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f),
CS_zup_right); CS_zup_right);
x = x * rot_x; x = x * rot_x;
y = y * rot_x; y = y * rot_x;
@ -333,7 +334,7 @@ unwind_zup_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_y; Matrix rot_y;
rot_y = Matrix::rotate_mat_normaxis(-roll, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f), rot_y = Matrix::rotate_mat_normaxis(-roll, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f),
CS_zup_right); CS_zup_right);
x = x * rot_y; x = x * rot_y;
y = y * rot_y; y = y * rot_y;
@ -377,7 +378,7 @@ unwind_zup_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_y; Matrix rot_y;
rot_y = Matrix::rotate_mat_normaxis(roll, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f), rot_y = Matrix::rotate_mat_normaxis(roll, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f),
CS_zup_right); CS_zup_right);
x = x * rot_y; x = x * rot_y;
y = y * rot_y; y = y * rot_y;
@ -394,7 +395,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the heading, and continue. // Unwind the heading, and continue.
Matrix rot_z; Matrix rot_z;
rot_z = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f), rot_z = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f),
CS_zup_right); CS_zup_right);
x = x * rot_z; x = x * rot_z;
y = y * rot_z; y = y * rot_z;
@ -410,7 +411,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr) {
// Unwind the pitch. // Unwind the pitch.
Matrix rot_x; Matrix rot_x;
rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f), rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f),
CS_zup_right); CS_zup_right);
x = x * rot_x; x = x * rot_x;
y = y * rot_x; y = y * rot_x;
@ -457,7 +458,7 @@ unwind_zup_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_y; Matrix rot_y;
rot_y = Matrix::rotate_mat_normaxis(roll, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f), rot_y = Matrix::rotate_mat_normaxis(roll, FLOATNAME(LVector3)(0.0f, 1.0f, 0.0f),
CS_zup_right); CS_zup_right);
x = x * rot_y; x = x * rot_y;
y = y * rot_y; y = y * rot_y;
@ -474,7 +475,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// Unwind the heading, and continue. // Unwind the heading, and continue.
Matrix rot_z; Matrix rot_z;
rot_z = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f), rot_z = Matrix::rotate_mat_normaxis(-heading, FLOATNAME(LVector3)(0.0f, 0.0f, 1.0f),
CS_zup_right); CS_zup_right);
x = x * rot_z; x = x * rot_z;
y = y * rot_z; y = y * rot_z;
@ -490,7 +491,7 @@ unwind_zup_rotation(FLOATNAME(LMatrix3) &mat, FLOATNAME(LVecBase3) &hpr,
// Unwind the pitch. // Unwind the pitch.
Matrix rot_x; Matrix rot_x;
rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f), rot_x = Matrix::rotate_mat_normaxis(-pitch, FLOATNAME(LVector3)(1.0f, 0.0f, 0.0f),
CS_zup_right); CS_zup_right);
x = x * rot_x; x = x * rot_x;
y = y * rot_x; y = y * rot_x;
@ -523,6 +524,11 @@ 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 << "\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 bMatHasNoShear,bIsLeftHandedMat;
@ -533,46 +539,46 @@ 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; bIsLeftHandedMat = 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; bIsLeftHandedMat = false;
} }
break; break;
case CS_zup_left: case CS_zup_left:
{ {
new_mat._m.m._02 = -new_mat._m.m._02; new_mat._m.m._02 = -new_mat._m.m._02;
new_mat._m.m._12 = -new_mat._m.m._12; new_mat._m.m._12 = -new_mat._m.m._12;
new_mat._m.m._20 = -new_mat._m.m._20; new_mat._m.m._20 = -new_mat._m.m._20;
new_mat._m.m._21 = -new_mat._m.m._21; new_mat._m.m._21 = -new_mat._m.m._21;
/* /*
FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2), FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2),
mat(1, 0), mat(1, 1), -mat(1, 2), mat(1, 0), mat(1, 1), -mat(1, 2),
-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; bIsLeftHandedMat = true;
} }
break; break;
case CS_yup_left: case CS_yup_left:
{ {
new_mat._m.m._02 = -new_mat._m.m._02; new_mat._m.m._02 = -new_mat._m.m._02;
new_mat._m.m._12 = -new_mat._m.m._12; new_mat._m.m._12 = -new_mat._m.m._12;
new_mat._m.m._20 = -new_mat._m.m._20; new_mat._m.m._20 = -new_mat._m.m._20;
new_mat._m.m._21 = -new_mat._m.m._21; new_mat._m.m._21 = -new_mat._m.m._21;
/* /*
FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2), FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2),
mat(1, 0), mat(1, 1), -mat(1, 2), mat(1, 0), mat(1, 1), -mat(1, 2),
-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; bIsLeftHandedMat = true;
} }
break; break;
@ -581,21 +587,26 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
<< "Unexpected coordinate system: " << (int)cs << "\n"; << "Unexpected coordinate system: " << (int)cs << "\n";
return false; return false;
} }
if (linmath_cat.is_debug()) {
linmath_cat.debug()
<< "after unwind, mat is " << new_mat << "\n";
}
scale[2] = new_mat._m.m._22; scale[2] = new_mat._m.m._22;
if(bIsLeftHandedMat) { if(bIsLeftHandedMat) {
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 { } else {
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;
} }
bMatHasNoShear = bMatHasNoShear =
(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 bMatHasNoShear;
} }
@ -632,46 +643,46 @@ 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; bIsLeftHandedMat = 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; bIsLeftHandedMat = false;
} }
break; break;
case CS_zup_left: case CS_zup_left:
{ {
new_mat._m.m._02 = -new_mat._m.m._02; new_mat._m.m._02 = -new_mat._m.m._02;
new_mat._m.m._12 = -new_mat._m.m._12; new_mat._m.m._12 = -new_mat._m.m._12;
new_mat._m.m._20 = -new_mat._m.m._20; new_mat._m.m._20 = -new_mat._m.m._20;
new_mat._m.m._21 = -new_mat._m.m._21; new_mat._m.m._21 = -new_mat._m.m._21;
/* /*
FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2), FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2),
mat(1, 0), mat(1, 1), -mat(1, 2), mat(1, 0), mat(1, 1), -mat(1, 2),
-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; bIsLeftHandedMat = true;
} }
break; break;
case CS_yup_left: case CS_yup_left:
{ {
new_mat._m.m._02 = -new_mat._m.m._02; new_mat._m.m._02 = -new_mat._m.m._02;
new_mat._m.m._12 = -new_mat._m.m._12; new_mat._m.m._12 = -new_mat._m.m._12;
new_mat._m.m._20 = -new_mat._m.m._20; new_mat._m.m._20 = -new_mat._m.m._20;
new_mat._m.m._21 = -new_mat._m.m._21; new_mat._m.m._21 = -new_mat._m.m._21;
/* /*
FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2), FLOATNAME(LMatrix3) lm(mat(0, 0), mat(0, 1), -mat(0, 2),
mat(1, 0), mat(1, 1), -mat(1, 2), mat(1, 0), mat(1, 1), -mat(1, 2),
-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; bIsLeftHandedMat = true;
} }
break; break;
@ -681,19 +692,19 @@ decompose_matrix(const FLOATNAME(LMatrix3) &mat,
return false; return false;
} }
scale[2] = new_mat._m.m._22; scale[2] = new_mat._m.m._22;
if(bIsLeftHandedMat) { if(bIsLeftHandedMat) {
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 { } else {
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;
} }
bMatHasNoShear = bMatHasNoShear =
(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 bMatHasNoShear;
} }