Update vector and matrix types

This commit is contained in:
Abdelrahman Said 2024-08-31 22:23:18 +01:00
parent bb6b0e3e5d
commit 4b178de784

View File

@ -5,8 +5,6 @@
#include "typed_list.h"
#include <math.h>
#define V3_ELEM_COUNT 3
typedef struct i64x2 V2i;
struct i64x2 {
i64 x;
@ -33,7 +31,7 @@ struct f32x2 {
typedef union f32x3 V3f;
union f32x3 {
f32 elements[V3_ELEM_COUNT];
f32 elements[3];
struct {
union {
f32 x;
@ -50,12 +48,15 @@ union f32x3 {
};
};
typedef struct f32x4 V4f;
struct f32x4 {
f32 x;
f32 y;
f32 z;
f32 w;
typedef union f32x4 V4f;
union f32x4 {
f32 elements[4];
struct {
f32 x;
f32 y;
f32 z;
f32 w;
};
};
typedef struct u64x3 V3u;
@ -65,19 +66,25 @@ struct u64x3 {
u64 z;
};
typedef struct f32_3x3 M3x3f;
struct f32_3x3 {
V3f row0;
V3f row1;
V3f row2;
typedef union f32_3x3 M3x3f;
union f32_3x3 {
V3f rows[3];
struct {
V3f row0;
V3f row1;
V3f row2;
};
};
typedef struct f32_4x4 M4x4f;
struct f32_4x4 {
V4f row0;
V4f row1;
V4f row2;
V4f row3;
typedef union f32_4x4 M4x4f;
union f32_4x4 {
V4f rows[4];
struct {
V4f row0;
V4f row1;
V4f row2;
V4f row3;
};
};
MAKE_LIST_TYPE(V3f);
@ -233,6 +240,8 @@ MAKE_LIST_TYPE(V2f);
#define project_vec4(V) ((V3f){.x = V.x / V.w, .y = V.y / V.w, .z = V.z / V.w})
#define mat_access(MAT, i, j) (MAT.rows[i].elements[j])
M4x4f lookat(V3f eye, V3f target, V3f up);
M4x4f projection(f32 coeff);
M4x4f viewport(f32 x, f32 y, u64 w, u64 h);