mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #6747 from hyperlogic/tony/glmhelpers-tests
Added tests for GLMHelpers::safeEulerAngles.
This commit is contained in:
commit
65862bfd02
4 changed files with 89 additions and 5 deletions
57
tests/shared/src/GLMHelpersTests.cpp
Normal file
57
tests/shared/src/GLMHelpersTests.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// GLMHelpersTests.cpp
|
||||
// tests/shared/src
|
||||
//
|
||||
// Created by Anthony Thibault on 2015.12.29
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "GLMHelpersTests.h"
|
||||
|
||||
#include <NumericalConstants.h>
|
||||
#include <StreamUtils.h>
|
||||
|
||||
#include <../QTestExtensions.h>
|
||||
|
||||
|
||||
QTEST_MAIN(GLMHelpersTests)
|
||||
|
||||
void GLMHelpersTests::testEulerDecomposition() {
|
||||
// quat to euler and back again....
|
||||
|
||||
const glm::quat ROT_X_90 = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
const glm::quat ROT_Y_180 = glm::angleAxis(PI, glm::vec3(0.0f, 1.0, 0.0f));
|
||||
const glm::quat ROT_Z_30 = glm::angleAxis(PI / 6.0f, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
const float EPSILON = 0.00001f;
|
||||
|
||||
std::vector<glm::quat> quatVec = {
|
||||
glm::quat(),
|
||||
ROT_X_90,
|
||||
ROT_Y_180,
|
||||
ROT_Z_30,
|
||||
ROT_X_90 * ROT_Y_180 * ROT_Z_30,
|
||||
ROT_X_90 * ROT_Z_30 * ROT_Y_180,
|
||||
ROT_Y_180 * ROT_Z_30 * ROT_X_90,
|
||||
ROT_Y_180 * ROT_X_90 * ROT_Z_30,
|
||||
ROT_Z_30 * ROT_X_90 * ROT_Y_180,
|
||||
ROT_Z_30 * ROT_Y_180 * ROT_X_90,
|
||||
};
|
||||
|
||||
for (auto& q : quatVec) {
|
||||
glm::vec3 euler = safeEulerAngles(q);
|
||||
glm::quat r(euler);
|
||||
|
||||
// when the axis and angle are flipped.
|
||||
if (glm::dot(q, r) < 0.0f) {
|
||||
r = -r;
|
||||
}
|
||||
|
||||
QCOMPARE_WITH_ABS_ERROR(q, r, EPSILON);
|
||||
}
|
||||
}
|
||||
|
||||
|
27
tests/shared/src/GLMHelpersTests.h
Normal file
27
tests/shared/src/GLMHelpersTests.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// GLMHelpersTests.h
|
||||
// tests/shared/src
|
||||
//
|
||||
// Created by Anthony thibault on 2015.12.29
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_GLMHelpersTests_h
|
||||
#define hifi_GLMHelpersTests_h
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <GLMHelpers.h>
|
||||
|
||||
class GLMHelpersTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testEulerDecomposition();
|
||||
};
|
||||
|
||||
float getErrorDifference(const float& a, const float& b);
|
||||
float getErrorDifference(const glm::vec3& a, const glm::vec3& b);
|
||||
|
||||
#endif // hifi_GLMHelpersTest_h
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// GeometryUtilTests.cpp
|
||||
// tests/physics/src
|
||||
// tests/shared/src
|
||||
//
|
||||
// Created by Andrew Meadows on 2015.07.27
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// GeometryUtilTests.h
|
||||
// tests/physics/src
|
||||
// tests/shared/src
|
||||
//
|
||||
// Created by Andrew Meadows on 2014.05.30
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
|
@ -9,8 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_AngularConstraintTests_h
|
||||
#define hifi_AngularConstraintTests_h
|
||||
#ifndef hifi_GeometryUtilTests_h
|
||||
#define hifi_GeometryUtilTests_h
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <glm/glm.hpp>
|
||||
|
@ -26,4 +26,4 @@ private slots:
|
|||
float getErrorDifference(const float& a, const float& b);
|
||||
float getErrorDifference(const glm::vec3& a, const glm::vec3& b);
|
||||
|
||||
#endif // hifi_AngularConstraintTests_h
|
||||
#endif // hifi_GeometryUtilTests_h
|
||||
|
|
Loading…
Reference in a new issue