@@ -424,6 +424,52 @@ TEST(GeometryTest, MatrixIsAligned) {
424
424
}
425
425
}
426
426
427
+ TEST (GeometryTest, MatrixLookAt) {
428
+ {
429
+ auto m = Matrix::MakeLookAt (Vector3 (0 , 0 , -1 ), Vector3 (0 , 0 , 1 ),
430
+ Vector3 (0 , 1 , 0 ));
431
+ auto expected = Matrix{
432
+ 1 , 0 , 0 , 0 , //
433
+ 0 , 1 , 0 , 0 , //
434
+ 0 , 0 , 1 , 0 , //
435
+ 0 , 0 , 1 , 1 , //
436
+ };
437
+ ASSERT_MATRIX_NEAR (m, expected);
438
+ }
439
+
440
+ // Sideways tilt.
441
+ {
442
+ auto m = Matrix::MakeLookAt (Vector3 (0 , 0 , -1 ), Vector3 (0 , 0 , 1 ),
443
+ Vector3 (1 , 1 , 0 ).Normalize ());
444
+
445
+ // clang-format off
446
+ auto expected = Matrix{
447
+ k1OverSqrt2, k1OverSqrt2, 0 , 0 ,
448
+ -k1OverSqrt2, k1OverSqrt2, 0 , 0 ,
449
+ 0 , 0 , 1 , 0 ,
450
+ 0 , 0 , 1 , 1 ,
451
+ };
452
+ // clang-format on
453
+ ASSERT_MATRIX_NEAR (m, expected);
454
+ }
455
+
456
+ // Half way between +x and -y, yaw 90
457
+ {
458
+ auto m =
459
+ Matrix::MakeLookAt (Vector3 (), Vector3 (10 , -10 , 0 ), Vector3 (0 , 0 , -1 ));
460
+
461
+ // clang-format off
462
+ auto expected = Matrix{
463
+ -k1OverSqrt2, 0 , k1OverSqrt2, 0 ,
464
+ -k1OverSqrt2, 0 , -k1OverSqrt2, 0 ,
465
+ 0 , -1 , 0 , 0 ,
466
+ 0 , 0 , 0 , 1 ,
467
+ };
468
+ // clang-format on
469
+ ASSERT_MATRIX_NEAR (m, expected);
470
+ }
471
+ }
472
+
427
473
TEST (GeometryTest, QuaternionLerp) {
428
474
auto q1 = Quaternion{{0.0 , 0.0 , 1.0 }, 0.0 };
429
475
auto q2 = Quaternion{{0.0 , 0.0 , 1.0 }, kPiOver4 };
0 commit comments