Merge pull request #1297 from marauder2k9-torque/matrix-templated

Template Matrix class
This commit is contained in:
Brian Roberts 2024-11-07 16:17:38 -06:00 committed by GitHub
commit 1be326e0d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 2523 additions and 99 deletions

View file

@ -52,8 +52,12 @@ enum GameConnectionConstants
class IDisplayDevice;
class SFXProfile;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class Point3F;
class MoveManager;
class MoveList;

View file

@ -28,7 +28,12 @@
#endif
class Point3F;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class PlaneF;
@ -84,4 +89,4 @@ public:
const MatrixF &localXfm ) = 0;
};
#endif // _T3D_PHYSICS_PHYSICSCOLLISION_H_
#endif // _T3D_PHYSICS_PHYSICSCOLLISION_H_

View file

@ -34,7 +34,12 @@
#endif
class PhysicsWorld;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class Point3F;
class Box3F;
@ -88,4 +93,4 @@ protected:
U32 mQueuedEvent;
};
#endif // _T3D_PHYSICS_PHYSICSOBJECT_H_
#endif // _T3D_PHYSICS_PHYSICSOBJECT_H_

View file

@ -35,7 +35,12 @@ class RectI;
class RectF;
class Box3I;
class Box3F;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class AngAxisF;
class QuatF;
class String;

View file

@ -45,7 +45,12 @@
//
class Point3F;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class HuffmanProcessor;
class BitVector;
class QuatF;

View file

@ -60,7 +60,12 @@
class Point2I;
class Point2F;
class LinearColorF;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class GFXShader;
class GFXVertexFormat;

View file

@ -27,7 +27,13 @@
#include "math/mPoint3.h"
#endif
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class QuatF;
//----------------------------------------------------------------------------

View file

@ -36,7 +36,12 @@
#endif
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class SphereF;

View file

@ -29,6 +29,8 @@
#include "console/enginePrimitives.h"
#include "console/engineTypes.h"
#ifndef USE_TEMPLATE_MATRIX
const MatrixF MatrixF::Identity( true );
// idx(i,j) is index to element in column i, row j
@ -209,3 +211,12 @@ EngineFieldTable::Field MatrixFEngineExport::getMatrixField()
typedef MatrixF ThisType;
return _FIELD_AS(F32, m, m, 16, "");
}
#else // !USE_TEMPLATE_MATRIX
//------------------------------------
// Templatized matrix class to replace MATRIXF above
// due to templated class, all functions need to be inline
//------------------------------------
#endif // !USE_TEMPLATE_MATRIX

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,12 @@
#endif
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class Box3F;

View file

@ -27,7 +27,12 @@
#include "math/mPoint3.h"
#endif
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class AngAxisF;
//----------------------------------------------------------------------------

View file

