Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
scenefx/include/util/matrix.h (1.6K)
1 #ifndef UTIL_MATRIX_H
2 #define UTIL_MATRIX_H
3
4 #include <wayland-server-protocol.h>
5
6 struct wlr_box;
7
8 /** Writes the identity matrix into mat */
9 void wlr_matrix_identity(float mat[static 9]);
10
11 /** mat ← a × b */
12 void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
13 const float b[static 9]);
14
15 /** Writes a 2D translation matrix to mat of magnitude (x, y) */
16 void wlr_matrix_translate(float mat[static 9], float x, float y);
17
18 /** Writes a 2D scale matrix to mat of magnitude (x, y) */
19 void wlr_matrix_scale(float mat[static 9], float x, float y);
20
21 /** Writes a transformation matrix which applies the specified
22 * wl_output_transform to mat */
23 void wlr_matrix_transform(float mat[static 9],
24 enum wl_output_transform transform);
25
26 /** Shortcut for the various matrix operations involved in projecting the
27 * specified wlr_box onto a given orthographic projection with a given
28 * rotation. The result is written to mat, which can be applied to each
29 * coordinate of the box to get a new coordinate from [-1,1]. */
30 void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box,
31 enum wl_output_transform transform, const float projection[static 9]);
32
33 /**
34 * Writes a 2D orthographic projection matrix to mat of (width, height) with a
35 * specified wl_output_transform.
36 *
37 * Equivalent to glOrtho(0, width, 0, height, 1, -1) with the transform applied.
38 */
39 void matrix_projection(float mat[static 9], int width, int height,
40 enum wl_output_transform transform);
41
42 /**
43 * Compute the inverse of a matrix.
44 *
45 * The matrix needs to be inversible.
46 */
47 void matrix_invert(float out[static 9], float m[static 9]);
48
49 #endif