All vectors (2D, 3D and quaternions) are in the form of structures of type struct vec. Note that the z component can be used for 2D vectors as well, since it is used in OpenGL to check depth. The w component is used only to describe the quaternion.
/ * Flip the 2D vector 90º * /
struct vec direction = to_vector2 (0.0f, -1.0f);
direction = vector2_rotate (90.0f * M_PIF / 180.0f);
/ * Get the slope in radians for the 2D vector * /
float angle = vector2_angle (direction);
/ * Create a 3D vector * /
struct vec position = to_vector3 (0.0f, 0.0f, 0.0f);
/ * Create quaternion * /
struct vec quaternion = to_quaternion (0.0f, 0.0f, 0.0f, 1.0f);
/ * Spherical interpolation between two quaternions * /
struct vec interpolated = quaternion_spherical_linear_interpolation (a, b, 0.5f);
Matrices
All matrices in the library are 4×4. MATHC also provides functions for adjusting model, world, and projection matrices. Typically, the world matrix is used to modify multiple vertices on the client side or on the GPU. If you want to change the vertices on the client side, then use the matrix_multiply_f4 () or pmatrix_multiply_f4 () functions to change the array with 4 floats:
/ * Components x, y, z and w * /
float v [4] = {0.0f, 10.0f, 0.0f, 1.0f};
struct mat rotation = matrix_rotation_z (to_radians (45.0f));
matrix_multiply_f4 (rotation, v);
If you want to change the vertices on the GPU side, then use the matrix_to_array () or pmatrix_to_array () functions to convert the matrix to an array with 16 float elements:
/ * MAT_SIZE – macro in mathc.h with value equal to 16 * /
float v [MAT_SIZE];
struct mat projection = matrix_ortho (-100.0f, 100.0f, -100.0f, 100.0f, 0.0f, 1.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);
matrix_to_array (pv, v);
Smoothness functions
Ease functions are useful for animation. The library implementation of functions is based on their description. The functions take values from 0.0f to 1.0f and return values within the same range. However, in some of the functions, the return value extrapolates this range.