naev 0.12.5
mat4.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include <stddef.h>
7
8#include "glad.h"
9
10#include "vec3.h"
11
12typedef struct mat4_ {
13 union {
14 /* Column-major; m[x][y] */
15 GLfloat m[4][4];
16 GLfloat ptr[16];
17 };
18} mat4;
19
20typedef struct quat {
21 GLfloat q[4]; /* x, y, z, w */
22} quat;
23
24/* Basic operations. */
25void mat4_tostr( const mat4 *m, char *buf, size_t len );
26void mat4_print( const mat4 *m );
27void mat4_mul( mat4 *out, const mat4 *m1, const mat4 *m2 );
28void mat4_mul_vec( vec3 *out, const mat4 *m, const vec3 *v );
29
30/* Affine transformations. */
31void mat4_apply( mat4 *lhs, const mat4 *rhs );
32void mat4_scale( mat4 *m, double x, double y, double z );
33void mat4_scale_xy( mat4 *m, double x, double y );
34void mat4_translate( mat4 *m, double x, double y, double z );
35void mat4_translate_x( mat4 *m, double x );
36void mat4_translate_xy( mat4 *m, double x, double y );
37void mat4_translate_scale_xy( mat4 *m, double x, double y, double w, double h );
38void mat4_rotate( mat4 *m, double angle, double x, double y, double z );
39void mat4_rotate_quaternion( mat4 *m, const quat *q );
40void mat4_rotate2d( mat4 *m, double angle );
41void mat4_rotate2dv( mat4 *m, double x, double y );
42void mat4_trs( mat4 *m, const vec3 *t, const quat *r, const vec3 *s );
43
44/* Creation functions. */
45__attribute__( ( const ) ) mat4 mat4_identity( void );
46__attribute__( ( const ) ) mat4 mat4_ortho( double left, double right,
47 double bottom, double top,
48 double nearVal, double farVal );
49mat4 mat4_lookat( const vec3 *eye, const vec3 *center, const vec3 *up );
50mat4 mat4_perspective( double fov, double aspect, double near, double far );
51
52/* Quaternion stuff. */
53void quat_normalize( quat *q );
54void quat_slerp( GLfloat qm[4], const GLfloat qa[4], const GLfloat qb[4],
55 GLfloat t );
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
Definition mat4.c:137
void mat4_apply(mat4 *lhs, const mat4 *rhs)
Applies a transformation to another, storing the result in the left hand side.
Definition mat4.c:84
mat4 mat4_lookat(const vec3 *eye, const vec3 *center, const vec3 *up)
Creates a matrix with a transformation to look at a center point from an eye with an up vector.
Definition mat4.c:382
mat4 mat4_identity(void)
Creates an identity matrix.
Definition mat4.c:335
mat4 mat4_perspective(double fov, double aspect, double near, double far)
Creates a matrix with a perspective transformation.
Definition mat4.c:433
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:216
void mat4_mul_vec(vec3 *out, const mat4 *m, const vec3 *v)
Multiplies a matrix with a vector (out = m * v);.
Definition mat4.c:67
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
Definition mat4.c:113
void mat4_mul(mat4 *out, const mat4 *m1, const mat4 *m2)
Multiplies two matrices (out = m1 * m2).
Definition mat4.c:46
void mat4_rotate_quaternion(mat4 *m, const quat *q)
Applies a quaternion transformation.
Definition mat4.c:253
void mat4_trs(mat4 *m, const vec3 *t, const quat *r, const vec3 *s)
Creates a homogeneous transform matrix from a translation, rotation, and scaling. Uses T*R*S order.
Definition mat4.c:290
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
Definition mat4.c:347
void mat4_rotate2d(mat4 *m, double angle)
Rotates an angle, in radians, around the z axis.
Definition mat4.c:167
void mat4_rotate2dv(mat4 *m, double c, double s)
Rotates the +x axis to the given vector.
Definition mat4.c:191
Definition mat4.h:12
Definition mat4.h:20
Definition vec3.h:6