Implement ability to move and rotate camera
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "vector/vec.h"
|
||||
#include "window/window.h"
|
||||
#include <SDL2/SDL_events.h>
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
@@ -10,10 +11,18 @@
|
||||
#define ARR_LEN(ARR) sizeof(ARR) / sizeof(ARR[0])
|
||||
#define RECURSION_DEPTH 3
|
||||
|
||||
typedef struct {
|
||||
vec3f_t position;
|
||||
vec3f_t rotation;
|
||||
} camera_t;
|
||||
|
||||
i32 main(i32 argc, char *argv[]) {
|
||||
colour_t bg =
|
||||
(colour_t){.rgba.r = 27, .rgba.g = 38, .rgba.b = 79, .rgba.a = 255};
|
||||
vec3f_t camera = {.x = 0.0f, .y = 0.0f, .z = 0.0f};
|
||||
camera_t camera = {
|
||||
.position = {.x = 0.0f, .y = 0.0f, .z = 0.0f},
|
||||
.rotation = {.x = 0.0f, .y = 0.0f, .z = 0.0f},
|
||||
};
|
||||
vec3f_t viewport = {.x = 1.0f, .y = 1.0f, .z = 1.0f};
|
||||
|
||||
window_t window = {0};
|
||||
@@ -107,8 +116,9 @@ i32 main(i32 argc, char *argv[]) {
|
||||
for (i32 y = h_min; y < h_max; ++y) {
|
||||
for (i32 x = w_min; x < w_max; ++x) {
|
||||
vec3f_t direction = window_to_viewport(&window, x, y, viewport);
|
||||
colour_t colour = trace_ray(camera, direction, 1, INFINITY, &scene, bg,
|
||||
RECURSION_DEPTH);
|
||||
vec3f_t rotated = vec_rotate_vec3f_t(direction, camera.rotation);
|
||||
colour_t colour = trace_ray(camera.position, rotated, 1, INFINITY,
|
||||
&scene, bg, RECURSION_DEPTH);
|
||||
set_pixel(&window, x, y, colour);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user