12 #ifndef hifi_GLMTestUtils_h
13 #define hifi_GLMTestUtils_h
15 #include <glm/glm.hpp>
16 #include <glm/gtx/quaternion.hpp>
17 #include <QTextStream>
22 float getErrorDifference(
const glm::quat& a,
const glm::quat& b) {
23 return fabsf(glm::dot(a, b)) - 1.0f;
26 inline float getErrorDifference(
const glm::vec3& a,
const glm::vec3& b) {
27 return glm::distance(a, b);
30 inline float getErrorDifference(
const glm::mat4& a,
const glm::mat4& b) {
32 for (
int i = 0; i < 4; ++i) {
33 for (
int j = 0; j < 4; ++j) {
34 float diff = fabs(a[i][j] - b[i][j]);
35 maxDiff = std::max(diff, maxDiff);
41 inline QTextStream& operator<<(QTextStream& stream,
const glm::vec3& v) {
42 return stream <<
"glm::vec3 { " << v.x <<
", " << v.y <<
", " << v.z <<
" }";
45 QTextStream& operator<<(QTextStream& stream,
const glm::quat& q) {
46 return stream <<
"glm::quat { " << q.x <<
", " << q.y <<
", " << q.z <<
", " << q.w <<
" }";
49 inline QTextStream& operator<< (QTextStream& stream,
const glm::mat4& matrix) {
51 stream.setFieldWidth(15);
52 for (
int r = 0; r < 4; ++r) {
53 for (
int c = 0; c < 4; ++c) {
54 stream << matrix[c][r];
58 stream.setFieldWidth(0);
63 #define QCOMPARE_QUATS(rotationA, rotationB, angle) \
64 QVERIFY(fabsf(1.0f - fabsf(glm::dot(rotationA, rotationB))) < 2.0f * sinf(angle))