Add V4f, Mat4x4f and a basic static camera matrix

This commit is contained in:
Abdelrahman Said 2024-08-11 17:56:31 +01:00
parent b6e7b9c213
commit fee04607a7

View File

@ -12,6 +12,7 @@
#include <string.h>
#define TRIANGLE_VERTICES 3
#define CAMERA_DISTANCE 5.0f
#define V2(T, ELEM_T, X0, Y0, X1, Y1) \
((T){(ELEM_T)X1 - (ELEM_T)X0, (ELEM_T)Y1 - (ELEM_T)Y0})
@ -62,6 +63,14 @@ struct f32x3 {
f32 z;
};
typedef struct f32x4 V4f;
struct f32x4 {
f32 x;
f32 y;
f32 z;
f32 w;
};
typedef struct u64x3 V3u;
struct u64x3 {
u64 x;
@ -76,8 +85,17 @@ struct f32_3x3 {
V3f row2;
};
typedef struct f32_4x4 M4x4f;
struct f32_4x4 {
V4f row0;
V4f row1;
V4f row2;
V4f row3;
};
internal void render_triangle(const Triangle *triangle, const Model *model,
Render *render, Colour colour, RenderType type);
Render *render, Colour colour, RenderType type,
ProjectionType projection);
internal void fill_triangle(Render *render, Vertex vertices[TRIANGLE_VERTICES],
TexCoord coordinates[TRIANGLE_VERTICES],
Colour colour, f32 intensity, Image *texture);
@ -94,6 +112,15 @@ internal u64 ndc_to_image_coordinate(f32 value, u64 max);
V3f g_light_dir = {0.0f, 0.0f, -1.0f};
// clang-format off
M4x4f g_cam_matrix = {
.row0 = {1.0f, 0.0f, 0.0f, 0.0f},
.row1 = {0.0f, 1.0f, 0.0f, 0.0f},
.row2 = {0.0f, 0.0f, 1.0f, 0.0f},
.row3 = {0.0f, 0.0f, -1.0f / CAMERA_DISTANCE, 1.0f},
};
// clang-format on
Model load_obj_file(Arena *arena, const char *filename, const char *texture) {
if (!arena) {
return NULL_MODEL;