mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-17 06:46:39 -04:00
util/matrix: Inline wlr_matrix_{identity, scale, translate}
This commit is contained in:
parent
088b7c98c5
commit
99b6084fcd
2 changed files with 11 additions and 39 deletions
|
|
@ -6,19 +6,10 @@
|
||||||
struct wlr_box;
|
struct wlr_box;
|
||||||
struct wlr_fbox;
|
struct wlr_fbox;
|
||||||
|
|
||||||
/** Writes the identity matrix into mat */
|
|
||||||
void wlr_matrix_identity(float mat[static 9]);
|
|
||||||
|
|
||||||
/** mat ← a × b */
|
/** mat ← a × b */
|
||||||
void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
|
void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
|
||||||
const float b[static 9]);
|
const float b[static 9]);
|
||||||
|
|
||||||
/** Writes a 2D translation matrix to mat of magnitude (x, y) */
|
|
||||||
void wlr_matrix_translate(float mat[static 9], float x, float y);
|
|
||||||
|
|
||||||
/** Writes a 2D scale matrix to mat of magnitude (x, y) */
|
|
||||||
void wlr_matrix_scale(float mat[static 9], float x, float y);
|
|
||||||
|
|
||||||
/** Writes a transformation matrix which applies the specified
|
/** Writes a transformation matrix which applies the specified
|
||||||
* wl_output_transform to mat */
|
* wl_output_transform to mat */
|
||||||
void wlr_matrix_transform(float mat[static 9],
|
void wlr_matrix_transform(float mat[static 9],
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,6 @@
|
||||||
#include <wlr/util/box.h>
|
#include <wlr/util/box.h>
|
||||||
#include "util/matrix.h"
|
#include "util/matrix.h"
|
||||||
|
|
||||||
void wlr_matrix_identity(float mat[static 9]) {
|
|
||||||
static const float identity[9] = {
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
};
|
|
||||||
memcpy(mat, identity, sizeof(identity));
|
|
||||||
}
|
|
||||||
|
|
||||||
void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
|
void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
|
||||||
const float b[static 9]) {
|
const float b[static 9]) {
|
||||||
float product[9];
|
float product[9];
|
||||||
|
|
@ -31,24 +22,6 @@ void wlr_matrix_multiply(float mat[static 9], const float a[static 9],
|
||||||
memcpy(mat, product, sizeof(product));
|
memcpy(mat, product, sizeof(product));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_matrix_translate(float mat[static 9], float x, float y) {
|
|
||||||
float translate[9] = {
|
|
||||||
1.0f, 0.0f, x,
|
|
||||||
0.0f, 1.0f, y,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
};
|
|
||||||
wlr_matrix_multiply(mat, mat, translate);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wlr_matrix_scale(float mat[static 9], float x, float y) {
|
|
||||||
float scale[9] = {
|
|
||||||
x, 0.0f, 0.0f,
|
|
||||||
0.0f, y, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
};
|
|
||||||
wlr_matrix_multiply(mat, mat, scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const float transforms[][9] = {
|
static const float transforms[][9] = {
|
||||||
[WL_OUTPUT_TRANSFORM_NORMAL] = {
|
[WL_OUTPUT_TRANSFORM_NORMAL] = {
|
||||||
1.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f,
|
||||||
|
|
@ -112,9 +85,17 @@ void matrix_projection(float mat[static 9], int width, int height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_matrix_project_fbox(float mat[static 9], const struct wlr_fbox *box) {
|
void wlr_matrix_project_fbox(float mat[static 9], const struct wlr_fbox *box) {
|
||||||
wlr_matrix_identity(mat);
|
mat[0] = box->width;
|
||||||
wlr_matrix_translate(mat, box->x, box->y);
|
mat[1] = 0.0f;
|
||||||
wlr_matrix_scale(mat, box->width, box->height);
|
mat[2] = box->x;
|
||||||
|
|
||||||
|
mat[3] = 0.0f;
|
||||||
|
mat[4] = box->height;
|
||||||
|
mat[5] = box->y;
|
||||||
|
|
||||||
|
mat[6] = 0.0f;
|
||||||
|
mat[7] = 0.0f;
|
||||||
|
mat[8] = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box) {
|
void wlr_matrix_project_box(float mat[static 9], const struct wlr_box *box) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue