Welcome to mirror list, hosted at ThFree Co, Russian Federation.

abc_matrix_test.cc « alembic « gtests « tests - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbdcd467de9f4a3f47c5b8f1f4ffc86a0f95110f (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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "testing/testing.h"

// Keep first since utildefines defines AT which conflicts with fucking STL
#include "intern/abc_util.h"

extern "C" {
#include "BLI_utildefines.h"
#include "BLI_math.h"
}


#define EXPECT_M3_NEAR(a, b, eps) {\
	EXPECT_V3_NEAR(a[0], b[0], eps); \
	EXPECT_V3_NEAR(a[1], b[1], eps); \
	EXPECT_V3_NEAR(a[2], b[2], eps); \
}

TEST(abc_matrix, CreateRotationMatrixY_YfromZ) {
	// Input variables
	float rot_x_mat[3][3];
	float rot_y_mat[3][3];
	float rot_z_mat[3][3];
	float euler[3] = {0.f, M_PI_4, 0.f};

	// Construct expected matrices
	float unit[3][3];
	float rot_z_min_quart_pi[3][3];  // rotation of -pi/4 radians over z-axis

	unit_m3(unit);
	unit_m3(rot_z_min_quart_pi);
	rot_z_min_quart_pi[0][0] = M_SQRT1_2;
	rot_z_min_quart_pi[0][1] = -M_SQRT1_2;
	rot_z_min_quart_pi[1][0] = M_SQRT1_2;
	rot_z_min_quart_pi[1][1] = M_SQRT1_2;

	// Run tests
	create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
	                               ABC_YUP_FROM_ZUP);

	EXPECT_M3_NEAR(rot_x_mat, unit, 1e-5f);
	EXPECT_M3_NEAR(rot_y_mat, unit, 1e-5f);
	EXPECT_M3_NEAR(rot_z_mat, rot_z_min_quart_pi, 1e-5f);
}

TEST(abc_matrix, CreateRotationMatrixZ_YfromZ) {
	// Input variables
	float rot_x_mat[3][3];
	float rot_y_mat[3][3];
	float rot_z_mat[3][3];
	float euler[3] = {0.f, 0.f, M_PI_4};

	// Construct expected matrices
	float unit[3][3];
	float rot_y_quart_pi[3][3];  // rotation of pi/4 radians over y-axis

	unit_m3(unit);
	unit_m3(rot_y_quart_pi);
	rot_y_quart_pi[0][0] = M_SQRT1_2;
	rot_y_quart_pi[0][2] = -M_SQRT1_2;
	rot_y_quart_pi[2][0] = M_SQRT1_2;
	rot_y_quart_pi[2][2] = M_SQRT1_2;

	// Run tests
	create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
	                               ABC_YUP_FROM_ZUP);

	EXPECT_M3_NEAR(rot_x_mat, unit, 1e-5f);
	EXPECT_M3_NEAR(rot_y_mat, rot_y_quart_pi, 1e-5f);
	EXPECT_M3_NEAR(rot_z_mat, unit, 1e-5f);
}

TEST(abc_matrix, CreateRotationMatrixXYZ_YfromZ) {
	// Input variables
	float rot_x_mat[3][3];
	float rot_y_mat[3][3];
	float rot_z_mat[3][3];
	// in degrees: X=10, Y=20, Z=30
	float euler[3] = {0.1745329201221466f, 0.3490658104419708f, 0.5235987901687622f};

	// Construct expected matrices
	float rot_x_p10[3][3];  // rotation of +10 degrees over x-axis
	float rot_y_p30[3][3];  // rotation of +30 degrees over y-axis
	float rot_z_m20[3][3];  // rotation of -20 degrees over z-axis

	unit_m3(rot_x_p10);
	rot_x_p10[1][1] =  0.9848077297210693f;
	rot_x_p10[1][2] =  0.1736481785774231f;
	rot_x_p10[2][1] = -0.1736481785774231f;
	rot_x_p10[2][2] =  0.9848077297210693f;

	unit_m3(rot_y_p30);
	rot_y_p30[0][0] =  0.8660253882408142f;
	rot_y_p30[0][2] = -0.5f;
	rot_y_p30[2][0] =  0.5f;
	rot_y_p30[2][2] =  0.8660253882408142f;

	unit_m3(rot_z_m20);
	rot_z_m20[0][0] =  0.9396926164627075f;
	rot_z_m20[0][1] = -0.3420201241970062f;
	rot_z_m20[1][0] =  0.3420201241970062f;
	rot_z_m20[1][1] =  0.9396926164627075f;

	// Run tests
	create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
	                               ABC_YUP_FROM_ZUP);

	EXPECT_M3_NEAR(rot_x_mat, rot_x_p10, 1e-5f);
	EXPECT_M3_NEAR(rot_y_mat, rot_y_p30, 1e-5f);
	EXPECT_M3_NEAR(rot_z_mat, rot_z_m20, 1e-5f);
}

TEST(abc_matrix, CreateRotationMatrixXYZ_ZfromY) {
	// Input variables
	float rot_x_mat[3][3];
	float rot_y_mat[3][3];
	float rot_z_mat[3][3];
	// in degrees: X=10, Y=20, Z=30
	float euler[3] = {0.1745329201221466f, 0.3490658104419708f, 0.5235987901687622f};

	// Construct expected matrices
	float rot_x_p10[3][3];  // rotation of +10 degrees over x-axis
	float rot_y_m30[3][3];  // rotation of -30 degrees over y-axis
	float rot_z_p20[3][3];  // rotation of +20 degrees over z-axis

	unit_m3(rot_x_p10);
	rot_x_p10[1][1] =  0.9848077297210693f;
	rot_x_p10[1][2] =  0.1736481785774231f;
	rot_x_p10[2][1] = -0.1736481785774231f;
	rot_x_p10[2][2] =  0.9848077297210693f;

	unit_m3(rot_y_m30);
	rot_y_m30[0][0] =  0.8660253882408142f;
	rot_y_m30[0][2] =  0.5f;
	rot_y_m30[2][0] = -0.5f;
	rot_y_m30[2][2] =  0.8660253882408142f;

	unit_m3(rot_z_p20);
	rot_z_p20[0][0] =  0.9396926164627075f;
	rot_z_p20[0][1] =  0.3420201241970062f;
	rot_z_p20[1][0] = -0.3420201241970062f;
	rot_z_p20[1][1] =  0.9396926164627075f;

	// Run tests
	create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler,
	                               ABC_ZUP_FROM_YUP);

	EXPECT_M3_NEAR(rot_x_mat, rot_x_p10, 1e-5f);
	EXPECT_M3_NEAR(rot_y_mat, rot_y_m30, 1e-5f);
	EXPECT_M3_NEAR(rot_z_mat, rot_z_p20, 1e-5f);
}