1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // matrix_utils_unittests:
7 // Unit tests for the matrix utils.
8 //
9
10 #include "matrix_utils.h"
11
12 #include <gtest/gtest.h>
13
14 using namespace angle;
15
16 namespace
17 {
18
19 struct RotateArgs
20 {
21 float angle;
22 Vector3 axis;
23 };
24
25 struct TranslateArgs
26 {
27 float x;
28 float y;
29 float z;
30 };
31
32 struct ScaleArgs
33 {
34 float x;
35 float y;
36 float z;
37 };
38
39 struct FrustumArgs
40 {
41 float l;
42 float r;
43 float b;
44 float t;
45 float n;
46 float f;
47 };
48
CheckMat4ExactlyEq(const Mat4 & a,const Mat4 & b)49 void CheckMat4ExactlyEq(const Mat4 &a, const Mat4 &b)
50 {
51 for (unsigned int i = 0; i < 4; i++)
52 {
53 for (unsigned int j = 0; i < 4; i++)
54 {
55 EXPECT_EQ(a.at(i, j), b.at(i, j));
56 }
57 }
58 }
59
60 // TODO(lfy): Spec out requirements for matrix precision
CheckMatrixCloseToGolden(float * golden,const Mat4 & m)61 void CheckMatrixCloseToGolden(float *golden, const Mat4 &m)
62 {
63 const float floatFaultTolarance = 0.000001f;
64 const auto &checkElts = m.elements();
65 for (size_t i = 0; i < checkElts.size(); i++)
66 {
67 EXPECT_NEAR(golden[i], checkElts[i], floatFaultTolarance);
68 }
69 }
70
CheckMatrixCloseToGolden(const std::vector<float> & golden,const Mat4 & m)71 void CheckMatrixCloseToGolden(const std::vector<float> &golden, const Mat4 &m)
72 {
73 const float floatFaultTolarance = 0.000001f;
74 const auto &checkElts = m.elements();
75 for (size_t i = 0; i < golden.size(); i++)
76 {
77 EXPECT_NEAR(golden[i], checkElts[i], floatFaultTolarance);
78 }
79 }
80 } // namespace
81
82 namespace
83 {
84
85 const unsigned int minDimensions = 2;
86 const unsigned int maxDimensions = 4;
87
TEST(MatrixUtilsTest,MatrixConstructorTest)88 TEST(MatrixUtilsTest, MatrixConstructorTest)
89 {
90 for (unsigned int i = minDimensions; i <= maxDimensions; i++)
91 {
92 for (unsigned int j = minDimensions; j <= maxDimensions; j++)
93 {
94 unsigned int numElements = i * j;
95 Matrix<float> m(std::vector<float>(numElements, 1.0f), i, j);
96 EXPECT_EQ(m.rows(), i);
97 EXPECT_EQ(m.columns(), j);
98 EXPECT_EQ(m.elements(), std::vector<float>(numElements, 1.0f));
99 }
100 }
101
102 for (unsigned int i = minDimensions; i <= maxDimensions; i++)
103 {
104 unsigned int numElements = i * i;
105 Matrix<float> m(std::vector<float>(numElements, 1.0f), i);
106 EXPECT_EQ(m.size(), i);
107 EXPECT_EQ(m.columns(), m.columns());
108 EXPECT_EQ(m.elements(), std::vector<float>(numElements, 1.0f));
109 }
110 }
111
TEST(MatrixUtilsTest,MatrixCompMultTest)112 TEST(MatrixUtilsTest, MatrixCompMultTest)
113 {
114 for (unsigned int i = minDimensions; i <= maxDimensions; i++)
115 {
116 unsigned int numElements = i * i;
117 Matrix<float> m1(std::vector<float>(numElements, 2.0f), i);
118 Matrix<float> actualResult = m1.compMult(m1);
119 std::vector<float> actualResultElements = actualResult.elements();
120 std::vector<float> expectedResultElements(numElements, 4.0f);
121 EXPECT_EQ(expectedResultElements, actualResultElements);
122 }
123 }
124
TEST(MatrixUtilsTest,MatrixOuterProductTest)125 TEST(MatrixUtilsTest, MatrixOuterProductTest)
126 {
127 for (unsigned int i = minDimensions; i <= maxDimensions; i++)
128 {
129 for (unsigned int j = minDimensions; j <= maxDimensions; j++)
130 {
131 unsigned int numElements = i * j;
132 Matrix<float> m1(std::vector<float>(numElements, 2.0f), i, 1);
133 Matrix<float> m2(std::vector<float>(numElements, 2.0f), 1, j);
134 Matrix<float> actualResult = m1.outerProduct(m2);
135 EXPECT_EQ(actualResult.rows(), i);
136 EXPECT_EQ(actualResult.columns(), j);
137 std::vector<float> actualResultElements = actualResult.elements();
138 std::vector<float> expectedResultElements(numElements, 4.0f);
139 EXPECT_EQ(expectedResultElements, actualResultElements);
140 }
141 }
142 }
143
TEST(MatrixUtilsTest,MatrixTransposeTest)144 TEST(MatrixUtilsTest, MatrixTransposeTest)
145 {
146 for (unsigned int i = minDimensions; i <= maxDimensions; i++)
147 {
148 for (unsigned int j = minDimensions; j <= maxDimensions; j++)
149 {
150 unsigned int numElements = i * j;
151 Matrix<float> m1(std::vector<float>(numElements, 2.0f), i, j);
152 Matrix<float> expectedResult =
153 Matrix<float>(std::vector<float>(numElements, 2.0f), j, i);
154 Matrix<float> actualResult = m1.transpose();
155 EXPECT_EQ(expectedResult.elements(), actualResult.elements());
156 EXPECT_EQ(actualResult.rows(), expectedResult.rows());
157 EXPECT_EQ(actualResult.columns(), expectedResult.columns());
158 // transpose(transpose(A)) = A
159 Matrix<float> m2 = actualResult.transpose();
160 EXPECT_EQ(m1.elements(), m2.elements());
161 }
162 }
163 }
164
TEST(MatrixUtilsTest,MatrixDeterminantTest)165 TEST(MatrixUtilsTest, MatrixDeterminantTest)
166 {
167 for (unsigned int i = minDimensions; i <= maxDimensions; i++)
168 {
169 unsigned int numElements = i * i;
170 Matrix<float> m(std::vector<float>(numElements, 2.0f), i);
171 EXPECT_EQ(m.determinant(), 0.0f);
172 }
173 }
174
175 TEST(MatrixUtilsTest, 2x2MatrixInverseTest)
176 {
177 float inputElements[] = {2.0f, 5.0f, 3.0f, 7.0f};
178 unsigned int numElements = 4;
179 std::vector<float> input(inputElements, inputElements + numElements);
180 Matrix<float> inputMatrix(input, 2);
181 float identityElements[] = {1.0f, 0.0f, 0.0f, 1.0f};
182 std::vector<float> identityMatrix(identityElements, identityElements + numElements);
183 // A * inverse(A) = I, where I is identity matrix.
184 Matrix<float> result = inputMatrix * inputMatrix.inverse();
185 EXPECT_EQ(identityMatrix, result.elements());
186 }
187
188 TEST(MatrixUtilsTest, 3x3MatrixInverseTest)
189 {
190 float inputElements[] = {11.0f, 23.0f, 37.0f, 13.0f, 29.0f, 41.0f, 19.0f, 31.0f, 43.0f};
191 unsigned int numElements = 9;
192 std::vector<float> input(inputElements, inputElements + numElements);
193 Matrix<float> inputMatrix(input, 3);
194 float identityElements[] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
195 std::vector<float> identityMatrix(identityElements, identityElements + numElements);
196 // A * inverse(A) = I, where I is identity matrix.
197 Matrix<float> result = inputMatrix * inputMatrix.inverse();
198 std::vector<float> resultElements = result.elements();
199 const float floatFaultTolarance = 0.000001f;
200 for (size_t i = 0; i < numElements; i++)
201 EXPECT_NEAR(resultElements[i], identityMatrix[i], floatFaultTolarance);
202 }
203
204 TEST(MatrixUtilsTest, 4x4MatrixInverseTest)
205 {
206 float inputElements[] = {29.0f, 43.0f, 61.0f, 79.0f, 31.0f, 47.0f, 67.0f, 83.0f,
207 37.0f, 53.0f, 71.0f, 89.0f, 41.0f, 59.0f, 73.0f, 97.0f};
208 unsigned int numElements = 16;
209 std::vector<float> input(inputElements, inputElements + numElements);
210 Matrix<float> inputMatrix(input, 4);
211 float identityElements[] = {
212 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
213 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
214 };
215 std::vector<float> identityMatrix(identityElements, identityElements + numElements);
216 // A * inverse(A) = I, where I is identity matrix.
217 Matrix<float> result = inputMatrix * inputMatrix.inverse();
218 std::vector<float> resultElements = result.elements();
219 const float floatFaultTolarance = 0.00001f;
220 for (unsigned int i = 0; i < numElements; i++)
221 EXPECT_NEAR(resultElements[i], identityMatrix[i], floatFaultTolarance);
222 }
223
224 // Tests constructors for mat4; using raw float*, std::vector<float>,
225 // and Matrix<float>.
TEST(MatrixUtilsTest,Mat4Construction)226 TEST(MatrixUtilsTest, Mat4Construction)
227 {
228 float elements[] = {
229 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f,
230 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f,
231 };
232
233 std::vector<float> elementsVector(16, 0);
234 for (int i = 0; i < 16; i++)
235 {
236 elementsVector[i] = elements[i];
237 }
238
239 Matrix<float> a(elements, 4);
240 Mat4 b(elements);
241 Mat4 bVec(elementsVector);
242
243 CheckMat4ExactlyEq(a, b);
244 CheckMat4ExactlyEq(b, bVec);
245
246 a.setToIdentity();
247 b = Mat4();
248
249 CheckMat4ExactlyEq(a, b);
250
251 Mat4 c(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f,
252 14.0f, 15.0f);
253 Mat4 d(elements);
254 Mat4 e(Matrix<float>(elements, 4));
255
256 CheckMat4ExactlyEq(c, d);
257 CheckMat4ExactlyEq(e, d);
258 }
259
260 // Tests rotation matrices.
TEST(MatrixUtilsTest,Mat4Rotate)261 TEST(MatrixUtilsTest, Mat4Rotate)
262 {
263 // Confidence check.
264 float elementsExpected[] = {
265 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
266 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
267 };
268
269 std::vector<float> elementsExpectedVector(16, 0);
270 for (int i = 0; i < 16; i++)
271 {
272 elementsExpectedVector[i] = elementsExpected[i];
273 }
274
275 Mat4 r = Mat4::Rotate(0.f, Vector3(0.f, 0.f, 1.f));
276 Mat4 golden(elementsExpected);
277 CheckMatrixCloseToGolden(elementsExpected, r);
278 CheckMatrixCloseToGolden(elementsExpectedVector, r);
279 CheckMat4ExactlyEq(r, golden);
280
281 // Randomly-generated inputs, outputs using GLM.
282 std::vector<RotateArgs> rotationGoldenInputs;
283 std::vector<std::vector<float>> rotationGoldenOutputs;
284 rotationGoldenInputs.push_back(
285 {-123.2026214599609375f,
286 Vector3(1.4951171875000000f, 8.4370708465576172f, 1.8489227294921875f)});
287 rotationGoldenInputs.push_back(
288 {-185.3049316406250000f,
289 Vector3(8.3313980102539062f, 5.8317651748657227f, -5.5201716423034668f)});
290 rotationGoldenInputs.push_back(
291 {89.1301574707031250f,
292 Vector3(-8.5962724685668945f, 2.4547367095947266f, -3.2461600303649902f)});
293 rotationGoldenInputs.push_back(
294 {64.2547302246093750f,
295 Vector3(-1.9640445709228516f, -9.6942234039306641f, 9.1921043395996094f)});
296 rotationGoldenInputs.push_back(
297 {-298.5585021972656250f,
298 Vector3(-5.3600544929504395f, -6.4333534240722656f, -5.3734750747680664f)});
299 rotationGoldenInputs.push_back(
300 {288.2606201171875000f,
301 Vector3(-2.3043875694274902f, -9.8447618484497070f, -0.9124794006347656f)});
302 rotationGoldenInputs.push_back(
303 {142.3956298828125000f,
304 Vector3(-1.0044975280761719f, -2.5834980010986328f, -0.8451175689697266f)});
305 rotationGoldenInputs.push_back(
306 {-140.0445861816406250f,
307 Vector3(-1.3710060119628906f, -2.5042991638183594f, -9.7572088241577148f)});
308 rotationGoldenInputs.push_back(
309 {-338.5443420410156250f,
310 Vector3(6.8056621551513672f, 2.7508878707885742f, -5.8343429565429688f)});
311 rotationGoldenInputs.push_back(
312 {79.0578613281250000f,
313 Vector3(9.0518493652343750f, -5.5615901947021484f, 6.3559799194335938f)});
314 rotationGoldenInputs.push_back(
315 {4464.6367187500000000f,
316 Vector3(-53.9424285888671875f, -10.3614959716796875f, 54.3564453125000000f)});
317 rotationGoldenInputs.push_back(
318 {-2820.6347656250000000f,
319 Vector3(62.1694793701171875f, 82.4977569580078125f, -60.0084800720214844f)});
320 rotationGoldenInputs.push_back(
321 {3371.0527343750000000f,
322 Vector3(-74.5660324096679688f, -31.3026275634765625f, 96.7252349853515625f)});
323 rotationGoldenInputs.push_back(
324 {5501.7167968750000000f,
325 Vector3(15.0308380126953125f, 23.2323913574218750f, 66.8295593261718750f)});
326 rotationGoldenInputs.push_back(
327 {392.1757812500000000f,
328 Vector3(36.5722198486328125f, 69.2820892333984375f, 24.1789474487304688f)});
329 rotationGoldenInputs.push_back(
330 {-2206.7138671875000000f,
331 Vector3(-91.5292282104492188f, 68.2716674804687500f, 42.0627288818359375f)});
332 rotationGoldenInputs.push_back(
333 {-4648.8623046875000000f,
334 Vector3(50.7790374755859375f, 43.3964080810546875f, -36.3877525329589844f)});
335 rotationGoldenInputs.push_back(
336 {2794.6015625000000000f,
337 Vector3(76.2934265136718750f, 63.4901885986328125f, 79.5993041992187500f)});
338 rotationGoldenInputs.push_back(
339 {2294.6787109375000000f,
340 Vector3(-81.3662338256835938f, 77.6944580078125000f, 10.8423461914062500f)});
341 rotationGoldenInputs.push_back(
342 {2451.0468750000000000f,
343 Vector3(-80.6299896240234375f, 51.8244628906250000f, 13.6877517700195312f)});
344 rotationGoldenOutputs.push_back({
345 -0.5025786161422729f,
346 0.0775775760412216f,
347 0.8610438108444214f,
348 0.0000000000000000f,
349 0.4305581450462341f,
350 0.8861245512962341f,
351 0.1714731603860855f,
352 0.0000000000000000f,
353 -0.7496895790100098f,
354 0.4569081664085388f,
355 -0.4787489175796509f,
356 0.0000000000000000f,
357 0.0000000000000000f,
358 0.0000000000000000f,
359 0.0000000000000000f,
360 1.0000000000000000f,
361 });
362 rotationGoldenOutputs.push_back({
363 0.0388860106468201f,
364 0.6800884604454041f,
365 -0.7320981621742249f,
366 0.0000000000000000f,
367 0.7683026194572449f,
368 -0.4887983798980713f,
369 -0.4132642149925232f,
370 0.0000000000000000f,
371 -0.6389046907424927f,
372 -0.5464027523994446f,
373 -0.5415209531784058f,
374 -0.0000000000000000f,
375 0.0000000000000000f,
376 0.0000000000000000f,
377 0.0000000000000000f,
378 1.0000000000000000f,
379 });
380 rotationGoldenOutputs.push_back({
381 0.8196773529052734f,
382 -0.5709969997406006f,
383 0.0457325875759125f,
384 0.0000000000000000f,
385 0.1115358471870422f,
386 0.0807825028896332f,
387 -0.9904716014862061f,
388 0.0000000000000000f,
389 0.5618618726730347f,
390 0.8169679641723633f,
391 0.1299021989107132f,
392 0.0000000000000000f,
393 0.0000000000000000f,
394 0.0000000000000000f,
395 0.0000000000000000f,
396 1.0000000000000000f,
397 });
398 rotationGoldenOutputs.push_back({
399 0.4463376104831696f,
400 0.6722379326820374f,
401 0.5906597971916199f,
402 0.0000000000000000f,
403 -0.5541059374809265f,
404 0.7259115576744080f,
405 -0.4074544310569763f,
406 0.0000000000000000f,
407 -0.7026730179786682f,
408 -0.1454258561134338f,
409 0.6964926123619080f,
410 0.0000000000000000f,
411 0.0000000000000000f,
412 0.0000000000000000f,
413 0.0000000000000000f,
414 1.0000000000000000f,
415 });
416 rotationGoldenOutputs.push_back({
417 0.6295375227928162f,
418 -0.2925493717193604f,
419 0.7197898030281067f,
420 0.0000000000000000f,
421 0.6561784744262695f,
422 0.6962769031524658f,
423 -0.2909094095230103f,
424 0.0000000000000000f,
425 -0.4160676598548889f,
426 0.6554489731788635f,
427 0.6302970647811890f,
428 0.0000000000000000f,
429 0.0000000000000000f,
430 0.0000000000000000f,
431 0.0000000000000000f,
432 1.0000000000000000f,
433 });
434 rotationGoldenOutputs.push_back({
435 0.3487194776535034f,
436 0.2365041077136993f,
437 -0.9068960547447205f,
438 0.0000000000000000f,
439 0.0657925531268120f,
440 0.9590729475021362f,
441 0.2754095196723938f,
442 0.0000000000000000f,
443 0.9349150061607361f,
444 -0.1557076722383499f,
445 0.3188872337341309f,
446 0.0000000000000000f,
447 0.0000000000000000f,
448 0.0000000000000000f,
449 0.0000000000000000f,
450 1.0000000000000000f,
451 });
452 rotationGoldenOutputs.push_back({
453 -0.5768983364105225f,
454 0.3758956193923950f,
455 0.7251832485198975f,
456 0.0000000000000000f,
457 0.7318079471588135f,
458 0.6322251558303833f,
459 0.2544573545455933f,
460 0.0000000000000000f,
461 -0.3628296852111816f,
462 0.6774909496307373f,
463 -0.6398130059242249f,
464 0.0000000000000000f,
465 0.0000000000000000f,
466 0.0000000000000000f,
467 0.0000000000000000f,
468 1.0000000000000000f,
469 });
470 rotationGoldenOutputs.push_back({
471 -0.7344170808792114f,
472 0.6750319004058838f,
473 0.0704519301652908f,
474 0.0000000000000000f,
475 -0.5576634407043457f,
476 -0.6593509316444397f,
477 0.5042498111724854f,
478 0.0000000000000000f,
479 0.3868372440338135f,
480 0.3310411870479584f,
481 0.8606789708137512f,
482 0.0000000000000000f,
483 0.0000000000000000f,
484 0.0000000000000000f,
485 0.0000000000000000f,
486 1.0000000000000000f,
487 });
488 rotationGoldenOutputs.push_back({
489 0.9672066569328308f,
490 -0.2128375321626663f,
491 -0.1386056393384933f,
492 0.0000000000000000f,
493 0.2423491925001144f,
494 0.9366652965545654f,
495 0.2528339624404907f,
496 0.0000000000000000f,
497 0.0760145336389542f,
498 -0.2781336307525635f,
499 0.9575299024581909f,
500 0.0000000000000000f,
501 0.0000000000000000f,
502 0.0000000000000000f,
503 0.0000000000000000f,
504 1.0000000000000000f,
505 });
506 rotationGoldenOutputs.push_back({
507 0.6229416728019714f,
508 0.2379529774188995f,
509 0.7451993227005005f,
510 0.0000000000000000f,
511 -0.7701886892318726f,
512 0.3533243536949158f,
513 0.5310096740722656f,
514 0.0000000000000000f,
515 -0.1369417309761047f,
516 -0.9047321081161499f,
517 0.4033691287040710f,
518 0.0000000000000000f,
519 0.0000000000000000f,
520 0.0000000000000000f,
521 0.0000000000000000f,
522 1.0000000000000000f,
523 });
524 rotationGoldenOutputs.push_back({
525 0.0691163539886475f,
526 0.5770183801651001f,
527 -0.8138013482093811f,
528 0.0000000000000000f,
529 -0.2371776401996613f,
530 -0.7828579545021057f,
531 -0.5752218365669250f,
532 -0.0000000000000000f,
533 -0.9690044522285461f,
534 0.2327727228403091f,
535 0.0827475786209106f,
536 0.0000000000000000f,
537 0.0000000000000000f,
538 0.0000000000000000f,
539 0.0000000000000000f,
540 1.0000000000000000f,
541 });
542 rotationGoldenOutputs.push_back({
543 0.6423799991607666f,
544 -0.2559574246406555f,
545 -0.7223805189132690f,
546 0.0000000000000000f,
547 0.6084498763084412f,
548 0.7434381246566772f,
549 0.2776480317115784f,
550 0.0000000000000000f,
551 0.4659791886806488f,
552 -0.6178879141807556f,
553 0.6333070397377014f,
554 0.0000000000000000f,
555 0.0000000000000000f,
556 0.0000000000000000f,
557 0.0000000000000000f,
558 1.0000000000000000f,
559 });
560 rotationGoldenOutputs.push_back({
561 -0.0772442221641541f,
562 0.8218145370483398f,
563 -0.5644945502281189f,
564 0.0000000000000000f,
565 -0.3352625370025635f,
566 -0.5546256303787231f,
567 -0.7615703344345093f,
568 -0.0000000000000000f,
569 -0.9389528036117554f,
570 0.1304270327091217f,
571 0.3183652758598328f,
572 0.0000000000000000f,
573 0.0000000000000000f,
574 0.0000000000000000f,
575 0.0000000000000000f,
576 1.0000000000000000f,
577 });
578 rotationGoldenOutputs.push_back({
579 -0.1511210501194000f,
580 0.9849811196327209f,
581 -0.0835132896900177f,
582 0.0000000000000000f,
583 -0.8243820667266846f,
584 -0.0789582207798958f,
585 0.5604994893074036f,
586 0.0000000000000000f,
587 0.5454874038696289f,
588 0.1535501033067703f,
589 0.8239331245422363f,
590 0.0000000000000000f,
591 0.0000000000000000f,
592 0.0000000000000000f,
593 0.0000000000000000f,
594 1.0000000000000000f,
595 });
596 rotationGoldenOutputs.push_back({
597 0.8769769668579102f,
598 0.2149325907230377f,
599 -0.4297852218151093f,
600 0.0000000000000000f,
601 -0.0991527736186981f,
602 0.9560844898223877f,
603 0.2758098840713501f,
604 0.0000000000000000f,
605 0.4701915681362152f,
606 -0.1992645263671875f,
607 0.8597752451896667f,
608 0.0000000000000000f,
609 0.0000000000000000f,
610 0.0000000000000000f,
611 0.0000000000000000f,
612 1.0000000000000000f,
613 });
614 rotationGoldenOutputs.push_back({
615 0.8634905815124512f,
616 -0.3842780590057373f,
617 0.3266716897487640f,
618 0.0000000000000000f,
619 0.1189628839492798f,
620 0.7845909595489502f,
621 0.6084939241409302f,
622 0.0000000000000000f,
623 -0.4901345074176788f,
624 -0.4865669906139374f,
625 0.7232017517089844f,
626 0.0000000000000000f,
627 0.0000000000000000f,
628 0.0000000000000000f,
629 0.0000000000000000f,
630 1.0000000000000000f,
631 });
632 rotationGoldenOutputs.push_back({
633 0.9201348423957825f,
634 -0.1924955844879150f,
635 -0.3410238325595856f,
636 0.0000000000000000f,
637 0.3022402822971344f,
638 0.9028221964836121f,
639 0.3058805167675018f,
640 0.0000000000000000f,
641 0.2490032464265823f,
642 -0.3845224678516388f,
643 0.8888981342315674f,
644 0.0000000000000000f,
645 0.0000000000000000f,
646 0.0000000000000000f,
647 0.0000000000000000f,
648 1.0000000000000000f,
649 });
650 rotationGoldenOutputs.push_back({
651 0.4109522104263306f,
652 -0.3483857214450836f,
653 0.8424642086029053f,
654 0.0000000000000000f,
655 0.8988372087478638f,
656 0.3092637956142426f,
657 -0.3105604350566864f,
658 0.0000000000000000f,
659 -0.1523487865924835f,
660 0.8848635554313660f,
661 0.4402346611022949f,
662 0.0000000000000000f,
663 0.0000000000000000f,
664 0.0000000000000000f,
665 0.0000000000000000f,
666 1.0000000000000000f,
667 });
668 rotationGoldenOutputs.push_back({
669 0.1795312762260437f,
670 -0.7746179103851318f,
671 -0.6064119935035706f,
672 0.0000000000000000f,
673 -0.9110413789749146f,
674 0.1016657948493958f,
675 -0.3995841145515442f,
676 0.0000000000000000f,
677 0.3711764216423035f,
678 0.6242043375968933f,
679 -0.6874569058418274f,
680 0.0000000000000000f,
681 0.0000000000000000f,
682 0.0000000000000000f,
683 0.0000000000000000f,
684 1.0000000000000000f,
685 });
686 rotationGoldenOutputs.push_back({
687 0.8035809993743896f,
688 -0.4176068902015686f,
689 0.4241013824939728f,
690 0.0000000000000000f,
691 -0.1537265181541443f,
692 0.5427432060241699f,
693 0.8257105946540833f,
694 0.0000000000000000f,
695 -0.5750005841255188f,
696 -0.7287209630012512f,
697 0.3719408810138702f,
698 0.0000000000000000f,
699 0.0000000000000000f,
700 0.0000000000000000f,
701 0.0000000000000000f,
702 1.0000000000000000f,
703 });
704 EXPECT_EQ(rotationGoldenInputs.size(), rotationGoldenOutputs.size());
705
706 for (size_t i = 0; i < rotationGoldenInputs.size(); i++)
707 {
708 const auto &input = rotationGoldenInputs[i];
709 const auto &output = rotationGoldenOutputs[i];
710 Mat4 rot = Mat4::Rotate(input.angle, input.axis);
711 CheckMatrixCloseToGolden(output, rot);
712 }
713 }
714
715 // Tests mat4 translation.
TEST(MatrixUtilsTest,Mat4Translate)716 TEST(MatrixUtilsTest, Mat4Translate)
717 {
718 float elementsExpected[] = {
719 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
720 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
721 };
722
723 std::vector<float> elementsExpectedVector(16, 0);
724 for (int i = 0; i < 16; i++)
725 {
726 elementsExpectedVector[i] = elementsExpected[i];
727 }
728
729 Mat4 r = Mat4::Translate(Vector3(0.f, 0.f, 0.f));
730 Mat4 golden(elementsExpected);
731 CheckMatrixCloseToGolden(elementsExpected, r);
732 CheckMatrixCloseToGolden(elementsExpectedVector, r);
733 CheckMat4ExactlyEq(r, golden);
734
735 float elementsExpected1[] = {
736 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
737 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
738 };
739
740 float elementsExpected2[] = {
741 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
742 0.0f, 0.0f, 1.0f, 0.0f, 2.0f, 2.0f, 2.0f, 1.0f,
743 };
744
745 Mat4 golden1(elementsExpected1);
746 Mat4 golden2(elementsExpected2);
747
748 Mat4 t1 = Mat4::Translate(Vector3(1.f, 1.f, 1.f));
749 Mat4 t2 = Mat4::Translate(Vector3(2.f, 2.f, 2.f));
750 Mat4 t1t1 = t1.product(t1);
751
752 CheckMat4ExactlyEq(t1, golden1);
753 CheckMat4ExactlyEq(t2, golden2);
754 CheckMat4ExactlyEq(t1t1, golden2);
755 }
756
757 // Tests scale for mat4.
TEST(MatrixUtilsTest,Mat4Scale)758 TEST(MatrixUtilsTest, Mat4Scale)
759 {
760
761 // Confidence check.
762 float elementsExpected[] = {
763 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
764 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
765 };
766
767 std::vector<float> elementsExpectedVector(16, 0);
768 for (int i = 0; i < 16; i++)
769 {
770 elementsExpectedVector[i] = elementsExpected[i];
771 }
772
773 Mat4 r = Mat4::Scale(Vector3(1.f, 1.f, 1.f));
774 Mat4 golden(elementsExpected);
775 CheckMatrixCloseToGolden(elementsExpected, r);
776 CheckMatrixCloseToGolden(elementsExpectedVector, r);
777 CheckMat4ExactlyEq(r, golden);
778
779 float elementsExpected2[] = {
780 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, 0.0f,
781 0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
782 };
783
784 float elementsExpected4[] = {
785 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f,
786 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
787 };
788
789 Mat4 golden2(elementsExpected2);
790 Mat4 golden4(elementsExpected4);
791
792 Mat4 t2 = Mat4::Scale(Vector3(2.f, 2.f, 2.f));
793 Mat4 t2t2 = t2.product(t2);
794
795 CheckMat4ExactlyEq(t2, golden2);
796 CheckMat4ExactlyEq(t2t2, golden4);
797 }
798
799 // Tests frustum matrices.
TEST(MatrixUtilsTest,Mat4Frustum)800 TEST(MatrixUtilsTest, Mat4Frustum)
801 {
802 // Randomly-generated inputs, outputs using GLM.
803 std::vector<FrustumArgs> frustumGoldenInputs;
804 std::vector<std::vector<float>> frustumGoldenOutputs;
805
806 EXPECT_EQ(frustumGoldenInputs.size(), frustumGoldenOutputs.size());
807
808 frustumGoldenInputs.push_back({6.5640869140625000f, 2.6196002960205078f, 7.6299438476562500f,
809 -3.5341463088989258f, 1.5971517562866211f, 3.3254327774047852f});
810 frustumGoldenInputs.push_back({-9.4570913314819336f, -5.3334407806396484f, 0.8660326004028320f,
811 -4.5830192565917969f, -6.7980914115905762f,
812 4.4744148254394531f});
813 frustumGoldenInputs.push_back({1.4876422882080078f, 2.8094434738159180f, -1.6803054809570312f,
814 -0.8823823928833008f, 9.7977848052978516f,
815 -8.6204166412353516f});
816 frustumGoldenInputs.push_back({-3.3456401824951172f, 9.8235015869140625f, 3.5869121551513672f,
817 5.2356719970703125f, -4.0609388351440430f, 7.7973194122314453f});
818 frustumGoldenInputs.push_back({9.5381393432617188f, 7.5244369506835938f, 3.2054557800292969f,
819 -5.9051651954650879f, -8.1114397048950195f,
820 -8.9626598358154297f});
821 frustumGoldenInputs.push_back({4.5731735229492188f, 1.3278274536132812f, -3.2062773704528809f,
822 -7.9090023040771484f, -6.6076564788818359f,
823 5.1205596923828125f});
824 frustumGoldenInputs.push_back({1.2519702911376953f, 1.8767604827880859f, 2.7256736755371094f,
825 -9.6021852493286133f, -3.9267930984497070f,
826 2.3794260025024414f});
827 frustumGoldenInputs.push_back({-8.9887380599975586f, 6.2763042449951172f, 5.8243169784545898f,
828 9.2890701293945312f, 1.3859443664550781f, -6.4422101974487305f});
829 frustumGoldenInputs.push_back({5.7714862823486328f, 1.3688507080078125f, 6.2611656188964844f,
830 -8.5859031677246094f, -3.2825427055358887f,
831 -9.7015857696533203f});
832 frustumGoldenInputs.push_back({5.4493808746337891f, 7.7383766174316406f, -1.1092796325683594f,
833 -3.6691951751708984f, -8.1641988754272461f,
834 4.3122081756591797f});
835 frustumGoldenInputs.push_back({-47.3135452270507812f, 1.1683349609375000f, 36.1483764648437500f,
836 -54.2228546142578125f, 76.4831085205078125f,
837 51.5773468017578125f});
838 frustumGoldenInputs.push_back({60.6750030517578125f, -35.2967681884765625f,
839 -32.8269577026367188f, 77.3887939453125000f,
840 73.3114624023437500f, -54.2619438171386719f});
841 frustumGoldenInputs.push_back({19.5157546997070312f, 1.3348083496093750f, 34.2350463867187500f,
842 -11.5907974243164062f, -6.4835968017578125f,
843 30.2026824951171875f});
844 frustumGoldenInputs.push_back({16.5014953613281250f, -59.4170761108398438f,
845 -22.8201065063476562f, 62.5094299316406250f,
846 -3.9552688598632812f, -76.2280197143554688f});
847 frustumGoldenInputs.push_back({35.6607666015625000f, -49.5569000244140625f,
848 97.1632690429687500f, 23.1938247680664062f, 18.6621780395507812f,
849 55.2039489746093750f});
850 frustumGoldenInputs.push_back({12.7565383911132812f, -0.8035964965820312f, 94.0040435791015625f,
851 -73.9960327148437500f, -51.3727264404296875f,
852 -21.3958053588867188f});
853 frustumGoldenInputs.push_back({0.6055984497070312f, -21.7872161865234375f, 22.3246612548828125f,
854 10.5279464721679688f, -56.8082237243652344f,
855 24.1726150512695312f});
856 frustumGoldenInputs.push_back({69.2176513671875000f, -59.0015220642089844f,
857 -38.5509605407714844f, 74.0315246582031250f,
858 47.9032897949218750f, -89.4692459106445312f});
859 frustumGoldenInputs.push_back({90.4153137207031250f, 10.0325012207031250f, 16.1712417602539062f,
860 -9.9705123901367188f, 25.6828689575195312f,
861 51.8659057617187500f});
862 frustumGoldenInputs.push_back({-89.5869369506835938f, -87.6541290283203125f,
863 -3.0015182495117188f, -46.5026855468750000f,
864 29.3566131591796875f, -3.5230865478515625f});
865 frustumGoldenOutputs.push_back({
866 -0.8098147511482239f,
867 0.0000000000000000f,
868 0.0000000000000000f,
869 0.0000000000000000f,
870 0.0000000000000000f,
871 -0.2861230373382568f,
872 0.0000000000000000f,
873 0.0000000000000000f,
874 -2.3282337188720703f,
875 -0.3668724894523621f,
876 -2.8482546806335449f,
877 -1.0000000000000000f,
878 0.0000000000000000f,
879 0.0000000000000000f,
880 -6.1462464332580566f,
881 0.0000000000000000f,
882 });
883 frustumGoldenOutputs.push_back({
884 -3.2971229553222656f,
885 0.0000000000000000f,
886 0.0000000000000000f,
887 0.0000000000000000f,
888 0.0000000000000000f,
889 2.4951465129852295f,
890 0.0000000000000000f,
891 0.0000000000000000f,
892 -3.5867569446563721f,
893 0.6821345686912537f,
894 0.2061366289854050f,
895 -1.0000000000000000f,
896 0.0000000000000000f,
897 0.0000000000000000f,
898 5.3967552185058594f,
899 0.0000000000000000f,
900 });
901 frustumGoldenOutputs.push_back({
902 14.8248996734619141f,
903 0.0000000000000000f,
904 0.0000000000000000f,
905 0.0000000000000000f,
906 0.0000000000000000f,
907 24.5582180023193359f,
908 0.0000000000000000f,
909 0.0000000000000000f,
910 3.2509319782257080f,
911 -3.2116978168487549f,
912 0.0639241635799408f,
913 -1.0000000000000000f,
914 0.0000000000000000f,
915 0.0000000000000000f,
916 -9.1714696884155273f,
917 0.0000000000000000f,
918 });
919 frustumGoldenOutputs.push_back({
920 -0.6167355179786682f,
921 0.0000000000000000f,
922 0.0000000000000000f,
923 0.0000000000000000f,
924 0.0000000000000000f,
925 -4.9260525703430176f,
926 0.0000000000000000f,
927 0.0000000000000000f,
928 0.4918970167636871f,
929 5.3510427474975586f,
930 -0.3150867819786072f,
931 -1.0000000000000000f,
932 0.0000000000000000f,
933 0.0000000000000000f,
934 5.3404870033264160f,
935 0.0000000000000000f,
936 });
937 frustumGoldenOutputs.push_back({
938 8.0562448501586914f,
939 0.0000000000000000f,
940 0.0000000000000000f,
941 0.0000000000000000f,
942 0.0000000000000000f,
943 1.7806558609008789f,
944 0.0000000000000000f,
945 0.0000000000000000f,
946 -8.4732360839843750f,
947 0.2963255345821381f,
948 -20.0583839416503906f,
949 -1.0000000000000000f,
950 0.0000000000000000f,
951 0.0000000000000000f,
952 170.8137969970703125f,
953 0.0000000000000000f,
954 });
955 frustumGoldenOutputs.push_back({
956 4.0720810890197754f,
957 0.0000000000000000f,
958 0.0000000000000000f,
959 0.0000000000000000f,
960 0.0000000000000000f,
961 2.8101394176483154f,
962 0.0000000000000000f,
963 0.0000000000000000f,
964 -1.8182963132858276f,
965 2.3635828495025635f,
966 0.1267964988946915f,
967 -1.0000000000000000f,
968 0.0000000000000000f,
969 0.0000000000000000f,
970 5.7698287963867188f,
971 0.0000000000000000f,
972 });
973 frustumGoldenOutputs.push_back({
974 -12.5699577331542969f,
975 0.0000000000000000f,
976 0.0000000000000000f,
977 0.0000000000000000f,
978 0.0000000000000000f,
979 0.6370600461959839f,
980 0.0000000000000000f,
981 0.0000000000000000f,
982 5.0076503753662109f,
983 0.5578025579452515f,
984 0.2453716099262238f,
985 -1.0000000000000000f,
986 0.0000000000000000f,
987 0.0000000000000000f,
988 2.9632694721221924f,
989 0.0000000000000000f,
990 });
991 frustumGoldenOutputs.push_back({
992 0.1815840899944305f,
993 0.0000000000000000f,
994 0.0000000000000000f,
995 0.0000000000000000f,
996 0.0000000000000000f,
997 0.8000248670578003f,
998 0.0000000000000000f,
999 0.0000000000000000f,
1000 -0.1776892393827438f,
1001 4.3620386123657227f,
1002 -0.6459077596664429f,
1003 -1.0000000000000000f,
1004 0.0000000000000000f,
1005 0.0000000000000000f,
1006 -2.2811365127563477f,
1007 0.0000000000000000f,
1008 });
1009 frustumGoldenOutputs.push_back({
1010 1.4911717176437378f,
1011 0.0000000000000000f,
1012 0.0000000000000000f,
1013 0.0000000000000000f,
1014 0.0000000000000000f,
1015 0.4421805739402771f,
1016 0.0000000000000000f,
1017 0.0000000000000000f,
1018 -1.6218323707580566f,
1019 0.1565788835287094f,
1020 -2.0227515697479248f,
1021 -1.0000000000000000f,
1022 0.0000000000000000f,
1023 0.0000000000000000f,
1024 9.9223108291625977f,
1025 0.0000000000000000f,
1026 });
1027 frustumGoldenOutputs.push_back({
1028 -7.1334328651428223f,
1029 0.0000000000000000f,
1030 0.0000000000000000f,
1031 0.0000000000000000f,
1032 0.0000000000000000f,
1033 6.3784909248352051f,
1034 0.0000000000000000f,
1035 0.0000000000000000f,
1036 5.7613725662231445f,
1037 1.8666533231735229f,
1038 0.3087419867515564f,
1039 -1.0000000000000000f,
1040 0.0000000000000000f,
1041 0.0000000000000000f,
1042 5.6435680389404297f,
1043 0.0000000000000000f,
1044 });
1045 frustumGoldenOutputs.push_back({
1046 3.1551213264465332f,
1047 0.0000000000000000f,
1048 0.0000000000000000f,
1049 0.0000000000000000f,
1050 0.0000000000000000f,
1051 -1.6926428079605103f,
1052 0.0000000000000000f,
1053 0.0000000000000000f,
1054 -0.9518032073974609f,
1055 0.2000025659799576f,
1056 5.1418004035949707f,
1057 -1.0000000000000000f,
1058 0.0000000000000000f,
1059 0.0000000000000000f,
1060 316.7777709960937500f,
1061 0.0000000000000000f,
1062 });
1063 frustumGoldenOutputs.push_back({
1064 -1.5277713537216187f,
1065 0.0000000000000000f,
1066 0.0000000000000000f,
1067 0.0000000000000000f,
1068 0.0000000000000000f,
1069 1.3303264379501343f,
1070 0.0000000000000000f,
1071 0.0000000000000000f,
1072 -0.2644343674182892f,
1073 0.4043145775794983f,
1074 0.1493220180273056f,
1075 -1.0000000000000000f,
1076 0.0000000000000000f,
1077 0.0000000000000000f,
1078 -62.3644447326660156f,
1079 0.0000000000000000f,
1080 });
1081 frustumGoldenOutputs.push_back({
1082 0.7132298350334167f,
1083 0.0000000000000000f,
1084 0.0000000000000000f,
1085 0.0000000000000000f,
1086 0.0000000000000000f,
1087 0.2829668223857880f,
1088 0.0000000000000000f,
1089 0.0000000000000000f,
1090 -1.1468359231948853f,
1091 -0.4941370785236359f,
1092 -0.6465383172035217f,
1093 -1.0000000000000000f,
1094 0.0000000000000000f,
1095 0.0000000000000000f,
1096 10.6754913330078125f,
1097 0.0000000000000000f,
1098 });
1099 frustumGoldenOutputs.push_back({
1100 0.1041976660490036f,
1101 0.0000000000000000f,
1102 0.0000000000000000f,
1103 0.0000000000000000f,
1104 0.0000000000000000f,
1105 -0.0927057415246964f,
1106 0.0000000000000000f,
1107 0.0000000000000000f,
1108 0.5652843713760376f,
1109 0.4651299417018890f,
1110 -1.1094539165496826f,
1111 -1.0000000000000000f,
1112 0.0000000000000000f,
1113 0.0000000000000000f,
1114 8.3434572219848633f,
1115 0.0000000000000000f,
1116 });
1117 frustumGoldenOutputs.push_back({
1118 -0.4379884898662567f,
1119 0.0000000000000000f,
1120 0.0000000000000000f,
1121 0.0000000000000000f,
1122 0.0000000000000000f,
1123 -0.5045915246009827f,
1124 0.0000000000000000f,
1125 0.0000000000000000f,
1126 0.1630663424730301f,
1127 -1.6271190643310547f,
1128 -2.0214161872863770f,
1129 -1.0000000000000000f,
1130 0.0000000000000000f,
1131 0.0000000000000000f,
1132 -56.3862075805664062f,
1133 0.0000000000000000f,
1134 });
1135 frustumGoldenOutputs.push_back({
1136 7.5770230293273926f,
1137 0.0000000000000000f,
1138 0.0000000000000000f,
1139 0.0000000000000000f,
1140 0.0000000000000000f,
1141 0.6115797758102417f,
1142 0.0000000000000000f,
1143 0.0000000000000000f,
1144 -0.8814766407012939f,
1145 -0.1190952509641647f,
1146 2.4274852275848389f,
1147 -1.0000000000000000f,
1148 0.0000000000000000f,
1149 0.0000000000000000f,
1150 -73.3338088989257812f,
1151 0.0000000000000000f,
1152 });
1153 frustumGoldenOutputs.push_back({
1154 5.0737905502319336f,
1155 0.0000000000000000f,
1156 0.0000000000000000f,
1157 0.0000000000000000f,
1158 0.0000000000000000f,
1159 9.6311941146850586f,
1160 0.0000000000000000f,
1161 0.0000000000000000f,
1162 0.9459113478660583f,
1163 -2.7848947048187256f,
1164 0.4030041098594666f,
1165 -1.0000000000000000f,
1166 0.0000000000000000f,
1167 0.0000000000000000f,
1168 33.9142799377441406f,
1169 0.0000000000000000f,
1170 });
1171 frustumGoldenOutputs.push_back({
1172 -0.7472094297409058f,
1173 0.0000000000000000f,
1174 0.0000000000000000f,
1175 0.0000000000000000f,
1176 0.0000000000000000f,
1177 0.8509900569915771f,
1178 0.0000000000000000f,
1179 0.0000000000000000f,
1180 -0.0796770751476288f,
1181 0.3151517212390900f,
1182 -0.3025783598423004f,
1183 -1.0000000000000000f,
1184 0.0000000000000000f,
1185 0.0000000000000000f,
1186 -62.3977890014648438f,
1187 0.0000000000000000f,
1188 });
1189 frustumGoldenOutputs.push_back({
1190 -0.6390139460563660f,
1191 0.0000000000000000f,
1192 0.0000000000000000f,
1193 0.0000000000000000f,
1194 0.0000000000000000f,
1195 -1.9648925065994263f,
1196 0.0000000000000000f,
1197 0.0000000000000000f,
1198 -1.2496180534362793f,
1199 -0.2371963709592819f,
1200 -2.9617946147918701f,
1201 -1.0000000000000000f,
1202 0.0000000000000000f,
1203 0.0000000000000000f,
1204 -101.7502517700195312f,
1205 0.0000000000000000f,
1206 });
1207 frustumGoldenOutputs.push_back({
1208 30.3771648406982422f,
1209 0.0000000000000000f,
1210 0.0000000000000000f,
1211 0.0000000000000000f,
1212 0.0000000000000000f,
1213 -1.3496931791305542f,
1214 0.0000000000000000f,
1215 0.0000000000000000f,
1216 -91.7013320922851562f,
1217 1.1379971504211426f,
1218 0.7856983542442322f,
1219 -1.0000000000000000f,
1220 0.0000000000000000f,
1221 0.0000000000000000f,
1222 -6.2911696434020996f,
1223 0.0000000000000000f,
1224 });
1225
1226 for (size_t i = 0; i < frustumGoldenInputs.size(); i++)
1227 {
1228 const auto &input = frustumGoldenInputs[i];
1229 const auto &output = frustumGoldenOutputs[i];
1230 Mat4 r = Mat4::Frustum(input.l, input.r, input.b, input.t, input.n, input.f);
1231 CheckMatrixCloseToGolden(output, r);
1232 }
1233 }
1234
1235 // Tests orthographic projection matrices.
TEST(MatrixUtilsTest,Mat4Ortho)1236 TEST(MatrixUtilsTest, Mat4Ortho)
1237 {
1238 // Randomly-generated inputs, outputs using GLM.
1239 std::vector<FrustumArgs> orthoGoldenInputs;
1240 std::vector<std::vector<float>> orthoGoldenOutputs;
1241
1242 orthoGoldenInputs.push_back({-1.2515230178833008f, 5.6523618698120117f, -0.7427234649658203f,
1243 -2.9657564163208008f, -5.4732933044433594f, -9.6416902542114258f});
1244 orthoGoldenInputs.push_back({-7.8948307037353516f, -8.4146118164062500f, -4.3893952369689941f,
1245 7.4392738342285156f, -8.1261911392211914f, 3.1107978820800781f});
1246 orthoGoldenInputs.push_back({3.1667709350585938f, 3.9134168624877930f, -7.1993961334228516f,
1247 -0.2519502639770508f, 5.4625358581542969f, 8.8320560455322266f});
1248 orthoGoldenInputs.push_back({0.3597183227539062f, 5.7859621047973633f, 4.6786174774169922f,
1249 -6.4736566543579102f, -2.7510557174682617f, 2.9977531433105469f});
1250 orthoGoldenInputs.push_back({3.2480134963989258f, 9.3551750183105469f, -7.5922241210937500f,
1251 -2.5135083198547363f, -4.5282001495361328f, -5.4564580917358398f});
1252 orthoGoldenInputs.push_back({-6.6918325424194336f, -9.6249752044677734f, -6.9591665267944336f,
1253 -2.7099137306213379f, -5.5196690559387207f, -9.0791969299316406f});
1254 orthoGoldenInputs.push_back({5.9386453628540039f, -9.1784019470214844f, -1.4078102111816406f,
1255 -1.0552892684936523f, 3.7563705444335938f, -6.6715431213378906f});
1256 orthoGoldenInputs.push_back({-8.6238059997558594f, -0.2995386123657227f, 5.6623821258544922f,
1257 7.6483421325683594f, 5.6686410903930664f, -7.1456899642944336f});
1258 orthoGoldenInputs.push_back({2.3857555389404297f, -2.6020836830139160f, 6.7841358184814453f,
1259 0.9868297576904297f, 5.6463518142700195f, -1.7597074508666992f});
1260 orthoGoldenInputs.push_back({4.6028537750244141f, 0.1757516860961914f, -6.1434607505798340f,
1261 6.8524093627929688f, 8.4380626678466797f, -1.4824752807617188f});
1262 orthoGoldenInputs.push_back({40.3382720947265625f, -34.5338973999023438f, -11.1726379394531250f,
1263 21.4206924438476562f, 17.5087890625000000f, 70.2734069824218750f});
1264 orthoGoldenInputs.push_back({85.2872314453125000f, 22.3899002075195312f, -92.8537139892578125f,
1265 7.6059341430664062f, 32.9500732421875000f, -8.1374511718750000f});
1266 orthoGoldenInputs.push_back({33.8771057128906250f, -27.6973648071289062f, 90.3841094970703125f,
1267 85.8473358154296875f, 36.0423278808593750f,
1268 -36.5140991210937500f});
1269 orthoGoldenInputs.push_back({-92.4729461669921875f, 7.1592102050781250f, -75.2177963256835938f,
1270 14.4945983886718750f, 10.6297378540039062f, 53.9828796386718750f});
1271 orthoGoldenInputs.push_back({90.2037658691406250f, 54.5332946777343750f, -58.9839515686035156f,
1272 56.7301330566406250f, 63.2403869628906250f, 81.1043853759765625f});
1273 orthoGoldenInputs.push_back({-78.6419067382812500f, 65.5156250000000000f, -78.8265304565429688f,
1274 -37.5036048889160156f, 76.9322204589843750f,
1275 -0.2213287353515625f});
1276 orthoGoldenInputs.push_back({80.1368560791015625f, 60.2946777343750000f, -27.3523788452148438f,
1277 88.5419616699218750f, -75.3445968627929688f,
1278 83.3852081298828125f});
1279 orthoGoldenInputs.push_back({55.0712585449218750f, -17.4033813476562500f, -98.6088104248046875f,
1280 81.6600952148437500f, 61.1217803955078125f, 73.5973815917968750f});
1281 orthoGoldenInputs.push_back({-48.7522583007812500f, 20.8100433349609375f, -45.6365356445312500f,
1282 -13.2819519042968750f, -29.7577133178710938f,
1283 62.1014862060546875f});
1284 orthoGoldenInputs.push_back({-60.3634567260742188f, 71.4023284912109375f, 59.0719757080078125f,
1285 22.6195831298828125f, -32.6802139282226562f,
1286 -56.3766899108886719f});
1287 orthoGoldenOutputs.push_back({
1288 0.2896919548511505f,
1289 0.0000000000000000f,
1290 0.0000000000000000f,
1291 0.0000000000000000f,
1292 0.0000000000000000f,
1293 -0.8996717929840088f,
1294 0.0000000000000000f,
1295 0.0000000000000000f,
1296 0.0000000000000000f,
1297 0.0000000000000000f,
1298 0.4798007607460022f,
1299 0.0000000000000000f,
1300 -0.6374438405036926f,
1301 -1.6682072877883911f,
1302 -3.6260902881622314f,
1303 1.0000000000000000f,
1304 });
1305 orthoGoldenOutputs.push_back({
1306 -3.8477735519409180f,
1307 0.0000000000000000f,
1308 0.0000000000000000f,
1309 0.0000000000000000f,
1310 0.0000000000000000f,
1311 0.1690807342529297f,
1312 0.0000000000000000f,
1313 0.0000000000000000f,
1314 0.0000000000000000f,
1315 0.0000000000000000f,
1316 -0.1779836267232895f,
1317 0.0000000000000000f,
1318 -31.3775196075439453f,
1319 -0.2578378617763519f,
1320 0.4463289380073547f,
1321 1.0000000000000000f,
1322 });
1323 orthoGoldenOutputs.push_back({
1324 2.6786458492279053f,
1325 0.0000000000000000f,
1326 0.0000000000000000f,
1327 0.0000000000000000f,
1328 0.0000000000000000f,
1329 0.2878755927085876f,
1330 0.0000000000000000f,
1331 0.0000000000000000f,
1332 0.0000000000000000f,
1333 0.0000000000000000f,
1334 -0.5935563445091248f,
1335 0.0000000000000000f,
1336 -9.4826574325561523f,
1337 1.0725302696228027f,
1338 -4.2423224449157715f,
1339 1.0000000000000000f,
1340 });
1341 orthoGoldenOutputs.push_back({
1342 0.3685790896415710f,
1343 0.0000000000000000f,
1344 0.0000000000000000f,
1345 0.0000000000000000f,
1346 0.0000000000000000f,
1347 -0.1793356239795685f,
1348 0.0000000000000000f,
1349 0.0000000000000000f,
1350 0.0000000000000000f,
1351 0.0000000000000000f,
1352 -0.3478981554508209f,
1353 0.0000000000000000f,
1354 -1.1325846910476685f,
1355 -0.1609572321176529f,
1356 -0.0429127886891365f,
1357 1.0000000000000000f,
1358 });
1359 orthoGoldenOutputs.push_back({
1360 0.3274843692779541f,
1361 0.0000000000000000f,
1362 0.0000000000000000f,
1363 0.0000000000000000f,
1364 0.0000000000000000f,
1365 0.3938003480434418f,
1366 0.0000000000000000f,
1367 0.0000000000000000f,
1368 0.0000000000000000f,
1369 0.0000000000000000f,
1370 2.1545734405517578f,
1371 0.0000000000000000f,
1372 -2.0636737346649170f,
1373 1.9898203611373901f,
1374 -10.7563400268554688f,
1375 1.0000000000000000f,
1376 });
1377 orthoGoldenOutputs.push_back({
1378 -0.6818625330924988f,
1379 0.0000000000000000f,
1380 0.0000000000000000f,
1381 0.0000000000000000f,
1382 0.0000000000000000f,
1383 0.4706709980964661f,
1384 0.0000000000000000f,
1385 0.0000000000000000f,
1386 0.0000000000000000f,
1387 0.0000000000000000f,
1388 0.5618722438812256f,
1389 0.0000000000000000f,
1390 -5.5629096031188965f,
1391 2.2754778861999512f,
1392 -4.1013488769531250f,
1393 1.0000000000000000f,
1394 });
1395 orthoGoldenOutputs.push_back({
1396 -0.1323009729385376f,
1397 0.0000000000000000f,
1398 0.0000000000000000f,
1399 0.0000000000000000f,
1400 0.0000000000000000f,
1401 5.6734218597412109f,
1402 0.0000000000000000f,
1403 0.0000000000000000f,
1404 0.0000000000000000f,
1405 0.0000000000000000f,
1406 0.1917929202318192f,
1407 0.0000000000000000f,
1408 -0.2143114656209946f,
1409 6.9871010780334473f,
1410 -0.2795547246932983f,
1411 1.0000000000000000f,
1412 });
1413 orthoGoldenOutputs.push_back({
1414 0.2402613908052444f,
1415 0.0000000000000000f,
1416 0.0000000000000000f,
1417 0.0000000000000000f,
1418 0.0000000000000000f,
1419 1.0070695877075195f,
1420 0.0000000000000000f,
1421 0.0000000000000000f,
1422 0.0000000000000000f,
1423 0.0000000000000000f,
1424 0.1560752540826797f,
1425 0.0000000000000000f,
1426 1.0719676017761230f,
1427 -6.7024130821228027f,
1428 -0.1152653917670250f,
1429 1.0000000000000000f,
1430 });
1431 orthoGoldenOutputs.push_back({
1432 -0.4009752273559570f,
1433 0.0000000000000000f,
1434 0.0000000000000000f,
1435 0.0000000000000000f,
1436 0.0000000000000000f,
1437 -0.3449878096580505f,
1438 0.0000000000000000f,
1439 0.0000000000000000f,
1440 0.0000000000000000f,
1441 0.0000000000000000f,
1442 0.2700491547584534f,
1443 0.0000000000000000f,
1444 -0.0433711148798466f,
1445 1.3404442071914673f,
1446 0.5247924923896790f,
1447 1.0000000000000000f,
1448 });
1449 orthoGoldenOutputs.push_back({
1450 -0.4517627954483032f,
1451 0.0000000000000000f,
1452 0.0000000000000000f,
1453 0.0000000000000000f,
1454 0.0000000000000000f,
1455 0.1538950353860855f,
1456 0.0000000000000000f,
1457 0.0000000000000000f,
1458 0.0000000000000000f,
1459 0.0000000000000000f,
1460 0.2016019672155380f,
1461 0.0000000000000000f,
1462 1.0793980360031128f,
1463 -0.0545518361032009f,
1464 0.7011300325393677f,
1465 1.0000000000000000f,
1466 });
1467 orthoGoldenOutputs.push_back({
1468 -0.0267121959477663f,
1469 0.0000000000000000f,
1470 0.0000000000000000f,
1471 0.0000000000000000f,
1472 0.0000000000000000f,
1473 0.0613622479140759f,
1474 0.0000000000000000f,
1475 0.0000000000000000f,
1476 0.0000000000000000f,
1477 0.0000000000000000f,
1478 -0.0379041880369186f,
1479 0.0000000000000000f,
1480 0.0775237977504730f,
1481 -0.3144218325614929f,
1482 -1.6636564731597900f,
1483 1.0000000000000000f,
1484 });
1485 orthoGoldenOutputs.push_back({
1486 -0.0317978523671627f,
1487 0.0000000000000000f,
1488 0.0000000000000000f,
1489 0.0000000000000000f,
1490 0.0000000000000000f,
1491 0.0199084915220737f,
1492 0.0000000000000000f,
1493 0.0000000000000000f,
1494 0.0000000000000000f,
1495 0.0000000000000000f,
1496 0.0486765764653683f,
1497 0.0000000000000000f,
1498 1.7119507789611816f,
1499 0.8485773205757141f,
1500 0.6038967370986938f,
1501 1.0000000000000000f,
1502 });
1503 orthoGoldenOutputs.push_back({
1504 -0.0324809923768044f,
1505 0.0000000000000000f,
1506 0.0000000000000000f,
1507 0.0000000000000000f,
1508 0.0000000000000000f,
1509 -0.4408419132232666f,
1510 0.0000000000000000f,
1511 0.0000000000000000f,
1512 0.0000000000000000f,
1513 0.0000000000000000f,
1514 0.0275647528469563f,
1515 0.0000000000000000f,
1516 0.1003620624542236f,
1517 38.8451042175292969f,
1518 -0.0065021286718547f,
1519 1.0000000000000000f,
1520 });
1521 orthoGoldenOutputs.push_back({
1522 0.0200738403946161f,
1523 0.0000000000000000f,
1524 0.0000000000000000f,
1525 0.0000000000000000f,
1526 0.0000000000000000f,
1527 0.0222934633493423f,
1528 0.0000000000000000f,
1529 0.0000000000000000f,
1530 0.0000000000000000f,
1531 0.0000000000000000f,
1532 -0.0461327582597733f,
1533 0.0000000000000000f,
1534 0.8562871813774109f,
1535 0.6768652200698853f,
1536 -1.4903790950775146f,
1537 1.0000000000000000f,
1538 });
1539 orthoGoldenOutputs.push_back({
1540 -0.0560687854886055f,
1541 0.0000000000000000f,
1542 0.0000000000000000f,
1543 0.0000000000000000f,
1544 0.0000000000000000f,
1545 0.0172839816659689f,
1546 0.0000000000000000f,
1547 0.0000000000000000f,
1548 0.0000000000000000f,
1549 0.0000000000000000f,
1550 -0.1119570210576057f,
1551 0.0000000000000000f,
1552 4.0576157569885254f,
1553 0.0194774791598320f,
1554 -8.0802049636840820f,
1555 1.0000000000000000f,
1556 });
1557 orthoGoldenOutputs.push_back({
1558 0.0138737112283707f,
1559 0.0000000000000000f,
1560 0.0000000000000000f,
1561 0.0000000000000000f,
1562 0.0000000000000000f,
1563 0.0483992844820023f,
1564 0.0000000000000000f,
1565 0.0000000000000000f,
1566 0.0000000000000000f,
1567 0.0000000000000000f,
1568 0.0259223338216543f,
1569 0.0000000000000000f,
1570 0.0910551249980927f,
1571 2.8151476383209229f,
1572 0.9942626357078552f,
1573 1.0000000000000000f,
1574 });
1575 orthoGoldenOutputs.push_back({
1576 -0.1007953882217407f,
1577 0.0000000000000000f,
1578 0.0000000000000000f,
1579 0.0000000000000000f,
1580 0.0000000000000000f,
1581 0.0172570981085300f,
1582 0.0000000000000000f,
1583 0.0000000000000000f,
1584 0.0000000000000000f,
1585 0.0000000000000000f,
1586 -0.0126000288873911f,
1587 0.0000000000000000f,
1588 7.0774250030517578f,
1589 -0.5279772877693176f,
1590 -0.0506559647619724f,
1591 1.0000000000000000f,
1592 });
1593 orthoGoldenOutputs.push_back({
1594 -0.0275958590209484f,
1595 0.0000000000000000f,
1596 0.0000000000000000f,
1597 0.0000000000000000f,
1598 0.0000000000000000f,
1599 0.0110945366322994f,
1600 0.0000000000000000f,
1601 0.0000000000000000f,
1602 0.0000000000000000f,
1603 0.0000000000000000f,
1604 -0.1603129208087921f,
1605 0.0000000000000000f,
1606 0.5197387337684631f,
1607 0.0940190702676773f,
1608 -10.7986106872558594f,
1609 1.0000000000000000f,
1610 });
1611 orthoGoldenOutputs.push_back({
1612 0.0287512056529522f,
1613 0.0000000000000000f,
1614 0.0000000000000000f,
1615 0.0000000000000000f,
1616 0.0000000000000000f,
1617 0.0618150420486927f,
1618 0.0000000000000000f,
1619 0.0000000000000000f,
1620 0.0000000000000000f,
1621 0.0000000000000000f,
1622 -0.0217724516987801f,
1623 0.0000000000000000f,
1624 0.4016861617565155f,
1625 1.8210244178771973f,
1626 -0.3521016240119934f,
1627 1.0000000000000000f,
1628 });
1629 orthoGoldenOutputs.push_back({
1630 0.0151784475892782f,
1631 0.0000000000000000f,
1632 0.0000000000000000f,
1633 0.0000000000000000f,
1634 0.0000000000000000f,
1635 -0.0548660829663277f,
1636 0.0000000000000000f,
1637 0.0000000000000000f,
1638 0.0000000000000000f,
1639 0.0000000000000000f,
1640 0.0844007357954979f,
1641 0.0000000000000000f,
1642 -0.0837764739990234f,
1643 2.2410478591918945f,
1644 -3.7582340240478516f,
1645 1.0000000000000000f,
1646 });
1647
1648 EXPECT_EQ(orthoGoldenInputs.size(), orthoGoldenOutputs.size());
1649
1650 for (size_t i = 0; i < orthoGoldenInputs.size(); i++)
1651 {
1652 const auto &input = orthoGoldenInputs[i];
1653 const auto &output = orthoGoldenOutputs[i];
1654 Mat4 r = Mat4::Ortho(input.l, input.r, input.b, input.t, input.n, input.f);
1655 CheckMatrixCloseToGolden(output, r);
1656 }
1657 }
1658
1659 // Tests for inverse transpose of mat4, which is a frequent operation done to
1660 // the modelview matrix, for things such as transformation of normals.
TEST(MatrixUtilsTest,Mat4InvTr)1661 TEST(MatrixUtilsTest, Mat4InvTr)
1662 {
1663
1664 std::vector<std::vector<float>> invTrInputs;
1665 std::vector<std::vector<float>> invTrOutputs;
1666 invTrInputs.push_back({
1667 0.3247877955436707f,
1668 -0.8279561400413513f,
1669 0.4571666717529297f,
1670 0.0000000000000000f,
1671 0.9041201472282410f,
1672 0.1299063563346863f,
1673 -0.4070515632629395f,
1674 0.0000000000000000f,
1675 0.2776319682598114f,
1676 0.5455390810966492f,
1677 0.7907638549804688f,
1678 0.0000000000000000f,
1679 0.0000000000000000f,
1680 0.0000000000000000f,
1681 0.0000000000000000f,
1682 1.0000000000000000f,
1683 });
1684 invTrInputs.push_back({
1685 -0.8843839168548584f,
1686 0.3047805428504944f,
1687 -0.3535164594650269f,
1688 0.0000000000000000f,
1689 0.4647803902626038f,
1690 0.6447106003761292f,
1691 -0.6068999171257019f,
1692 0.0000000000000000f,
1693 0.0429445058107376f,
1694 -0.7010400891304016f,
1695 -0.7118276357650757f,
1696 0.0000000000000000f,
1697 0.0000000000000000f,
1698 0.0000000000000000f,
1699 0.0000000000000000f,
1700 1.0000000000000000f,
1701 });
1702 invTrInputs.push_back({
1703 -0.4487786889076233f,
1704 0.8632985353469849f,
1705 0.2308966517448425f,
1706 0.0000000000000000f,
1707 -0.5765564441680908f,
1708 -0.0823006033897400f,
1709 -0.8129017353057861f,
1710 -0.0000000000000000f,
1711 -0.6827739477157593f,
1712 -0.4979379475116730f,
1713 0.5346751213073730f,
1714 0.0000000000000000f,
1715 0.0000000000000000f,
1716 0.0000000000000000f,
1717 0.0000000000000000f,
1718 1.0000000000000000f,
1719 });
1720 invTrInputs.push_back({
1721 0.9865614175796509f,
1722 0.0901400744915009f,
1723 -0.1362765878438950f,
1724 0.0000000000000000f,
1725 0.0155128352344036f,
1726 0.7786107659339905f,
1727 0.6273153424263000f,
1728 0.0000000000000000f,
1729 0.1626526862382889f,
1730 -0.6209991574287415f,
1731 0.7667490243911743f,
1732 0.0000000000000000f,
1733 0.0000000000000000f,
1734 0.0000000000000000f,
1735 0.0000000000000000f,
1736 1.0000000000000000f,
1737 });
1738 invTrInputs.push_back({
1739 -0.5566663742065430f,
1740 0.8302737474441528f,
1741 -0.0277124047279358f,
1742 0.0000000000000000f,
1743 -0.0281167924404144f,
1744 0.0145094990730286f,
1745 0.9994993209838867f,
1746 0.0000000000000000f,
1747 0.8302601575851440f,
1748 0.5571669340133667f,
1749 0.0152677297592163f,
1750 0.0000000000000000f,
1751 0.0000000000000000f,
1752 0.0000000000000000f,
1753 0.0000000000000000f,
1754 1.0000000000000000f,
1755 });
1756 invTrInputs.push_back({
1757 0.4160673320293427f,
1758 -0.9093281030654907f,
1759 0.0032218396663666f,
1760 0.0000000000000000f,
1761 -0.1397584974765778f,
1762 -0.0674473643302917f,
1763 -0.9878858327865601f,
1764 -0.0000000000000000f,
1765 0.8985296487808228f,
1766 0.4105767309665680f,
1767 -0.1551489830017090f,
1768 0.0000000000000000f,
1769 0.0000000000000000f,
1770 0.0000000000000000f,
1771 0.0000000000000000f,
1772 1.0000000000000000f,
1773 });
1774 invTrInputs.push_back({
1775 0.9039891958236694f,
1776 -0.3967807590961456f,
1777 -0.1592751741409302f,
1778 0.0000000000000000f,
1779 0.4139676988124847f,
1780 0.9054293632507324f,
1781 0.0939593166112900f,
1782 0.0000000000000000f,
1783 0.1069311797618866f,
1784 -0.1508729904890060f,
1785 0.9827527999877930f,
1786 0.0000000000000000f,
1787 0.0000000000000000f,
1788 0.0000000000000000f,
1789 0.0000000000000000f,
1790 1.0000000000000000f,
1791 });
1792 invTrInputs.push_back({
1793 0.3662135303020477f,
1794 0.2184857577085495f,
1795 0.9045174121856689f,
1796 0.0000000000000000f,
1797 -0.6651677489280701f,
1798 0.7412178516387939f,
1799 0.0902667641639709f,
1800 0.0000000000000000f,
1801 -0.6507223844528198f,
1802 -0.6347126960754395f,
1803 0.4167736768722534f,
1804 0.0000000000000000f,
1805 0.0000000000000000f,
1806 0.0000000000000000f,
1807 0.0000000000000000f,
1808 1.0000000000000000f,
1809 });
1810 invTrInputs.push_back({
1811 0.3791426718235016f,
1812 0.7277372479438782f,
1813 -0.5715323686599731f,
1814 0.0000000000000000f,
1815 -0.3511379361152649f,
1816 0.6845993995666504f,
1817 0.6387689113616943f,
1818 0.0000000000000000f,
1819 0.8561266660690308f,
1820 -0.0414978563785553f,
1821 0.5150970220565796f,
1822 0.0000000000000000f,
1823 0.0000000000000000f,
1824 0.0000000000000000f,
1825 0.0000000000000000f,
1826 1.0000000000000000f,
1827 });
1828 invTrInputs.push_back({
1829 -0.6766842603683472f,
1830 -0.0953263640403748f,
1831 -0.7300762534141541f,
1832 -0.0000000000000000f,
1833 -0.5922094583511353f,
1834 0.6596454977989197f,
1835 0.4627699255943298f,
1836 0.0000000000000000f,
1837 0.4374772906303406f,
1838 0.7455072402954102f,
1839 -0.5028247833251953f,
1840 0.0000000000000000f,
1841 0.0000000000000000f,
1842 0.0000000000000000f,
1843 0.0000000000000000f,
1844 1.0000000000000000f,
1845 });
1846 invTrInputs.push_back({
1847 0.8012667894363403f,
1848 -0.5429225564002991f,
1849 0.2514090538024902f,
1850 0.0000000000000000f,
1851 0.3384204804897308f,
1852 0.7577887773513794f,
1853 0.5578778386116028f,
1854 0.0000000000000000f,
1855 -0.4933994412422180f,
1856 -0.3619270324707031f,
1857 0.7909271121025085f,
1858 0.0000000000000000f,
1859 0.0000000000000000f,
1860 0.0000000000000000f,
1861 0.0000000000000000f,
1862 1.0000000000000000f,
1863 });
1864 invTrInputs.push_back({
1865 0.6100972890853882f,
1866 0.4051006734371185f,
1867 0.6809366941452026f,
1868 0.0000000000000000f,
1869 -0.6470826864242554f,
1870 0.7507012486457825f,
1871 0.1331603974103928f,
1872 0.0000000000000000f,
1873 -0.4572366476058960f,
1874 -0.5218631625175476f,
1875 0.7201343774795532f,
1876 0.0000000000000000f,
1877 0.0000000000000000f,
1878 0.0000000000000000f,
1879 0.0000000000000000f,
1880 1.0000000000000000f,
1881 });
1882 invTrInputs.push_back({
1883 0.6304160356521606f,
1884 0.2796489298343658f,
1885 -0.7241353392601013f,
1886 0.0000000000000000f,
1887 0.3735889792442322f,
1888 0.7084143161773682f,
1889 0.5988158583641052f,
1890 0.0000000000000000f,
1891 0.6804460883140564f,
1892 -0.6480321288108826f,
1893 0.3421219885349274f,
1894 0.0000000000000000f,
1895 0.0000000000000000f,
1896 0.0000000000000000f,
1897 0.0000000000000000f,
1898 1.0000000000000000f,
1899 });
1900 invTrInputs.push_back({
1901 -0.2888220548629761f,
1902 0.9278694987297058f,
1903 -0.2358816564083099f,
1904 0.0000000000000000f,
1905 0.8899697065353394f,
1906 0.1693908572196960f,
1907 -0.4233919680118561f,
1908 0.0000000000000000f,
1909 -0.3528962731361389f,
1910 -0.3322124481201172f,
1911 -0.8746994137763977f,
1912 -0.0000000000000000f,
1913 0.0000000000000000f,
1914 0.0000000000000000f,
1915 0.0000000000000000f,
1916 1.0000000000000000f,
1917 });
1918 invTrInputs.push_back({
1919 0.7878623008728027f,
1920 0.2866843938827515f,
1921 0.5450551509857178f,
1922 0.0000000000000000f,
1923 -0.5206709504127502f,
1924 0.7827371954917908f,
1925 0.3409168124198914f,
1926 0.0000000000000000f,
1927 -0.3288993835449219f,
1928 -0.5523898601531982f,
1929 0.7659573554992676f,
1930 0.0000000000000000f,
1931 0.0000000000000000f,
1932 0.0000000000000000f,
1933 0.0000000000000000f,
1934 1.0000000000000000f,
1935 });
1936 invTrInputs.push_back({
1937 -0.3225378990173340f,
1938 0.9464974999427795f,
1939 0.0105716586112976f,
1940 0.0000000000000000f,
1941 -0.4923008084297180f,
1942 -0.1582012772560120f,
1943 -0.8559277057647705f,
1944 -0.0000000000000000f,
1945 -0.8084610104560852f,
1946 -0.2812736034393311f,
1947 0.5169874429702759f,
1948 0.0000000000000000f,
1949 0.0000000000000000f,
1950 0.0000000000000000f,
1951 0.0000000000000000f,
1952 1.0000000000000000f,
1953 });
1954 invTrInputs.push_back({
1955 0.3137793838977814f,
1956 0.3656709790229797f,
1957 0.8762575387954712f,
1958 0.0000000000000000f,
1959 0.8767655491828918f,
1960 0.2426431477069855f,
1961 -0.4152186512947083f,
1962 0.0000000000000000f,
1963 -0.3644512593746185f,
1964 0.8985595107078552f,
1965 -0.2444712668657303f,
1966 0.0000000000000000f,
1967 0.0000000000000000f,
1968 0.0000000000000000f,
1969 0.0000000000000000f,
1970 1.0000000000000000f,
1971 });
1972 invTrInputs.push_back({
1973 0.8862395882606506f,
1974 -0.3831786513328552f,
1975 0.2602950036525726f,
1976 0.0000000000000000f,
1977 0.4416945576667786f,
1978 0.8683440685272217f,
1979 -0.2255758643150330f,
1980 0.0000000000000000f,
1981 -0.1395897567272186f,
1982 0.3148851394653320f,
1983 0.9388087987899780f,
1984 0.0000000000000000f,
1985 0.0000000000000000f,
1986 0.0000000000000000f,
1987 0.0000000000000000f,
1988 1.0000000000000000f,
1989 });
1990 invTrInputs.push_back({
1991 0.4614841341972351f,
1992 -0.8635553717613220f,
1993 -0.2032356113195419f,
1994 0.0000000000000000f,
1995 -0.7492366433143616f,
1996 -0.5020523071289062f,
1997 0.4319583475589752f,
1998 0.0000000000000000f,
1999 -0.4750548601150513f,
2000 -0.0470703244209290f,
2001 -0.8786963224411011f,
2002 -0.0000000000000000f,
2003 0.0000000000000000f,
2004 0.0000000000000000f,
2005 0.0000000000000000f,
2006 1.0000000000000000f,
2007 });
2008 invTrInputs.push_back({
2009 0.7327640056610107f,
2010 -0.5076418519020081f,
2011 0.4531629979610443f,
2012 0.0000000000000000f,
2013 -0.0702797919511795f,
2014 0.6059250831604004f,
2015 0.7924112081527710f,
2016 0.0000000000000000f,
2017 -0.6768439412117004f,
2018 -0.6124986410140991f,
2019 0.4083231091499329f,
2020 0.0000000000000000f,
2021 0.0000000000000000f,
2022 0.0000000000000000f,
2023 0.0000000000000000f,
2024 1.0000000000000000f,
2025 });
2026 invTrOutputs.push_back({
2027 0.3247878849506378f,
2028 -0.8279562592506409f,
2029 0.4571668505668640f,
2030 -0.0000000000000000f,
2031 0.9041203260421753f,
2032 0.1299064010381699f,
2033 -0.4070515930652618f,
2034 0.0000000000000000f,
2035 0.2776320576667786f,
2036 0.5455390810966492f,
2037 0.7907639741897583f,
2038 -0.0000000000000000f,
2039 -0.0000000000000000f,
2040 0.0000000000000000f,
2041 -0.0000000000000000f,
2042 1.0000000000000000f,
2043 });
2044 invTrOutputs.push_back({
2045 -0.8843840360641479f,
2046 0.3047805130481720f,
2047 -0.3535164594650269f,
2048 -0.0000000000000000f,
2049 0.4647804200649261f,
2050 0.6447105407714844f,
2051 -0.6068999171257019f,
2052 -0.0000000000000000f,
2053 0.0429445207118988f,
2054 -0.7010400891304016f,
2055 -0.7118277549743652f,
2056 0.0000000000000000f,
2057 -0.0000000000000000f,
2058 0.0000000000000000f,
2059 0.0000000000000000f,
2060 1.0000000000000000f,
2061 });
2062 invTrOutputs.push_back({
2063 -0.4487787485122681f,
2064 0.8632985949516296f,
2065 0.2308966219425201f,
2066 -0.0000000000000000f,
2067 -0.5765565037727356f,
2068 -0.0823005959391594f,
2069 -0.8129017353057861f,
2070 0.0000000000000000f,
2071 -0.6827740073204041f,
2072 -0.4979379475116730f,
2073 0.5346751213073730f,
2074 -0.0000000000000000f,
2075 -0.0000000000000000f,
2076 0.0000000000000000f,
2077 -0.0000000000000000f,
2078 1.0000000000000000f,
2079 });
2080 invTrOutputs.push_back({
2081 0.9865614175796509f,
2082 0.0901400819420815f,
2083 -0.1362766027450562f,
2084 -0.0000000000000000f,
2085 0.0155128324404359f,
2086 0.7786108255386353f,
2087 0.6273154020309448f,
2088 -0.0000000000000000f,
2089 0.1626526862382889f,
2090 -0.6209992170333862f,
2091 0.7667490839958191f,
2092 -0.0000000000000000f,
2093 -0.0000000000000000f,
2094 0.0000000000000000f,
2095 -0.0000000000000000f,
2096 1.0000000000000000f,
2097 });
2098 invTrOutputs.push_back({
2099 -0.5566664934158325f,
2100 0.8302738070487976f,
2101 -0.0277124084532261f,
2102 -0.0000000000000000f,
2103 -0.0281168315559626f,
2104 0.0145094739273190f,
2105 0.9994993805885315f,
2106 -0.0000000000000000f,
2107 0.8302602171897888f,
2108 0.5571669340133667f,
2109 0.0152676850557327f,
2110 -0.0000000000000000f,
2111 -0.0000000000000000f,
2112 -0.0000000000000000f,
2113 -0.0000000000000000f,
2114 1.0000000000000000f,
2115 });
2116 invTrOutputs.push_back({
2117 0.4160673320293427f,
2118 -0.9093281030654907f,
2119 0.0032218731939793f,
2120 -0.0000000000000000f,
2121 -0.1397585272789001f,
2122 -0.0674473419785500f,
2123 -0.9878858327865601f,
2124 0.0000000000000000f,
2125 0.8985296487808228f,
2126 0.4105767309665680f,
2127 -0.1551489681005478f,
2128 -0.0000000000000000f,
2129 -0.0000000000000000f,
2130 0.0000000000000000f,
2131 -0.0000000000000000f,
2132 1.0000000000000000f,
2133 });
2134 invTrOutputs.push_back({
2135 0.9039891958236694f,
2136 -0.3967807590961456f,
2137 -0.1592751741409302f,
2138 -0.0000000000000000f,
2139 0.4139677286148071f,
2140 0.9054294228553772f,
2141 0.0939593166112900f,
2142 0.0000000000000000f,
2143 0.1069311797618866f,
2144 -0.1508729755878448f,
2145 0.9827527999877930f,
2146 -0.0000000000000000f,
2147 -0.0000000000000000f,
2148 0.0000000000000000f,
2149 -0.0000000000000000f,
2150 1.0000000000000000f,
2151 });
2152 invTrOutputs.push_back({
2153 0.3662134706974030f,
2154 0.2184857726097107f,
2155 0.9045172333717346f,
2156 -0.0000000000000000f,
2157 -0.6651675701141357f,
2158 0.7412176728248596f,
2159 0.0902667865157127f,
2160 0.0000000000000000f,
2161 -0.6507222652435303f,
2162 -0.6347125172615051f,
2163 0.4167735874652863f,
2164 -0.0000000000000000f,
2165 -0.0000000000000000f,
2166 0.0000000000000000f,
2167 -0.0000000000000000f,
2168 1.0000000000000000f,
2169 });
2170 invTrOutputs.push_back({
2171 0.3791427314281464f,
2172 0.7277373671531677f,
2173 -0.5715324282646179f,
2174 -0.0000000000000000f,
2175 -0.3511379957199097f,
2176 0.6845995187759399f,
2177 0.6387690305709839f,
2178 -0.0000000000000000f,
2179 0.8561268448829651f,
2180 -0.0414978675544262f,
2181 0.5150971412658691f,
2182 -0.0000000000000000f,
2183 -0.0000000000000000f,
2184 0.0000000000000000f,
2185 -0.0000000000000000f,
2186 1.0000000000000000f,
2187 });
2188 invTrOutputs.push_back({
2189 -0.6766842603683472f,
2190 -0.0953262373805046f,
2191 -0.7300761342048645f,
2192 -0.0000000000000000f,
2193 -0.5922094583511353f,
2194 0.6596452593803406f,
2195 0.4627698063850403f,
2196 0.0000000000000000f,
2197 0.4374772608280182f,
2198 0.7455070018768311f,
2199 -0.5028247833251953f,
2200 -0.0000000000000000f,
2201 -0.0000000000000000f,
2202 -0.0000000000000000f,
2203 -0.0000000000000000f,
2204 1.0000000000000000f,
2205 });
2206 invTrOutputs.push_back({
2207 0.8012669086456299f,
2208 -0.5429226160049438f,
2209 0.2514090836048126f,
2210 -0.0000000000000000f,
2211 0.3384204804897308f,
2212 0.7577888369560242f,
2213 0.5578778982162476f,
2214 0.0000000000000000f,
2215 -0.4933995306491852f,
2216 -0.3619270920753479f,
2217 0.7909271717071533f,
2218 -0.0000000000000000f,
2219 -0.0000000000000000f,
2220 0.0000000000000000f,
2221 -0.0000000000000000f,
2222 1.0000000000000000f,
2223 });
2224 invTrOutputs.push_back({
2225 0.6100972294807434f,
2226 0.4051006138324738f,
2227 0.6809366941452026f,
2228 -0.0000000000000000f,
2229 -0.6470826268196106f,
2230 0.7507011294364929f,
2231 0.1331604123115540f,
2232 0.0000000000000000f,
2233 -0.4572366178035736f,
2234 -0.5218631029129028f,
2235 0.7201343774795532f,
2236 -0.0000000000000000f,
2237 -0.0000000000000000f,
2238 0.0000000000000000f,
2239 -0.0000000000000000f,
2240 1.0000000000000000f,
2241 });
2242 invTrOutputs.push_back({
2243 0.6304160952568054f,
2244 0.2796489298343658f,
2245 -0.7241354584693909f,
2246 -0.0000000000000000f,
2247 0.3735889494419098f,
2248 0.7084143161773682f,
2249 0.5988159179687500f,
2250 -0.0000000000000000f,
2251 0.6804461479187012f,
2252 -0.6480321288108826f,
2253 0.3421220481395721f,
2254 -0.0000000000000000f,
2255 -0.0000000000000000f,
2256 0.0000000000000000f,
2257 -0.0000000000000000f,
2258 1.0000000000000000f,
2259 });
2260 invTrOutputs.push_back({
2261 -0.2888221442699432f,
2262 0.9278693199157715f,
2263 -0.2358815670013428f,
2264 -0.0000000000000000f,
2265 0.8899695873260498f,
2266 0.1693906933069229f,
2267 -0.4233919084072113f,
2268 -0.0000000000000000f,
2269 -0.3528962433338165f,
2270 -0.3322124481201172f,
2271 -0.8746994137763977f,
2272 0.0000000000000000f,
2273 -0.0000000000000000f,
2274 0.0000000000000000f,
2275 0.0000000000000000f,
2276 1.0000000000000000f,
2277 });
2278 invTrOutputs.push_back({
2279 0.7878623008728027f,
2280 0.2866844236850739f,
2281 0.5450551509857178f,
2282 -0.0000000000000000f,
2283 -0.5206709504127502f,
2284 0.7827371954917908f,
2285 0.3409168422222137f,
2286 0.0000000000000000f,
2287 -0.3288994133472443f,
2288 -0.5523898601531982f,
2289 0.7659573554992676f,
2290 -0.0000000000000000f,
2291 -0.0000000000000000f,
2292 0.0000000000000000f,
2293 -0.0000000000000000f,
2294 1.0000000000000000f,
2295 });
2296 invTrOutputs.push_back({
2297 -0.3225379288196564f,
2298 0.9464974999427795f,
2299 0.0105716586112976f,
2300 -0.0000000000000000f,
2301 -0.4923008382320404f,
2302 -0.1582012772560120f,
2303 -0.8559277057647705f,
2304 0.0000000000000000f,
2305 -0.8084610104560852f,
2306 -0.2812735736370087f,
2307 0.5169873833656311f,
2308 -0.0000000000000000f,
2309 -0.0000000000000000f,
2310 0.0000000000000000f,
2311 -0.0000000000000000f,
2312 1.0000000000000000f,
2313 });
2314 invTrOutputs.push_back({
2315 0.3137793540954590f,
2316 0.3656708896160126f,
2317 0.8762574791908264f,
2318 -0.0000000000000000f,
2319 0.8767654895782471f,
2320 0.2426430881023407f,
2321 -0.4152186512947083f,
2322 0.0000000000000000f,
2323 -0.3644512593746185f,
2324 0.8985593318939209f,
2325 -0.2444712817668915f,
2326 -0.0000000000000000f,
2327 -0.0000000000000000f,
2328 0.0000000000000000f,
2329 -0.0000000000000000f,
2330 1.0000000000000000f,
2331 });
2332 invTrOutputs.push_back({
2333 0.8862395882606506f,
2334 -0.3831786811351776f,
2335 0.2602950334548950f,
2336 -0.0000000000000000f,
2337 0.4416945576667786f,
2338 0.8683440685272217f,
2339 -0.2255758792161942f,
2340 0.0000000000000000f,
2341 -0.1395897865295410f,
2342 0.3148851692676544f,
2343 0.9388088583946228f,
2344 -0.0000000000000000f,
2345 -0.0000000000000000f,
2346 0.0000000000000000f,
2347 -0.0000000000000000f,
2348 1.0000000000000000f,
2349 });
2350 invTrOutputs.push_back({
2351 0.4614838957786560f,
2352 -0.8635552525520325f,
2353 -0.2032355368137360f,
2354 -0.0000000000000000f,
2355 -0.7492365241050720f,
2356 -0.5020524263381958f,
2357 0.4319583177566528f,
2358 0.0000000000000000f,
2359 -0.4750548005104065f,
2360 -0.0470703467726707f,
2361 -0.8786963820457458f,
2362 0.0000000000000000f,
2363 -0.0000000000000000f,
2364 0.0000000000000000f,
2365 -0.0000000000000000f,
2366 1.0000000000000000f,
2367 });
2368 invTrOutputs.push_back({
2369 0.7327639460563660f,
2370 -0.5076418519020081f,
2371 0.4531629383563995f,
2372 -0.0000000000000000f,
2373 -0.0702798143029213f,
2374 0.6059250235557556f,
2375 0.7924111485481262f,
2376 0.0000000000000000f,
2377 -0.6768438220024109f,
2378 -0.6124985218048096f,
2379 0.4083230793476105f,
2380 -0.0000000000000000f,
2381 -0.0000000000000000f,
2382 0.0000000000000000f,
2383 -0.0000000000000000f,
2384 1.0000000000000000f,
2385 });
2386
2387 EXPECT_EQ(invTrInputs.size(), invTrInputs.size());
2388
2389 for (size_t i = 0; i < invTrInputs.size(); i++)
2390 {
2391 Mat4 a(invTrInputs[i]);
2392 CheckMatrixCloseToGolden(invTrOutputs[i], a.transpose().inverse());
2393 }
2394 }
2395
2396 // Tests mat4 matrix/matrix multiplication by multiplying two translation matrices.
TEST(MatrixUtilsTest,Mat4Mult)2397 TEST(MatrixUtilsTest, Mat4Mult)
2398 {
2399 Mat4 a, b;
2400 CheckMatrixCloseToGolden(a.data(), a.product(b));
2401
2402 Mat4 r = Mat4::Translate(Vector3(1.f, 1.f, 1.f));
2403 CheckMatrixCloseToGolden(r.data(), a.product(r));
2404
2405 Mat4 s = Mat4::Translate(Vector3(2.f, 2.f, 2.f));
2406 Mat4 t = r.product(r);
2407 CheckMatrixCloseToGolden(s.data(), t);
2408 }
2409
2410 // Tests exact equality.
TEST(MatrixUtilsTest,ExactEquality)2411 TEST(MatrixUtilsTest, ExactEquality)
2412 {
2413 Matrix<float> a(std::vector<float>(16), 4, 4);
2414 Matrix<float> b(std::vector<float>(16), 4, 4);
2415 EXPECT_EQ(a, b);
2416 Matrix<float> c(std::vector<float>(16), 4, 4);
2417 c(0, 0) += 0.000001f;
2418 EXPECT_NE(a, c);
2419 }
2420
2421 // Tests near equality.
TEST(MatrixUtilsTest,NearEquality)2422 TEST(MatrixUtilsTest, NearEquality)
2423 {
2424 Matrix<float> a(std::vector<float>(16), 4, 4);
2425 Matrix<float> b(std::vector<float>(16), 4, 4);
2426
2427 float *bData = b.data();
2428 for (int i = 0; i < 16; i++)
2429 {
2430 bData[i] += 0.09f;
2431 }
2432
2433 EXPECT_TRUE(a.nearlyEqual(0.1f, b));
2434
2435 for (int i = 0; i < 16; i++)
2436 {
2437 bData[i] -= 2 * 0.09f;
2438 }
2439
2440 EXPECT_TRUE(a.nearlyEqual(0.1f, b));
2441 }
2442
2443 } // namespace
2444