From 98766ca5ac3a444bf9a657337867ca30b89b7783 Mon Sep 17 00:00:00 2001 From: Rogerborg Date: Wed, 21 Jan 2009 15:06:21 +0000 Subject: [PATCH] https://sourceforge.net/tracker2/index.php?func=detail&aid=2526240&group_id=74339&atid=540676 Improve matrix::getScale() to return the absolute scale values when the matrix contains a rotation. This still isn't perfect, but it's an improvement. New unit test added. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2114 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/matrix4.h | 22 ++- tests/main.cpp | 16 +- tests/tests-last-passed-at.txt | 2 +- tests/tests.cbp | 1 + tests/tests_vc8.vcproj | 4 + tests/tests_vc9.vcproj | 321 ++------------------------------- 6 files changed, 47 insertions(+), 319 deletions(-) diff --git a/include/matrix4.h b/include/matrix4.h index d2feac8f..a1810063 100644 --- a/include/matrix4.h +++ b/include/matrix4.h @@ -665,10 +665,30 @@ namespace core return *this; } + //! Returns the absolute values of the scales of the matrix. + /** + Note that this always returns the absolute (positive) values. Unfortunately it + does not appear to be possible to extract any original negative values. The best + that we could do would be to arbitrarily make one scale negative if one or three + of them were negative. + FIXME - return the original values. + */ template inline vector3d CMatrix4::getScale() const { - return vector3d(M[0],M[5],M[10]); + // See http://www.robertblum.com/articles/2005/02/14/decomposing-matrices + + // Deal with the 0 rotation case first + // Prior to Irrlicht 1.6, we always returned this value. + if(core::iszero(M[1]) && core::iszero(M[2]) && + core::iszero(M[4]) && core::iszero(M[6]) && + core::iszero(M[8]) && core::iszero(M[9])) + return vector3d(M[0], M[5], M[10]); + + // We have to do the full calculation. + return vector3d(sqrtf(M[0] * M[0] + M[1] * M[1] + M[2] * M[2]), + sqrtf(M[4] * M[4] + M[5] * M[5] + M[6] * M[6]), + sqrtf(M[8] * M[8] + M[9] * M[9] + M[10] * M[10])); } template diff --git a/tests/main.cpp b/tests/main.cpp index 2763dd16..6c54c5e3 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -16,15 +16,13 @@ #include #include -// This is an MSVC pragma to link against the Irrlicht library. -// Other builds must link against it in the project files. -#if defined(_MSC_VER) -#pragma comment(lib, "Irrlicht.lib") -#endif // _MSC_VER - +//! Defines a test typedef struct _STestDefinition { + //! The test entry point function bool(*testSignature)(void); + + //! A descriptive name for the test const char * testName; } STestDefinition; @@ -52,6 +50,7 @@ int main(int argumentCount, char * arguments[]) tests.push_back(newTest);\ } + // Use an STL vector so that we don't rely on Irrlicht. std::vector tests; // Note that to interactively debug a test, you will generally want to move it @@ -88,6 +87,7 @@ int main(int argumentCount, char * arguments[]) TEST(vectorPositionDimension2d); TEST(writeImageToFile); TEST(flyCircleAnimator); + TEST(relativeTransformations); const unsigned int numberOfTests = tests.size(); @@ -128,7 +128,7 @@ int main(int argumentCount, char * arguments[]) closeTestLog(); char runNextTest[256]; (void)sprintf(runNextTest, "\"%s\" %d %d", arguments[0], testToRun, fails); - fails = system(runNextTest); + fails = system(runNextTest); // Spawn the next test in a new process. } if(1 == testToRun) @@ -154,6 +154,8 @@ int main(int argumentCount, char * arguments[]) } } closeTestLog(); + + (void)system("tests.log"); } return fails; diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 627448b6..a206eceb 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,2 +1,2 @@ -Test suite pass at GMT Wed Jan 21 08:35:20 2009 +Test suite pass at GMT Wed Jan 21 14:53:52 2009 diff --git a/tests/tests.cbp b/tests/tests.cbp index b0fbe233..86d6f85a 100644 --- a/tests/tests.cbp +++ b/tests/tests.cbp @@ -55,6 +55,7 @@ + diff --git a/tests/tests_vc8.vcproj b/tests/tests_vc8.vcproj index 73c7ccc8..23a2eb18 100644 --- a/tests/tests_vc8.vcproj +++ b/tests/tests_vc8.vcproj @@ -241,6 +241,10 @@ RelativePath=".\planeMatrix.cpp" > + + diff --git a/tests/tests_vc9.vcproj b/tests/tests_vc9.vcproj index 6864e157..d821f242 100644 --- a/tests/tests_vc9.vcproj +++ b/tests/tests_vc9.vcproj @@ -1,310 +1,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + +