strichmaennchen git · main
git clone https://git.christianimmanuel.de/games/strichmaennchen.gitwget https://git.christianimmanuel.de/games/strichmaennchen/archive/strichmaennchen.tar.gzlinalg.h raw
#ifndef LINALG_H
#define LINALG_H
typedef struct {
float x, y, z;
} Vec3;
typedef struct {
float x, y, z, w;
} Vec4;
typedef struct {
float m[16]; // column-major 4x4 matrix
} Mat4;
// Vector helpers
Vec3 vec3(float x, float y, float z);
float vec3_dot(Vec3 a, Vec3 b);
Vec3 vec3_normalize(Vec3 v);
float vec3_length(Vec3 v);
Vec3 vec3_add(Vec3 a, Vec3 b);
Vec3 vec3_sub(Vec3 a, Vec3 b);
Vec3 vec3_div_scalar(Vec4 v);
Vec3 vec3_div_scalar_f(Vec3 v, float s);
Vec3 vec3_negate(Vec3 v);
Vec3 vec3_rotate(Vec3 v, Vec3 rot);
Vec4 vec4(float x, float y, float z, float w);
Vec4 mat4_mul_vec4(Mat4 m, Vec4 v);
Vec4 vec4_sub(Vec4 a, Vec4 b);
Vec3 mat4_mul_vec3_dir(Mat4 m, Vec3 v);
// Matrix helpers
Mat4 mat4_identity();
Mat4 mat4_mul(Mat4 a, Mat4 b);
Mat4 mat4_inverse(Mat4 m);
Mat4 mat4_translate(Vec3 v);
Vec3 vec3_cross(Vec3 a, Vec3 b);
Vec3 vec3_scale(Vec3 v, float s);
Mat4 mat4_perspective(float fov_deg, float aspect, float near, float far);
Mat4 mat4_orthographic(float left, float right, float bottom, float top, float near, float far);
Mat4 mat4_lookAt(Vec3 eye, Vec3 center, Vec3 up);
Mat4 mat4_rotate_y(float angle_rad);
Mat4 mat4_rotate_x(float angle_rad);
Mat4 mat4_rotate_z(float angle_rad);
#endif