From a645d75861bd8db86172007be011df17d2c51fac Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Wed, 24 Oct 2012 13:09:59 -0700 Subject: Add rotate_x/y_axis functions and unit tests --- src/check_rotation.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/check_rotation.cpp (limited to 'src/check_rotation.cpp') 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 + +#include +#include +#include + +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))); +} -- cgit v1.2.3