The MATHC project is a collection of objects for developing 2D and 3D games.
Today we will take a look at the MATHC project. At its core, it is a simple math library that can be used to develop 2D and 3D games. It contains realizations of the following mathematical objects in pure C:
2D and 3D vectors;
quaternions;
matrices;
smoothness functions.
Object implementations support both the C99 standard and newer ones.
Float type
Each structure and function of the library uses a float type, since this data type is used in most of the development of 2D and 3D games using OpenGL.
Passing by value or by pointer
For functions that accept structures as parameters, there are two implementation versions. The first is when the structure is passed by value, the second is by pointer. The second kind of function is prefixed with p in front of the type name (pvector2, pvector3, pquaternion and pmatrix), and the result is written to the passed argument * result.
/ * Pass by value, the result is a specific value * /
struct mat projection = matrix_ortho (-100.0f, 100.0f, 100.0f, -100.0f);
struct mat view = matrix_look_at (to_vector3 (0.0f, 0.0f, 1.0f),
to_vector3 (0.0f, 0.0f, 0.0f));
struct mat pv = matrix_multiply_matrix (projection, view);
/ * Pass by pointer * /
struct vec pos = {0};
struct vec target = {0};
struct mat projection = {0};
struct mat view = {0};
struct mat multiplied_matrix = {0};
to_pvector3 (0.0f, 0.0f, 1.0f, & pos);
to_pvector3 (0.0f, 0.0f, 0.0f, & target);
to_pvector3 (0.0f, 1.0f, 0.0f, & up);
pmatrix_ortho (-100.0f, 100.0f, 100.0f, -100.0f, & projection);
pmatrix_look_at (& pos, & target, & view);
pmatrix_multiply_matrix (& projection, & view, & multiplied_matrix);