summaryrefslogtreecommitdiff
path: root/src/check_rotation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/check_rotation.cpp')
-rw-r--r--src/check_rotation.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/check_rotation.cpp b/src/check_rotation.cpp
new file mode 100644
index 0000000..858bae3
--- /dev/null
+++ b/src/check_rotation.cpp
@@ -0,0 +1,45 @@
+#include <glu3.h>
+
+#include <cassert>
+#include <cmath>
+#include <cfloat>
+
+extern GLUmat4 rotate_x_axis(float theta);
+extern GLUmat4 rotate_y_axis(float theta);
+
+#define EPSILONS 2
+
+static inline bool equal(const float & a, const float & b)
+{
+ return (fabs(a - b) < EPSILONS * FLT_EPSILON);
+}
+
+static inline bool equal(const GLUvec4 & a, const GLUvec4 & b)
+{
+ return equal(a.values[0], b.values[0]) &&
+ equal(a.values[1], b.values[1]) &&
+ equal(a.values[2], b.values[2]) &&
+ equal(a.values[3], b.values[3]);
+}
+
+static inline bool equal(const GLUmat4 & a, const GLUmat4 & b)
+{
+ return equal(a.col[0], b.col[0]) &&
+ equal(a.col[1], b.col[1]) &&
+ equal(a.col[2], b.col[2]) &&
+ equal(a.col[3], b.col[3]);
+}
+
+void check_rotation(void)
+{
+ // Rotation by 0 and 2PI are equal (within 2 epsilons)
+ assert(equal(rotate_x_axis(0.0f), rotate_x_axis(2.0f * M_PI)));
+ assert(equal(rotate_y_axis(0.0f), rotate_y_axis(2.0f * M_PI)));
+ assert(equal(rotate_x_axis(M_PI) * rotate_x_axis(M_PI),
+ rotate_x_axis(0.0f)));
+ assert(equal(rotate_y_axis(M_PI) * rotate_y_axis(M_PI),
+ rotate_y_axis(0.0f)));
+
+ assert(equal(rotate_x_axis(M_PI) * rotate_y_axis(M_PI),
+ rotate_y_axis(M_PI) * rotate_x_axis(M_PI)));
+}