From 7637bbbf5ae19de092a010f1d34a83a3e1ac3dd7 Mon Sep 17 00:00:00 2001 From: luckysmg <2539699336@qq.com> Date: Tue, 14 Feb 2023 17:22:14 +0800 Subject: [PATCH] ++ --- impeller/entity/entity_unittests.cc | 46 +++++++++++++++++++++++++ impeller/geometry/geometry_unittests.cc | 4 +-- impeller/geometry/matrix.h | 2 +- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index ec12c076dc095..64d3795924679 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -404,6 +404,52 @@ TEST_P(EntityTest, CubicCurveTest) { ASSERT_TRUE(OpenPlaygroundHere(entity)); } +TEST_P(EntityTest, CanDrawCorrectlyWithRotatedTransformation) { + auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { + const char* input_axis[] = {"X", "Y", "Z"}; + static int rotation_axis_index = 0; + static float rotation = 0; + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + ImGui::SliderFloat("Rotation", &rotation, -kPi, kPi); + ImGui::Combo("Rotation Axis", &rotation_axis_index, input_axis, + sizeof(input_axis) / sizeof(char*)); + Matrix rotation_matrix; + switch (rotation_axis_index) { + case 0: + rotation_matrix = Matrix::MakeRotationX(Radians(rotation)); + break; + case 1: + rotation_matrix = Matrix::MakeRotationY(Radians(rotation)); + break; + case 2: + rotation_matrix = Matrix::MakeRotationZ(Radians(rotation)); + break; + default: + rotation_matrix = Matrix{}; + break; + } + + if (ImGui::Button("Reset")) { + rotation = 0; + } + ImGui::End(); + Matrix current_transform = + Matrix::MakeScale(GetContentScale()) + .MakeTranslation( + Vector3(Point(pass.GetRenderTargetSize().width / 2.0, + pass.GetRenderTargetSize().height / 2.0))); + Matrix result_transform = current_transform * rotation_matrix; + Path path = + PathBuilder{}.AddRect(Rect::MakeXYWH(-300, -400, 600, 800)).TakePath(); + + Entity entity; + entity.SetTransformation(result_transform); + entity.SetContents(SolidColorContents::Make(path, Color::Red())); + return entity.Render(context, pass); + }; + ASSERT_TRUE(OpenPlaygroundHere(callback)); +} + TEST_P(EntityTest, CubicCurveAndOverlapTest) { // Compare with https://fiddle.skia.org/c/7a05a3e186c65a8dfb732f68020aae06 Path path = diff --git a/impeller/geometry/geometry_unittests.cc b/impeller/geometry/geometry_unittests.cc index 5ab4baa1d0830..a98b922bc1e03 100644 --- a/impeller/geometry/geometry_unittests.cc +++ b/impeller/geometry/geometry_unittests.cc @@ -341,7 +341,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) { auto expect = Matrix{ 0.02, 0, 0, 0, // 0, -0.01, 0, 0, // - 0, 0, 1, 0, // + 0, 0, 0, 0, // -1, 1, 0.5, 1, // }; ASSERT_MATRIX_NEAR(m, expect); @@ -352,7 +352,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) { auto expect = Matrix{ 0.005, 0, 0, 0, // 0, -0.02, 0, 0, // - 0, 0, 1, 0, // + 0, 0, 0, 0, // -1, 1, 0.5, 1, // }; ASSERT_MATRIX_NEAR(m, expect); diff --git a/impeller/geometry/matrix.h b/impeller/geometry/matrix.h index f58ad34d3fc6a..64688828f4884 100644 --- a/impeller/geometry/matrix.h +++ b/impeller/geometry/matrix.h @@ -443,7 +443,7 @@ struct Matrix { // Per assumptions about NDC documented above. const auto scale = MakeScale({2.0f / static_cast(size.width), - -2.0f / static_cast(size.height), 1.0}); + -2.0f / static_cast(size.height), 0.0}); const auto translate = MakeTranslation({-1.0, 1.0, 0.5}); return translate * scale; }