@ -101,6 +101,7 @@ IMPLEMENT_STRUCT( RectF,
FIELD( extent, extent, 1, "The width and height of the Rect.")
END_IMPLEMENT_STRUCT;
#ifndef USE_TEMPLATE_MATRIX
IMPLEMENT_STRUCT( MatrixF,
MatrixF, MathTypes,
"" )
@ -108,6 +109,15 @@ IMPLEMENT_STRUCT( MatrixF,
MatrixFEngineExport::getMatrixField(),
END_IMPLEMENT_STRUCT;
#else
IMPLEMENT_STRUCT(MatrixF,
MatrixF, MathTypes,
"")
MatrixTemplateExport::getMatrixField<F32, 4, 4>(),
END_IMPLEMENT_STRUCT;
#endif
IMPLEMENT_STRUCT( AngAxisF,
AngAxisF, MathTypes,
"" )

View file

@ -38,7 +38,12 @@ class Point3F;
class Point4F;
class RectI;
class RectF;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class Box3F;
class EaseF;
class AngAxisF;

View file

@ -1,93 +0,0 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2014 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef TORQUE_TESTS_ENABLED
#include "testing/unitTesting.h"
#include "platform/platform.h"
#include "math/mMatrix.h"
#include "math/mRandom.h"
extern void default_matF_x_matF_C(const F32 *a, const F32 *b, F32 *mresult);
extern void mInstallLibrary_ASM();
// If we're x86 and not Mac, then include these. There's probably a better way to do this.
#if defined(WIN32) && defined(TORQUE_CPU_X86)
void Athlon_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
void SSE_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
#endif
#if defined( __VEC__ )
extern void vec_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
#endif
TEST(MatrixF, MultiplyImplmentations)
{
F32 m1[16], m2[16], mrC[16];
// I am not positive that the best way to do this is to use random numbers
// but I think that using some kind of standard matrix may not always catch
// all problems.
for (S32 i = 0; i < 16; i++)
{
m1[i] = gRandGen.randF();
m2[i] = gRandGen.randF();
}
// C will be the baseline
default_matF_x_matF_C(m1, m2, mrC);
#if defined(WIN32) && defined(TORQUE_CPU_X86)
// Check the CPU info
U32 cpuProperties = Platform::SystemInfo.processor.properties;
bool same;
// Test SSE if it is available
F32 mrSSE[16];
if (cpuProperties & CPU_PROP_SSE)
{
SSE_MatrixF_x_MatrixF(m1, m2, mrSSE);
same = true;
for (S32 i = 0; i < 16; i++)
same &= mIsEqual(mrC[i], mrSSE[i]);
EXPECT_TRUE(same) << "Matrix multiplication verification failed. (C vs. SSE)";
}
same = true;
#endif
// If Altivec exists, test it!
#if defined(__VEC__)
bool same = false;
F32 mrVEC[16];
vec_MatrixF_x_MatrixF(m1, m2, mrVEC);
for (S32 i = 0; i < 16; i++)
same &= isEqual(mrC[i], mrVEC[i]);
EXPECT_TRUE(same) << "Matrix multiplication verification failed. (C vs. Altivec)";
#endif
}
#endif

View file

@ -22,7 +22,7 @@
#ifndef _MATRIXSETDELEGATES_H_
#define _MATRIXSETDELEGATES_H_
// Access to the direct value
#ifndef USE_TEMPLATE_MATRIX
#define MATRIX_SET_GET_VALUE_FN(xfm) _transform_##xfm
#define MATRIX_SET_GET_VALUE(xfm) inline const MatrixF &MATRIX_SET_GET_VALUE_FN(xfm)() { return mTransform[xfm]; }
#define MATRIX_SET_BIND_VALUE(xfm) mEvalDelegate[xfm].bind(this, &MatrixSet::MATRIX_SET_GET_VALUE_FN(xfm))
@ -44,5 +44,28 @@
return mTransform[matC]; \
}
#else
// Access to the direct value
#define MATRIX_SET_GET_VALUE_FN(xfm) _transform_##xfm
#define MATRIX_SET_GET_VALUE(xfm) inline const MatrixF &MATRIX_SET_GET_VALUE_FN(xfm)() { return mTransform[xfm]; }
#define MATRIX_SET_BIND_VALUE(xfm) mEvalDelegate[xfm].bind(this, &MatrixSet::MATRIX_SET_GET_VALUE_FN(xfm))
#define MATRIX_SET_IS_INVERSE_OF_FN(inv_xfm, src_xfm) _##inv_xfm##_is_inverse_of_##src_xfm
#define MATRIX_SET_IS_INVERSE_OF(inv_xfm, src_xfm) inline const MatrixF &MATRIX_SET_IS_INVERSE_OF_FN(inv_xfm, src_xfm)() \
{ \
mEvalDelegate[src_xfm]().invertTo(&mTransform[inv_xfm]); \
MATRIX_SET_BIND_VALUE(inv_xfm); \
return mTransform[inv_xfm]; \
}
#define MATRIX_SET_MULT_ASSIGN_FN(matA, matB, matC) _##matC##_is_##matA##_x_##matB
#define MATRIX_SET_MULT_ASSIGN(matA, matB, matC) inline const MatrixF &MATRIX_SET_MULT_ASSIGN_FN(matA, matB, matC)() \
{ \
mTransform[matC].mul(mEvalDelegate[matA](),mEvalDelegate[matB]()); \
MATRIX_SET_BIND_VALUE(matC); \
return mTransform[matC]; \
}
#endif
#endif // _MATRIXSETDELEGATES_H_

View file

@ -32,7 +32,12 @@
class Frustum;
class RectI;
#ifndef USE_TEMPLATE_MATRIX
class MatrixF;
#else
template<typename DATA_TYPE, U32 rows, U32 cols> class Matrix;
typedef Matrix<F32, 4, 4> MatrixF;
#endif
class PlaneF;
struct SGWinding

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,7 @@
/// What's the name of your application? Used in a variety of places.
#define TORQUE_APP_NAME "@TORQUE_APP_NAME@"
#cmakedefine USE_TEMPLATE_MATRIX
/// What version of the application specific source code is this?
///
/// Version number is major * 1000 + minor * 100 + revision * 10.

View file

@ -74,7 +74,7 @@ advanced_option(TORQUE_TOOLS "Enable or disable the tools" ON)
advanced_option(TORQUE_TOOLS_EXT_COMMANDS "Enable or disable some extended functionality like shell commands or free write access" OFF)
advanced_option(TORQUE_ENABLE_PROFILER "Enable or disable the profiler" OFF)
advanced_option(TORQUE_SHOW_LEGACY_FILE_FIELDS "If on, shows legacy direct file path fields in the inspector." OFF)
advanced_option(USE_TEMPLATE_MATRIX "Set to true to use the new templated matrix class(still in beta)." OFF)
#testing
advanced_option(TORQUE_TESTING "Unit test build" OFF)