[Impeller] Map to Metal's NDC in the perspective projection utility (flutter/engine#35394)

This commit is contained in:
Brandon DeRosier
2022-08-15 10:21:43 -07:00
committed by GitHub
parent f223617fc2
commit d9db0d0b47
2 changed files with 8 additions and 9 deletions

View File

@@ -284,8 +284,8 @@ TEST(GeometryTest, MatrixMakePerspective) {
auto expect = Matrix{
3.4641, 0, 0, 0, //
0, 1.73205, 0, 0, //
0, 0, -1.22222, -1, //
0, 0, -2.22222, 0, //
0, 0, -1.11111, -1, //
0, 0, -1.11111, 0, //
};
ASSERT_MATRIX_NEAR(m, expect);
}
@@ -295,8 +295,8 @@ TEST(GeometryTest, MatrixMakePerspective) {
auto expect = Matrix{
0.915244, 0, 0, 0, //
0, 1.83049, 0, 0, //
0, 0, -3, -1, //
0, 0, -40, 0, //
0, 0, -2, -1, //
0, 0, -20, 0, //
};
ASSERT_MATRIX_NEAR(m, expect);
}

View File

@@ -336,14 +336,13 @@ struct Matrix {
Scalar z_far) {
Scalar height = std::tan(fov_y.radians * 0.5);
Scalar width = height * aspect_ratio;
Scalar z_diff = z_near - z_far;
// clang-format off
return {
1.0f / width, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f / height, 0.0f, 0.0f,
0.0f, 0.0f, (z_near + z_far) / z_diff, -1.0f,
0.0f, 0.0f, (2.0f * z_near * z_far) / z_diff, 0.0f
1.0f / width, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f / height, 0.0f, 0.0f,
0.0f, 0.0f, z_far / (z_near - z_far), -1.0f,
0.0f, 0.0f, -(z_far * z_near) / (z_far - z_near), 0.0f,
};
// clang-format on
}