Update vector and matrix types
This commit is contained in:
parent
bb6b0e3e5d
commit
4b178de784
@ -5,8 +5,6 @@
|
|||||||
#include "typed_list.h"
|
#include "typed_list.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define V3_ELEM_COUNT 3
|
|
||||||
|
|
||||||
typedef struct i64x2 V2i;
|
typedef struct i64x2 V2i;
|
||||||
struct i64x2 {
|
struct i64x2 {
|
||||||
i64 x;
|
i64 x;
|
||||||
@ -33,7 +31,7 @@ struct f32x2 {
|
|||||||
|
|
||||||
typedef union f32x3 V3f;
|
typedef union f32x3 V3f;
|
||||||
union f32x3 {
|
union f32x3 {
|
||||||
f32 elements[V3_ELEM_COUNT];
|
f32 elements[3];
|
||||||
struct {
|
struct {
|
||||||
union {
|
union {
|
||||||
f32 x;
|
f32 x;
|
||||||
@ -50,12 +48,15 @@ union f32x3 {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct f32x4 V4f;
|
typedef union f32x4 V4f;
|
||||||
struct f32x4 {
|
union f32x4 {
|
||||||
f32 x;
|
f32 elements[4];
|
||||||
f32 y;
|
struct {
|
||||||
f32 z;
|
f32 x;
|
||||||
f32 w;
|
f32 y;
|
||||||
|
f32 z;
|
||||||
|
f32 w;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct u64x3 V3u;
|
typedef struct u64x3 V3u;
|
||||||
@ -65,19 +66,25 @@ struct u64x3 {
|
|||||||
u64 z;
|
u64 z;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct f32_3x3 M3x3f;
|
typedef union f32_3x3 M3x3f;
|
||||||
struct f32_3x3 {
|
union f32_3x3 {
|
||||||
V3f row0;
|
V3f rows[3];
|
||||||
V3f row1;
|
struct {
|
||||||
V3f row2;
|
V3f row0;
|
||||||
|
V3f row1;
|
||||||
|
V3f row2;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct f32_4x4 M4x4f;
|
typedef union f32_4x4 M4x4f;
|
||||||
struct f32_4x4 {
|
union f32_4x4 {
|
||||||
V4f row0;
|
V4f rows[4];
|
||||||
V4f row1;
|
struct {
|
||||||
V4f row2;
|
V4f row0;
|
||||||
V4f row3;
|
V4f row1;
|
||||||
|
V4f row2;
|
||||||
|
V4f row3;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
MAKE_LIST_TYPE(V3f);
|
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 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 lookat(V3f eye, V3f target, V3f up);
|
||||||
M4x4f projection(f32 coeff);
|
M4x4f projection(f32 coeff);
|
||||||
M4x4f viewport(f32 x, f32 y, u64 w, u64 h);
|
M4x4f viewport(f32 x, f32 y, u64 w, u64 h);
|
||||||
|
Loading…
Reference in New Issue
Block a user