Compare commits
No commits in common. "34d0d17b76b0dd90f7620ce5a73c25a2e75c7b69" and "b6e7b9c21378c8b18d730b4ce8bd0381741a6a49" have entirely different histories.
34d0d17b76
...
b6e7b9c213
37
src/obj.c
37
src/obj.c
@ -12,7 +12,6 @@
|
||||
#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})
|
||||
@ -63,14 +62,6 @@ 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;
|
||||
@ -85,17 +76,8 @@ 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,
|
||||
ProjectionType projection);
|
||||
Render *render, Colour colour, RenderType type);
|
||||
internal void fill_triangle(Render *render, Vertex vertices[TRIANGLE_VERTICES],
|
||||
TexCoord coordinates[TRIANGLE_VERTICES],
|
||||
Colour colour, f32 intensity, Image *texture);
|
||||
@ -112,15 +94,6 @@ 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;
|
||||
@ -204,8 +177,7 @@ bool init_render(Arena *arena, Render *render, u64 width, u64 height) {
|
||||
}
|
||||
|
||||
void render_model(const Model *model, Render *render, Colour colour,
|
||||
RenderType type, ColourType colour_type,
|
||||
ProjectionType projection) {
|
||||
RenderType type, ColourType colour_type) {
|
||||
Triangle triangle;
|
||||
|
||||
for (u64 i = 0; i < model->triangles->count; ++i) {
|
||||
@ -216,13 +188,12 @@ void render_model(const Model *model, Render *render, Colour colour,
|
||||
.b = rand() % UINT8_MAX,
|
||||
.a = 255};
|
||||
}
|
||||
render_triangle(&triangle, model, render, colour, type, projection);
|
||||
render_triangle(&triangle, model, render, colour, type);
|
||||
}
|
||||
}
|
||||
|
||||
internal void render_triangle(const Triangle *triangle, const Model *model,
|
||||
Render *render, Colour colour, RenderType type,
|
||||
ProjectionType projection) {
|
||||
Render *render, Colour colour, RenderType type) {
|
||||
Image *img = &(render->img);
|
||||
Vertex vertices[TRIANGLE_VERTICES] = {
|
||||
list_get(model->vertices, triangle->p0),
|
||||
|
10
src/obj.h
10
src/obj.h
@ -47,13 +47,6 @@ typedef enum {
|
||||
COUNT_COLOUR_TYPE,
|
||||
} ColourType;
|
||||
|
||||
typedef enum {
|
||||
PROJECTION_TYPE_ORTHOGRAPHIC,
|
||||
PROJECTION_TYPE_PERSPECTIVE,
|
||||
|
||||
COUNT_PROJECTION_TYPE,
|
||||
} ProjectionType;
|
||||
|
||||
MAKE_LIST_TYPE(Vertex);
|
||||
MAKE_LIST_TYPE(TexCoord);
|
||||
MAKE_LIST_TYPE(Triangle);
|
||||
@ -75,7 +68,6 @@ struct render {
|
||||
Model load_obj_file(Arena *arena, const char *filename, const char *texture);
|
||||
bool init_render(Arena *arena, Render *render, u64 width, u64 height);
|
||||
void render_model(const Model *model, Render *render, Colour colour,
|
||||
RenderType type, ColourType colour_type,
|
||||
ProjectionType projection);
|
||||
RenderType type, ColourType colour_type);
|
||||
|
||||
#endif // OBJ_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user