0ad/source/maths/tests/test_Matrix3d.h
Ykkrosh 173c56140c # Fixed skeletal animation algorithm.
* Skinning is done in a way that works when there's more than one bone
influencing a vertex.
 * PMDs now store vertexes in world-space instead of bind-space. (The
loader converts the old-version PMDs so they still work.)
 * Moved SkinPoint, SkinNormal into CModelDef so it could use them when
loading the old PMDs.
 * Made the FastNormals approach non-optional, so the inverse-transpose
bone matrices could be removed. Changed the explanation of why it's a
valid approach.
 * Quaternion: Made GetInverse assume that the quaternions have unit
length (which they do when they're representing 3D rotations).
 * lib: Added support for DDS files that aren't a multiple of 4x4 (most
useful for 1x1, 2x2, etc that are still powers of two).
 * Actor Viewer: Added white terrain texture to the minimal test mod, so
shadows are visible. Changed default so walk/run animations don't move
the unit along the ground.
 * Removed some redundant repetition in doc comments.
 * Removed some unnecessary #includes.

This was SVN commit r4696.
2006-12-15 16:09:30 +00:00

68 lines
1.5 KiB
C++

#include "lib/self_test.h"
#include <cstdlib>
#include <cmath>
#include "lib/lib.h"
#include "maths/Matrix3D.h"
#include "maths/Quaternion.h"
class TestMatrix : public CxxTest::TestSuite
{
public:
void test_inverse()
{
CMatrix3D m;
srand(0);
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 16; ++j)
{
m._data[j] = -1.0f + 2.0f*(rand()/(float)RAND_MAX);
}
CMatrix3D n;
m.GetInverse(n);
m *= n;
// verify identity has 1s on diagonal and 0 otherwise
for (int x = 0; x < 4; ++x)
{
for (int y = 0; y < 4; ++y)
{
const float expected = (x==y)? 1.0f : 0.0f;
TS_ASSERT_DELTA(m(x,y), expected, 0.0001f);
}
}
}
}
void test_quats()
{
srand(0);
for (int i = 0; i < 4; ++i)
{
CQuaternion q;
q.FromEulerAngles(
-6.28f + 12.56f*(rand()/(float)RAND_MAX),
-6.28f + 12.56f*(rand()/(float)RAND_MAX),
-6.28f + 12.56f*(rand()/(float)RAND_MAX)
);
CMatrix3D m;
q.ToMatrix(m);
CQuaternion q2 = m.GetRotation();
// Quaternions (x,y,z,w) and (-x,-y,-z,-w) are equivalent when
// interpreted as rotations, so it doesn't matter which we get
const bool ok_oneway =
feq(q2.m_W, q.m_W) &&
feq(q2.m_V.X, q.m_V.X) &&
feq(q2.m_V.Y, q.m_V.Y) &&
feq(q2.m_V.Z, q.m_V.Z);
const bool ok_otherway =
feq(q2.m_W, -q.m_W) &&
feq(q2.m_V.X, -q.m_V.X) &&
feq(q2.m_V.Y, -q.m_V.Y) &&
feq(q2.m_V.Z, -q.m_V.Z);
TS_ASSERT(ok_oneway ^ ok_otherway);
}
}
};