Add perspective projection support
This commit is contained in:
parent
fee04607a7
commit
34d0d17b76
@ -204,7 +204,8 @@ 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) {
|
||||
RenderType type, ColourType colour_type,
|
||||
ProjectionType projection) {
|
||||
Triangle triangle;
|
||||
|
||||
for (u64 i = 0; i < model->triangles->count; ++i) {
|
||||
@ -215,12 +216,13 @@ void render_model(const Model *model, Render *render, Colour colour,
|
||||
.b = rand() % UINT8_MAX,
|
||||
.a = 255};
|
||||
}
|
||||
render_triangle(&triangle, model, render, colour, type);
|
||||
render_triangle(&triangle, model, render, colour, type, projection);
|
||||
}
|
||||
}
|
||||
|
||||
internal void render_triangle(const Triangle *triangle, const Model *model,
|
||||
Render *render, Colour colour, RenderType type) {
|
||||
Render *render, Colour colour, RenderType type,
|
||||
ProjectionType projection) {
|
||||
Image *img = &(render->img);
|
||||
Vertex vertices[TRIANGLE_VERTICES] = {
|
||||
list_get(model->vertices, triangle->p0),
|
||||
|
10
src/obj.h
10
src/obj.h
@ -47,6 +47,13 @@ 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);
|
||||
@ -68,6 +75,7 @@ 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);
|
||||
RenderType type, ColourType colour_type,
|
||||
ProjectionType projection);
|
||||
|
||||
#endif // OBJ_H
|
||||
|
Loading…
Reference in New Issue
Block a user