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
master
Rogerborg 2009-01-21 15:06:21 +00:00
parent 0e147df2e0
commit 98766ca5ac
6 changed files with 47 additions and 319 deletions

View File

@ -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 <class T>
inline vector3d<T> CMatrix4<T>::getScale() const
{
return vector3d<T>(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<T>(M[0], M[5], M[10]);
// We have to do the full calculation.
return vector3d<T>(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 <class T>

View File

@ -16,15 +16,13 @@
#include <assert.h>
#include <vector>
// 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<STestDefinition> 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;

View File

@ -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

View File

@ -55,6 +55,7 @@
<Unit filename="matrixOps.cpp" />
<Unit filename="md2Animation.cpp" />
<Unit filename="planeMatrix.cpp" />
<Unit filename="relativeTransformations.cpp" />
<Unit filename="sceneCollisionManager.cpp" />
<Unit filename="sceneNodeAnimator.cpp" />
<Unit filename="softwareDevice.cpp" />

View File

@ -241,6 +241,10 @@
RelativePath=".\planeMatrix.cpp"
>
</File>
<File
RelativePath=".\relativeTransformations.cpp"
>
</File>
<File
RelativePath=".\sceneCollisionManager.cpp"
>

View File

@ -1,310 +1,11 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="tests"
ProjectGUID="{2A1DE18B-F678-4A94-A996-E848E20B2983}"
RootNamespace="tests"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\lib\Win32-visualstudio\Irrlicht.lib"
OutputFile="..\bin\Win32-VisualStudio\$(ProjectName).exe"
GenerateDebugInformation="true"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\include"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="..\lib\Win32-visualstudio\Irrlicht.lib"
OutputFile="..\bin\Win32-VisualStudio\$(ProjectName).exe"
GenerateDebugInformation="true"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\b3dAnimation.cpp"
>
</File>
<File
RelativePath=".\burningsVideo.cpp"
>
</File>
<File
RelativePath=".\collisionResponseAnimator.cpp"
>
</File>
<File
RelativePath=".\cursorSetVisible.cpp"
>
</File>
<File
RelativePath=".\disambiguateTextures.cpp"
>
</File>
<File
RelativePath=".\drawPixel.cpp"
>
</File>
<File
RelativePath=".\drawRectOutline.cpp"
>
</File>
<File
RelativePath=".\exports.cpp"
>
</File>
<File
RelativePath=".\fast_atof.cpp"
>
</File>
<File
RelativePath=".\flyCircleAnimator.cpp"
>
</File>
<File
RelativePath=".\guiDisabledMenu.cpp"
>
</File>
<File
RelativePath=".\irrCoreEquals.cpp"
>
</File>
<File
RelativePath=".\line2dIntersectWith.cpp"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\makeColorKeyTexture.cpp"
>
</File>
<File
RelativePath=".\matrixOps.cpp"
>
</File>
<File
RelativePath=".\md2Animation.cpp"
>
</File>
<File
RelativePath=".\planeMatrix.cpp"
>
</File>
<File
RelativePath=".\sceneCollisionManager.cpp"
>
</File>
<File
RelativePath=".\sceneNodeAnimator.cpp"
>
</File>
<File
RelativePath=".\softwareDevice.cpp"
>
</File>
<File
RelativePath=".\terrainSceneNode.cpp"
>
</File>
<File
RelativePath=".\testDimension2d.cpp"
>
</File>
<File
RelativePath=".\testUtils.cpp"
>
</File>
<File
RelativePath=".\testVector2d.cpp"
>
</File>
<File
RelativePath=".\testVector3d.cpp"
>
</File>
<File
RelativePath=".\textureRenderStates.cpp"
>
</File>
<File
RelativePath=".\transparentAlphaChannelRef.cpp"
>
</File>
<File
RelativePath=".\vectorPositionDimension2d.cpp"
>
</File>
<File
RelativePath=".\writeImageToFile.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\testUtils.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="tests"
ProjectGUID="{2A1DE18B-F678-4A94-A996-E848E20B2983}"
RootNamespace="tests"
TargetFrameworkVersion="196613"
>
<xi:include href="tests_vc_all.xml"/>
</VisualStudioProject>