Fixed some bugs.

This commit is contained in:
Tristan Campbell 2002-10-26 18:54:54 +00:00
parent 466cc98536
commit b161ad781a
2 changed files with 3 additions and 87 deletions

View file

@ -98,48 +98,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpDire
#ifdef _DEBUG
printf("Matrix Determinant: %f\n", det);
printf("Matrix Determinant - 1 = %f\n", det -1);
printf("FLOATING POINT ERROR: %f\n", FLOATING_POINT_ERROR);
#endif
// use approxEqual to avoid direct comparisons
if (approxEqual(det, 1.0f) ||
approxEqual(det, -1.0f))
{
#ifdef _DEBUG
printf("Matrix is Orthogonal\n");
#endif
/* this matrix is orthogonal
since inv(M) * M = I
when orthogonal
trans(M) * M = I
proper orthogonal
inv(M) = trans(M)
improper orthogonal
inv(M) = -trans(M)
*/
if (approxEqual(det, 1))
{
// proper orthogonal
int srcIndex = 0;
for (int col = 0; col < source.width; col++)
for (int row = 0; row < source.height; row++)
destMatrix[col + row * source.width] = srcMatrix[srcIndex++];
}
else
{
// improper orthogonal
int srcIndex = 0;
for (int col = 0; col < source.width; col++)
for (int row = 0; row < source.height; row++)
destMatrix[col + row * source.width] = -srcMatrix[srcIndex++];
}
}
else
{
float sign;
@ -167,12 +126,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpDire
= (sign / det) * determinant(temp_matrix, temp_side);
// swap signs
sign = (sign == 1) ? -1.0f : 1.0f;
sign *= -1.0f;
}
}
}
dest.writeComplete();
}
}

View file

@ -98,49 +98,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpSafe
#ifdef _DEBUG
printf("Matrix Determinant: %f\n", det);
printf("Matrix Determinant - 1: %f\n", det-1);
printf("FLOATING POINT ERROR: %f\n", FLOATING_POINT_ERROR);
#endif
// use approxEqual to avoid direct comparisons
if (approxEqual(det,1) || approxEqual(det, -1))
{
#ifdef _DEBUG
printf("Matrix is Orthogonal\n");
#endif
/* this matrix is orthogonal
since inv(M) * M = I
when orthogonal
trans(M) * M = I
proper orthogonal
inv(M) = trans(M)
improper orthogonal
inv(M) = -trans(M)
*/
if (approxEqual(det, 1))
{
// proper orthogonal
int srcIndex = 0;
for (int col = 0; col < source.width; col++)
for (int row = 0; row < source.height; row++)
destMatrix[col + row * source.width] = srcMatrix[srcIndex++];
}
else
{
// improper orthogonal
int srcIndex = 0;
for (int col = 0; col < source.width; col++)
for (int row = 0; row < source.height; row++)
destMatrix[col + row * source.width] = -srcMatrix[srcIndex++];
}
}
else
{
float sign;
float sign;
for (int col = 0; col < source.width; col++)
{
@ -166,11 +126,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpSafe
= (sign / det) * determinant(temp_matrix, temp_side);
// swap signs
sign = (sign == 1) ? -1.0f : 1.0f;
sign *= -1.0f;
}
}
}
dest.writeComplete();
}