Add clipping planes to the scene
This commit is contained in:
parent
44c7b6ac1b
commit
9d929c22ba
@ -51,11 +51,21 @@ typedef struct {
|
||||
transform_t transform;
|
||||
} instance_t;
|
||||
|
||||
typedef struct {
|
||||
vec3f_t normal;
|
||||
f32 distance;
|
||||
} clipping_plane_t;
|
||||
|
||||
typedef struct {
|
||||
u64 instance_count;
|
||||
instance_t *instances;
|
||||
camera_t *camera;
|
||||
const mat3x4f_t *proj_matrix;
|
||||
clipping_plane_t near;
|
||||
clipping_plane_t left;
|
||||
clipping_plane_t right;
|
||||
clipping_plane_t bottom;
|
||||
clipping_plane_t top;
|
||||
} rasteriser_scene_t;
|
||||
|
||||
void render_scene(window_t *wnd, Arena *arena, const rasteriser_scene_t *scene);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "window/window.h"
|
||||
#include <SDL2/SDL_events.h>
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
@ -97,11 +98,40 @@ int main(void) {
|
||||
(vec4f_t){0.0f, 0.0f, 1.0f, 0.0f},
|
||||
};
|
||||
|
||||
f32 sqrt_2 = sqrtf(2.0f);
|
||||
f32 one_div_sqrt_2 = 1.0f / sqrt_2;
|
||||
f32 neg_one_div_sqrt_2 = -1.0f / sqrt_2;
|
||||
|
||||
rasteriser_scene_t scene = {
|
||||
.instance_count = ARR_LEN(instances),
|
||||
.instances = instances,
|
||||
.camera = &camera,
|
||||
.proj_matrix = &proj_matrix,
|
||||
.near =
|
||||
(clipping_plane_t){
|
||||
.normal = (vec3f_t){0.0f, 0.0f, 1.0f},
|
||||
.distance = viewport.z,
|
||||
},
|
||||
.left =
|
||||
(clipping_plane_t){
|
||||
.normal = (vec3f_t){one_div_sqrt_2, 0.0f, one_div_sqrt_2},
|
||||
.distance = 0.0f,
|
||||
},
|
||||
.right =
|
||||
(clipping_plane_t){
|
||||
.normal = (vec3f_t){neg_one_div_sqrt_2, 0.0f, one_div_sqrt_2},
|
||||
.distance = 0.0f,
|
||||
},
|
||||
.bottom =
|
||||
(clipping_plane_t){
|
||||
.normal = (vec3f_t){0.0f, one_div_sqrt_2, one_div_sqrt_2},
|
||||
.distance = 0.0f,
|
||||
},
|
||||
.top =
|
||||
(clipping_plane_t){
|
||||
.normal = (vec3f_t){0.0f, neg_one_div_sqrt_2, one_div_sqrt_2},
|
||||
.distance = 0.0f,
|
||||
},
|
||||
};
|
||||
|
||||
bool running = true;
|
||||
@ -141,7 +171,7 @@ int main(void) {
|
||||
|
||||
clear_window(&window, bg);
|
||||
|
||||
render_scene(&window, arena, &scene);
|
||||
render_scene(&window, frame_arena, &scene);
|
||||
|
||||
swap_buffers(&window);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user