summaryrefslogtreecommitdiff
path: root/src/check_rotation.cpp
blob: 858bae38da0d9993ac38a01ac3c99d6a01203ccc (plain)
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
#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)));
}