mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 04:42:20 +02:00
add unit tests and fix final bugs
This commit is contained in:
parent
506f522802
commit
205e5d7309
3 changed files with 78 additions and 4 deletions
|
@ -538,12 +538,11 @@ void generateBasisVectors(const glm::vec3& primaryAxis, const glm::vec3& seconda
|
|||
uAxisOut = glm::normalize(primaryAxis);
|
||||
glm::vec3 normSecondary = glm::normalize(secondaryAxis);
|
||||
|
||||
// if secondaryAxis is parallel with the primaryAxis, pick another axis.
|
||||
// if normSecondary is parallel with the primaryAxis, pick another secondary.
|
||||
const float EPSILON = 1.0e-4f;
|
||||
if (fabsf(fabsf(glm::dot(uAxisOut, secondaryAxis)) - 1.0f) < EPSILON) {
|
||||
// pick a better secondaryAxis.
|
||||
if (fabsf(fabsf(glm::dot(uAxisOut, normSecondary)) - 1.0f) < EPSILON) {
|
||||
normSecondary = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
if (fabsf(fabsf(glm::dot(uAxisOut, secondaryAxis)) - 1.0f) < EPSILON) {
|
||||
if (fabsf(fabsf(glm::dot(uAxisOut, normSecondary)) - 1.0f) < EPSILON) {
|
||||
normSecondary = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,3 +140,77 @@ void GLMHelpersTests::testSimd() {
|
|||
}
|
||||
qDebug() << "Done ";
|
||||
}
|
||||
|
||||
void GLMHelpersTests::testGenerateBasisVectors() {
|
||||
{ // very simple case: primary along X, secondary is linear combination of X and Y
|
||||
glm::vec3 u(1.0f, 0.0f, 0.0f);
|
||||
glm::vec3 v(1.0f, 1.0f, 0.0f);
|
||||
glm::vec3 w;
|
||||
|
||||
generateBasisVectors(u, v, u, v, w);
|
||||
|
||||
QCOMPARE_WITH_ABS_ERROR(u, Vectors::UNIT_X, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(v, Vectors::UNIT_Y, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(w, Vectors::UNIT_Z, EPSILON);
|
||||
}
|
||||
|
||||
{ // point primary along Y instead of X
|
||||
glm::vec3 u(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 v(1.0f, 1.0f, 0.0f);
|
||||
glm::vec3 w;
|
||||
|
||||
generateBasisVectors(u, v, u, v, w);
|
||||
|
||||
QCOMPARE_WITH_ABS_ERROR(u, Vectors::UNIT_Y, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(v, Vectors::UNIT_X, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(w, -Vectors::UNIT_Z, EPSILON);
|
||||
}
|
||||
|
||||
{ // pass bad data (both vectors along Y). The helper will guess X for secondary.
|
||||
glm::vec3 u(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 v(0.0f, 1.0f, 0.0f);
|
||||
glm::vec3 w;
|
||||
|
||||
generateBasisVectors(u, v, u, v, w);
|
||||
|
||||
QCOMPARE_WITH_ABS_ERROR(u, Vectors::UNIT_Y, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(v, Vectors::UNIT_X, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(w, -Vectors::UNIT_Z, EPSILON);
|
||||
}
|
||||
|
||||
{ // pass bad data (both vectors along X). The helper will guess X for secondary, fail, then guess Y.
|
||||
glm::vec3 u(1.0f, 0.0f, 0.0f);
|
||||
glm::vec3 v(1.0f, 0.0f, 0.0f);
|
||||
glm::vec3 w;
|
||||
|
||||
generateBasisVectors(u, v, u, v, w);
|
||||
|
||||
QCOMPARE_WITH_ABS_ERROR(u, Vectors::UNIT_X, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(v, Vectors::UNIT_Y, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(w, Vectors::UNIT_Z, EPSILON);
|
||||
}
|
||||
|
||||
{ // general case for arbitrary rotation
|
||||
float angle = 1.234f;
|
||||
glm::vec3 axis = glm::normalize(glm::vec3(1.0f, 2.0f, 3.0f));
|
||||
glm::quat rotation = glm::angleAxis(angle, axis);
|
||||
|
||||
// expected values
|
||||
glm::vec3 x = rotation * Vectors::UNIT_X;
|
||||
glm::vec3 y = rotation * Vectors::UNIT_Y;
|
||||
glm::vec3 z = rotation * Vectors::UNIT_Z;
|
||||
|
||||
// primary is along x
|
||||
// secondary is linear combination of x and y
|
||||
// tertiary is unknown
|
||||
glm::vec3 u = 1.23f * x;
|
||||
glm::vec3 v = 2.34f * x + 3.45f * y;
|
||||
glm::vec3 w;
|
||||
|
||||
generateBasisVectors(u, v, u, v, w);
|
||||
|
||||
QCOMPARE_WITH_ABS_ERROR(u, x, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(v, y, EPSILON);
|
||||
QCOMPARE_WITH_ABS_ERROR(w, z, EPSILON);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ private slots:
|
|||
void testEulerDecomposition();
|
||||
void testSixByteOrientationCompression();
|
||||
void testSimd();
|
||||
void testGenerateBasisVectors();
|
||||
};
|
||||
|
||||
float getErrorDifference(const float& a, const float& b);
|
||||
|
|
Loading…
Reference in a new issue