From 84e25c0673b9208a476f68b1e6bc932fb774d737 Mon Sep 17 00:00:00 2001 From: YYBartT Date: Fri, 8 Nov 2024 18:13:48 +0100 Subject: [PATCH 01/27] docs(general): add note about matrices being stored in arrays YoYoGames/GameMaker-Bugs#2960 --- Manual/contents/GameMaker_Language/GML_Overview/Data_Types.htm | 1 + 1 file changed, 1 insertion(+) diff --git a/Manual/contents/GameMaker_Language/GML_Overview/Data_Types.htm b/Manual/contents/GameMaker_Language/GML_Overview/Data_Types.htm index c432aa2b..a12f0a2c 100644 --- a/Manual/contents/GameMaker_Language/GML_Overview/Data_Types.htm +++ b/Manual/contents/GameMaker_Language/GML_Overview/Data_Types.htm @@ -43,6 +43,7 @@

Data Types

Arrays

+

Note that matrices are also stored in arrays. See Matrix Functions for more information.

 

Structs

From 502f486b14af62b7e7e021cf68555487017973e9 Mon Sep 17 00:00:00 2001 From: YYBartT Date: Mon, 11 Nov 2024 13:33:08 +0100 Subject: [PATCH 02/27] docs(feature): Add a new function matrix_inverse() for inverting a matrix YoYoGames/GameMaker-Bugs#2960 * Added matrix_inverse() page * Various other improvements to matrix function pages: * Changed the type "Matrix Array" to "Matrix", abstracting away the underlying type (similar to e.g. "Instance", "Surface", etc., which are stored in a "Handle") * Data Types: added a note under the "Arrays" section mentioning that matrices are stored in arrays * Matrix Functions page: * Grouped matrix functions according to their use, updated ToC accordingly * Documented that matrices are ordered column-major in arrays * Added a line to clarify that lines are the columns instead of the rows when splitting up an assignment over multiple lines * matrix_build() page: documented that matrices are ordered column-major in arrays, added note about matrices possibly ending up transposed in the shader * matrix_multiply() page: documented order of matrix multiplication on and added a second, copy-pastable example * matrix_set() page: listed the functions that can be used to create matrices of the various types, updated code example * matrix_get() and matrix_set() page: added proper short descriptions * Visual update of matrix function pages --- .../camera_get_proj_mat.htm | 18 +++-- .../camera_get_view_mat.htm | 18 +++-- .../Matrix_Functions/Matrix_Functions.htm | 58 ++++++++----- .../Matrix_Functions/matrix_build.htm | 19 ++--- .../matrix_build_identity.htm | 4 +- .../Matrix_Functions/matrix_build_lookat.htm | 4 +- .../matrix_build_projection_ortho.htm | 48 ++++++----- .../matrix_build_projection_perspective.htm | 50 ++++++------ ...atrix_build_projection_perspective_fov.htm | 46 ++++++----- .../Matrix_Functions/matrix_get.htm | 5 +- .../Matrix_Functions/matrix_inverse.htm | 76 ++++++++++++++++++ .../Matrix_Functions/matrix_multiply.htm | 40 ++++++--- .../Matrix_Functions/matrix_set.htm | 36 ++++++--- .../matrix_transform_vertex.htm | 21 +++-- .../matrix_array_indices_column_major.png | Bin 0 -> 7761 bytes .../snippets/Note_Matrix_Column_Major.hts | 15 ++++ Manual/toc/Default.toc | 5 +- Manual/variable/Default.var | 2 +- 18 files changed, 313 insertions(+), 152 deletions(-) create mode 100644 Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Matrix_Functions/matrix_inverse.htm create mode 100644 Manual/contents/assets/Images/Scripting_Reference/GML/Reference/Maths/matrix_array_indices_column_major.png create mode 100644 Manual/contents/assets/snippets/Note_Matrix_Column_Major.hts diff --git a/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/camera_get_proj_mat.htm b/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/camera_get_proj_mat.htm index 5a363eda..299a04cf 100644 --- a/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/camera_get_proj_mat.htm +++ b/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/camera_get_proj_mat.htm @@ -4,7 +4,7 @@ camera_get_proj_mat - + @@ -16,25 +16,27 @@

