This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compressQuat_test.cpp
118 lines (92 loc) · 4.13 KB
/
compressQuat_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Created by Game on 2017/11/11.
//
#include <cmath>
#include <vector>
#include <string>
#include "compressQuat.h"
#include "gtest/gtest.h"
const float mPi = 3.1415926535897932384626433832795f;
TEST(compressQuat, InitQuat) {
cqQuaternion q{};
cq_identity(&q);
}
TEST(compressQuat, Euler2Quaternion) {
size_t test_size = 720;
for (size_t x = 0; x < test_size;) {
float x_rad = x * (mPi / 180);
x += 2;
for (int y = 0; y < test_size;) {
float y_rad = y * (mPi / 180);
y += 2;
for (int z = 0; z < test_size;) {
float z_rad = z * (mPi / 180);
z += 2;
cqQuaternion test_quat1 {0,0,0,0};
cqQuaternion test_quat2 {0,0,0,0};
cqFloat3 euler1 { x_rad, y_rad, z_rad };
cqFloat3 euler2 { 0, 0, 0 };
cq_fromEuler(&euler1, &test_quat1);
cq_toEuler(&test_quat1, &euler2);
cq_fromEuler(&euler2, &test_quat2);
auto check = cq_compare(&test_quat1, &test_quat2, 0.5f) == cqTRUE;
const float diff_w = test_quat1.x * test_quat2.x +
test_quat1.y * test_quat1.y +
test_quat1.z * test_quat1.z +
test_quat1.w * test_quat1.w;
// Converts w back to an angle.
const float angle = 2.f * acosf(fminf(fabsf(diff_w), 1.f));
EXPECT_TRUE(check) << std::string("angle : ") + std::to_string(angle);
}
}
}
}
TEST(compressQuat, QuaternionCompress) {
size_t test_size = 720;
for (size_t x = 0; x < test_size;) {
float x_rad = x * (mPi / 180);
x += 2;
for (int y = 0; y < test_size;) {
float y_rad = y * (mPi / 180);
y += 2;
for (int z = 0; z < test_size;) {
float z_rad = z * (mPi / 180);
z += 2;
cqQuaternion test_quat {0,0,0,0};
cqFloat3 euler { x_rad, y_rad, z_rad };
cq_fromEuler(&euler, &test_quat);
CompressQuat cquat {};
compress_pack(&test_quat, &cquat);
cqQuaternion unquat {};
cqQuaternion unquatN {};
cq_identity(&unquat);
cq_identity(&unquatN);
uncompress_pack(&cquat, &unquat);
uncompress_packN(&cquat, &unquatN);
auto check = cq_compare(&unquat, &test_quat, 2.0f) == cqTRUE &&
cq_compare(&unquatN, &test_quat, 2.5f) == cqTRUE;
const float diff_w = test_quat.x * unquat.x +
test_quat.y * unquat.y +
test_quat.z * unquat.z +
test_quat.w * unquat.w;
const float normalize_diff_w = test_quat.x * unquatN.x +
test_quat.y * unquatN.y +
test_quat.z * unquatN.z +
test_quat.w * unquatN.w;
// Converts w back to an angle.
const float angle = 2.f * acosf(fminf(fabsf(diff_w), 1.f));
const float normalize_angle = 2.f * acosf(fminf(fabsf(normalize_diff_w), 1.f));
EXPECT_TRUE(check) << " Compress Quat : x= " + std::to_string(test_quat.x) +
" y= " + std::to_string(test_quat.y) +
" z= " + std::to_string(test_quat.z) +
" w= " + std::to_string(test_quat.w) +
" Uncompress Quat : x= "+ std::to_string(unquat.x) +
" y= " + std::to_string(unquat.y) +
" z= " + std::to_string(unquat.z) +
" w= " + std::to_string(unquat.w) +
" angle= " + std::to_string(angle) +
" angle(normalize)= " + std::to_string(normalize_angle);
}
}
}
}