naev 0.11.5
mat4.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "glad.h"
7
8#include "vec3.h"
9
10typedef struct mat4_ {
11 union {
12 /* Column-major; m[x][y] */
13 GLfloat m[4][4];
14 GLfloat ptr[16];
15 };
16} mat4;
17
18/* Basic operations. */
19void mat4_print( const mat4 *m );
20void mat4_mul( mat4 *out, const mat4 *m1, const mat4 *m2 );
21
22/* Affine transformations. */
23void mat4_apply( mat4 *lhs, const mat4 *rhs );
24void mat4_scale( mat4 *m, double x, double y, double z );
25void mat4_translate( mat4 *m, double x, double y, double z );
26void mat4_rotate( mat4 *m, double angle, double x, double y, double z );
27void mat4_rotate2d( mat4 *m, double angle );
28void mat4_rotate2dv( mat4 *m, double x, double y );
29
30/* Creation functions. */
31__attribute__((const)) mat4 mat4_identity( void );
32__attribute__((const)) mat4 mat4_ortho( double left, double right,
33 double bottom, double top, double nearVal, double farVal );
34mat4 mat4_lookat( const vec3 *eye, const vec3 *center, const vec3 *up );
35mat4 mat4_perspective( double fov, double aspect, double near, double far );
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
Definition mat4.c:99
void mat4_apply(mat4 *lhs, const mat4 *rhs)
Applies a transformation to another, storing the result in the left hand side.
Definition mat4.c:53
mat4 mat4_identity(void)
Creates an identity matrix.
Definition mat4.c:195
void mat4_rotate(mat4 *m, double angle, double x, double y, double z)
Multiplies the given matrix by a rotation. (Follows the right-hand rule.)
Definition mat4.c:159
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
Definition mat4.c:82
void mat4_mul(mat4 *out, const mat4 *m1, const mat4 *m2)
Multiplies two matrices (out = m1 * m2).
Definition mat4.c:35
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
Definition mat4.c:209
void mat4_rotate2d(mat4 *m, double angle)
Rotates an angle, in radians, around the z axis.
Definition mat4.c:111
void mat4_rotate2dv(mat4 *m, double c, double s)
Rotates the +x axis to the given vector.
Definition mat4.c:135
Definition mat4.h:10
Definition vec3.h:6