camera_get_proj_mat

-

This function can be used to retrieve the projection matrix. The function returns the matrix array which can then be used in other matrix functions or to set the projection matrix of another camera (using camera_set_proj_mat()).

+

This function can be used to retrieve the projection matrix. The function returns the matrix which can then be used in other matrix functions or to set the projection matrix of another camera (using camera_set_proj_mat()).

 

Syntax:

camera_get_proj_mat(camera_id)

- + + - + - + + - +
ArgumentTypeArgumentType Description
camera_idcamera_idCamera ID The unique camera ID value returned when you created the camera

 

Returns:

-

Matrix Array

+

Matrix

 

Example:

mat = camera_get_proj_mat(camera_view[0]);

@@ -49,7 +51,7 @@

Example:

Next: camera_get_update_script
-
© Copyright YoYo Games Ltd. 2022 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

camera_get_view_mat

-

This function can be used to retrieve the view matrix. The function returns the matrix array which can then be used in other matrix functions or to set the view matrix of another camera (using camera_set_view_mat()). Note that this function is generally for use with cameras created using camera_create(), but it can also be used on those created in the room editor (or with camera_create_view()) - in which case the returned matrix will only be valid after the given camera is used in a view port for the first time.

+

This function can be used to retrieve the view matrix. The function returns the matrix which can then be used in other matrix functions or to set the view matrix of another camera (using camera_set_view_mat()). Note that this function is generally for use with cameras created using camera_create(), but it can also be used on those created in the room editor (or with camera_create_view()) - in which case the returned matrix will only be valid after the given camera is used in a view port for the first time.

 

Syntax:

camera_get_view_mat(camera_id)

- + + - + - + + - +
ArgumentTypeArgumentType Description
camera_idcamera_idCamera ID The unique camera ID value returned when you created the camera

 

Returns:

-

Matrix Array

+

Matrix

 

Example:

mat = camera_get_view_mat(camera_view[0]);

@@ -49,7 +51,7 @@

Example:

Next: camera_get_proj_mat
-
© Copyright YoYo Games Ltd. 2022 All Rights Reserved
+
© Copyright YoYo Games Ltd. 2024 All Rights Reserved

matrix_build

-

This function can be used to create your own custom matrix and will return a matrix array, which should be stored in a variable for future reference and use. It accepts 3-dimensional (x, y, z) translation, rotation and scale values, and uses them to build a matrix array.

-

The matrix array contains 16 values in total, where the initial 4 elements are row/column 1, the next 4 elements are row/column 2 and so on, as part of a 4x4 matrix. Whether the array is ordered by rows or columns depends on the target platform, as the graphics renderer used by a platform may use row-major or column-major matrices.

+

This function creates a custom transformation matrix from 3-dimensional (x, y, z) translation, rotation and scale values and returns it.

+
+

 When you set this matrix in a shader using shader_set_uniform_f_arrayshader_set_uniform_matrix or shader_set_uniform_matrix_array, depending on the shader type and the target platform, you may receive the matrix transposed in the shader.

 When you build a new matrix in this way, the order of operation is YXZ.

 

Syntax:

@@ -47,17 +48,17 @@

Syntax:

xrotation Real - The angle to rotate around the x-axis (in degrees °). + The angle to rotate around the x-axis (in degrees). yrotation Real - The angle to rotate around the y-axis (in degrees °). + The angle to rotate around the y-axis (in degrees). zrotation Real - The angle to rotate around the z-axis (in degrees °). + The angle to rotate around the z-axis (in degrees). xscale @@ -78,18 +79,18 @@

Syntax:

 

Returns:

-

Matrix Array

+

Matrix

 

Example:

-

t_matrix = matrix_build(x, y, 0, 0, 90, 0, 1, 2, 1);

-

The above code will build a new matrix transform and store the resulting matrix index in a variable t_matrix.

+

t_matrix = matrix_build(x, y, 0, 0, 90, 0, 1, 2, 1);

+

The above code builds a new matrix transform and stores the resulting matrix index in a variable t_matrix.