(libretro-common) Start documenting matrix_4x4.c

This commit is contained in:
twinaphex 2015-06-24 11:37:45 +02:00
parent 80a1051e40
commit 2c09bbcda3

View File

@ -24,6 +24,9 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
/*
* Sets mat to an identity matrix
*/
void matrix_4x4_identity(math_matrix_4x4 *mat) void matrix_4x4_identity(math_matrix_4x4 *mat)
{ {
unsigned i; unsigned i;
@ -33,6 +36,9 @@ void matrix_4x4_identity(math_matrix_4x4 *mat)
MAT_ELEM_4X4(*mat, i, i) = 1.0f; MAT_ELEM_4X4(*mat, i, i) = 1.0f;
} }
/*
* Sets out to the transposed matrix of in
*/
void matrix_4x4_transpose(math_matrix_4x4 *out, const math_matrix_4x4 *in) void matrix_4x4_transpose(math_matrix_4x4 *out, const math_matrix_4x4 *in)
{ {
unsigned i, j; unsigned i, j;
@ -45,6 +51,9 @@ void matrix_4x4_transpose(math_matrix_4x4 *out, const math_matrix_4x4 *in)
*out = mat; *out = mat;
} }
/*
* Builds an X-axis rotation matrix
*/
void matrix_4x4_rotate_x(math_matrix_4x4 *mat, float rad) void matrix_4x4_rotate_x(math_matrix_4x4 *mat, float rad)
{ {
float cosine = cosf(rad); float cosine = cosf(rad);
@ -58,6 +67,10 @@ void matrix_4x4_rotate_x(math_matrix_4x4 *mat, float rad)
MAT_ELEM_4X4(*mat, 2, 1) = sine; MAT_ELEM_4X4(*mat, 2, 1) = sine;
} }
/*
* Builds a rotation matrix using the
* rotation around the Y-axis.
*/
void matrix_4x4_rotate_y(math_matrix_4x4 *mat, float rad) void matrix_4x4_rotate_y(math_matrix_4x4 *mat, float rad)
{ {
float cosine = cosf(rad); float cosine = cosf(rad);
@ -71,6 +84,10 @@ void matrix_4x4_rotate_y(math_matrix_4x4 *mat, float rad)
MAT_ELEM_4X4(*mat, 2, 0) = sine; MAT_ELEM_4X4(*mat, 2, 0) = sine;
} }
/*
* Builds a rotation matrix using the
* rotation around the Z-axis.
*/
void matrix_4x4_rotate_z(math_matrix_4x4 *mat, float rad) void matrix_4x4_rotate_z(math_matrix_4x4 *mat, float rad)
{ {
float cosine = cosf(rad); float cosine = cosf(rad);
@ -84,6 +101,9 @@ void matrix_4x4_rotate_z(math_matrix_4x4 *mat, float rad)
MAT_ELEM_4X4(*mat, 1, 0) = sine; MAT_ELEM_4X4(*mat, 1, 0) = sine;
} }
/*
* Creates an orthographic projection matrix.
*/
void matrix_4x4_ortho(math_matrix_4x4 *mat, void matrix_4x4_ortho(math_matrix_4x4 *mat,
float left, float right, float left, float right,
float bottom, float top, float bottom, float top,
@ -115,6 +135,11 @@ void matrix_4x4_scale(math_matrix_4x4 *out, float x, float y,
MAT_ELEM_4X4(*out, 3, 3) = 1.0f; MAT_ELEM_4X4(*out, 3, 3) = 1.0f;
} }
/*
* Builds a translation matrix. All other elements in
* the matrix will be set to zero except for the
* diagonal which is set to 1.0
*/
void matrix_4x4_translate(math_matrix_4x4 *out, float x, void matrix_4x4_translate(math_matrix_4x4 *out, float x,
float y, float z) float y, float z)
{ {
@ -124,6 +149,9 @@ void matrix_4x4_translate(math_matrix_4x4 *out, float x,
MAT_ELEM_4X4(*out, 2, 3) = z; MAT_ELEM_4X4(*out, 2, 3) = z;
} }
/*
* Creates a perspective projection matrix.
*/
void matrix_4x4_projection(math_matrix_4x4 *out, float znear, void matrix_4x4_projection(math_matrix_4x4 *out, float znear,
float zfar) float zfar)
{ {
@ -135,6 +163,9 @@ void matrix_4x4_projection(math_matrix_4x4 *out, float znear,
MAT_ELEM_4X4(*out, 3, 2) = -1.0f; MAT_ELEM_4X4(*out, 3, 2) = -1.0f;
} }
/*
* Multiplies a with b, stores the result in out
*/
void matrix_4x4_multiply( void matrix_4x4_multiply(
math_matrix_4x4 *out, math_matrix_4x4 *out,
const math_matrix_4x4 *a, const math_matrix_4x4 *a,