Files
asteroids/maths.h
2025-10-18 17:43:22 +01:00

45 lines
914 B
C

#ifndef MATHS_H
#define MATHS_H
#define PI 3.14159265358979323846264
#define MAT2_ID ((mat2_t) { { 1, 0 }, { 0, 1 } })
#define MAT3_ID ((mat3_t) { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } })
typedef struct {
float x, y;
} vec2_t;
typedef struct {
vec2_t x, y;
} mat2_t;
typedef struct {
float x, y, z;
} vec3_t;
typedef struct {
vec3_t x, y, z;
} mat3_t;
float vec2_len(vec2_t v);
vec2_t vec2_add(vec2_t v1, vec2_t v2);
vec2_t vec2_sub(vec2_t v1, vec2_t v2);
vec2_t vec2_scale(vec2_t v, float s);
vec3_t vec2_extend(vec2_t v);
vec2_t vec2_norm(vec2_t v);
float vec2_dot(vec2_t v1, vec2_t v2);
vec2_t vec3_reduce(vec3_t v);
mat2_t mat2_rotation(float theta);
vec2_t mat2_mul_vec2(mat2_t m, vec2_t v);
mat2_t mat2_mul_mat2(mat2_t m1, mat2_t m2);
mat3_t mat2_extend(mat2_t m);
mat3_t mat3_translation(vec2_t v);
vec3_t mat3_mul_vec3(mat3_t m, vec3_t v);
mat3_t mat3_mul_mat3(mat3_t m1, mat3_t m2);
#endif