aboutsummaryrefslogtreecommitdiff
path: root/render/matrix.c
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2018-01-21 15:53:29 -0500
committerTony Crisci <tony@dubstepdish.com>2018-01-21 15:53:42 -0500
commitd13114520acef63f9293ff313b8a549bc81be30c (patch)
tree8c4d3be30d295472f3b858f6316bcb9089330750 /render/matrix.c
parent7474f005917fbb98cad08e8078c1da0c27742174 (diff)
move matrix model code to matrix.h
Diffstat (limited to 'render/matrix.c')
-rw-r--r--render/matrix.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/render/matrix.c b/render/matrix.c
index 54dba4cc..a64a8f9b 100644
--- a/render/matrix.c
+++ b/render/matrix.c
@@ -1,6 +1,8 @@
#include <string.h>
#include <math.h>
#include <wayland-server-protocol.h>
+#include <wlr/types/wlr_box.h>
+#include <wlr/types/wlr_output.h>
#include <wlr/render/matrix.h>
/* Obtains the index for the given row/column */
@@ -158,3 +160,47 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
mat[10] = 1.0f;
mat[15] = 1.0f;
}
+
+void wlr_matrix_box_model(float (*mat)[16], struct wlr_box *box,
+ enum wl_output_transform transform, float rotation) {
+ int x = box->x;
+ int y = box->y;
+ int width = box->width;
+ int height = box->height;
+
+ float translate_center[16];
+ wlr_matrix_translate(&translate_center,
+ (int)x + width / 2, (int)y + height / 2, 0);
+
+ float rotate[16];
+ wlr_matrix_rotate(&rotate, rotation);
+
+ float translate_origin[16];
+ wlr_matrix_translate(&translate_origin, -width / 2,
+ -height / 2, 0);
+
+ float scale[16];
+ wlr_matrix_scale(&scale, width, height, 1);
+
+ wlr_matrix_mul(&translate_center, &rotate, mat);
+ wlr_matrix_mul(mat, &translate_origin, mat);
+ wlr_matrix_mul(mat, &scale, mat);
+
+ if (transform != WL_OUTPUT_TRANSFORM_NORMAL) {
+ float surface_translate_center[16];
+ wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0);
+
+ float surface_transform[16];
+ wlr_matrix_transform(surface_transform,
+ wlr_output_transform_invert(transform));
+
+ float surface_translate_origin[16];
+ wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0);
+
+ wlr_matrix_mul(mat, &surface_translate_center,
+ mat);
+ wlr_matrix_mul(mat, &surface_transform, mat);
+ wlr_matrix_mul(mat, &surface_translate_origin,
+ mat);
+ }
+}