Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3fc40ca

Browse files
authored
++ (#39617)
1 parent a6e8fb1 commit 3fc40ca

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

impeller/entity/entity_unittests.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,52 @@ TEST_P(EntityTest, CubicCurveTest) {
404404
ASSERT_TRUE(OpenPlaygroundHere(entity));
405405
}
406406

407+
TEST_P(EntityTest, CanDrawCorrectlyWithRotatedTransformation) {
408+
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
409+
const char* input_axis[] = {"X", "Y", "Z"};
410+
static int rotation_axis_index = 0;
411+
static float rotation = 0;
412+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
413+
ImGui::SliderFloat("Rotation", &rotation, -kPi, kPi);
414+
ImGui::Combo("Rotation Axis", &rotation_axis_index, input_axis,
415+
sizeof(input_axis) / sizeof(char*));
416+
Matrix rotation_matrix;
417+
switch (rotation_axis_index) {
418+
case 0:
419+
rotation_matrix = Matrix::MakeRotationX(Radians(rotation));
420+
break;
421+
case 1:
422+
rotation_matrix = Matrix::MakeRotationY(Radians(rotation));
423+
break;
424+
case 2:
425+
rotation_matrix = Matrix::MakeRotationZ(Radians(rotation));
426+
break;
427+
default:
428+
rotation_matrix = Matrix{};
429+
break;
430+
}
431+
432+
if (ImGui::Button("Reset")) {
433+
rotation = 0;
434+
}
435+
ImGui::End();
436+
Matrix current_transform =
437+
Matrix::MakeScale(GetContentScale())
438+
.MakeTranslation(
439+
Vector3(Point(pass.GetRenderTargetSize().width / 2.0,
440+
pass.GetRenderTargetSize().height / 2.0)));
441+
Matrix result_transform = current_transform * rotation_matrix;
442+
Path path =
443+
PathBuilder{}.AddRect(Rect::MakeXYWH(-300, -400, 600, 800)).TakePath();
444+
445+
Entity entity;
446+
entity.SetTransformation(result_transform);
447+
entity.SetContents(SolidColorContents::Make(path, Color::Red()));
448+
return entity.Render(context, pass);
449+
};
450+
ASSERT_TRUE(OpenPlaygroundHere(callback));
451+
}
452+
407453
TEST_P(EntityTest, CubicCurveAndOverlapTest) {
408454
// Compare with https://fiddle.skia.org/c/7a05a3e186c65a8dfb732f68020aae06
409455
Path path =

impeller/geometry/geometry_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) {
341341
auto expect = Matrix{
342342
0.02, 0, 0, 0, //
343343
0, -0.01, 0, 0, //
344-
0, 0, 1, 0, //
344+
0, 0, 0, 0, //
345345
-1, 1, 0.5, 1, //
346346
};
347347
ASSERT_MATRIX_NEAR(m, expect);
@@ -352,7 +352,7 @@ TEST(GeometryTest, MatrixMakeOrthographic) {
352352
auto expect = Matrix{
353353
0.005, 0, 0, 0, //
354354
0, -0.02, 0, 0, //
355-
0, 0, 1, 0, //
355+
0, 0, 0, 0, //
356356
-1, 1, 0.5, 1, //
357357
};
358358
ASSERT_MATRIX_NEAR(m, expect);

impeller/geometry/matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ struct Matrix {
443443
// Per assumptions about NDC documented above.
444444
const auto scale =
445445
MakeScale({2.0f / static_cast<Scalar>(size.width),
446-
-2.0f / static_cast<Scalar>(size.height), 1.0});
446+
-2.0f / static_cast<Scalar>(size.height), 0.0});
447447
const auto translate = MakeTranslation({-1.0, 1.0, 0.5});
448448
return translate * scale;
449449
}

0 commit comments

Comments
 (0)