util/matrix: Rotate around (.5, .5) with wlr_matrix_transform

Before we would rotate around 0,0 which means that the content needed
to be scaled to -1, 1 to be transformed properly when we're usually
working in the 0, 1 range. Switch it around.

These matrices were precomputed by simply adding a -.5 -.5 translate
and back again with old transform in between.
This commit is contained in:
Alexander Orzechowski 2025-01-27 13:43:51 -05:00
parent c9d6339b60
commit 3a4bc44688
2 changed files with 8 additions and 12 deletions

View file

@ -57,21 +57,21 @@ static const float transforms[][9] = {
},
[WL_OUTPUT_TRANSFORM_90] = {
0.0f, 1.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_180] = {
-1.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f,
-1.0f, 0.0f, 1.0f,
0.0f, -1.0f, 1.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_270] = {
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 1.0f,
1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_FLIPPED] = {
-1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f,
},
@ -82,12 +82,12 @@ static const float transforms[][9] = {
},
[WL_OUTPUT_TRANSFORM_FLIPPED_180] = {
1.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f,
0.0f, -1.0f, 1.0f,
0.0f, 0.0f, 1.0f,
},
[WL_OUTPUT_TRANSFORM_FLIPPED_270] = {
0.0f, -1.0f, 0.0f,
-1.0f, 0.0f, 0.0f,
0.0f, -1.0f, 1.0f,
-1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
},
};
@ -132,9 +132,7 @@ void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box,
wlr_matrix_scale(mat, width, height);
if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
wlr_matrix_translate(mat, 0.5, 0.5);
wlr_matrix_transform(mat, transform);
wlr_matrix_translate(mat, -0.5, -0.5);
}
wlr_matrix_multiply(mat, projection, mat);