diff options
Diffstat (limited to '')
-rw-r--r-- | src/renderer.c | 79 |
1 files changed, 1 insertions, 78 deletions
diff --git a/src/renderer.c b/src/renderer.c index 3841583..54d3bd0 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -3,90 +3,13 @@ #include "ray.h" #include <math.h> -#include <pthread.h> #include <stdio.h> #include <string.h> - -void init_camera(Camera* camera) { - camera->pos.x = 3; - camera->pos.y = 3; - camera->angle = PI / 4; -} - -static double fov = PI / 4; - -#define MOVE_SPEED 1 -#define ROTATE_SPEED PI / 2 -#define FOV_CHANGE_SPEED 1 -#define PLAYER_SIZE .1 - - -void update_camera(Camera* camera, Screen* screen) { - double rotate = 0; - - if (key_down(KEY_LEFT)) - rotate -= ROTATE_SPEED; - - if (key_down(KEY_RIGHT)) - rotate += ROTATE_SPEED; - - rotate *= screen->delta; - rotate += camera->angle; - while (rotate >= PI2) rotate -= PI2; - while (rotate < 0) rotate += PI2; - camera->angle = rotate; - - v2 forward = { cos(camera->angle), sin(camera->angle) }; - v2 left = { forward.y, -forward.x }; - v2 move = { 0, 0 }; - - if (key_down(KEY_W)) { - move.x += forward.x; - move.y += forward.y; - } - - if (key_down(KEY_S)) { - move.x -= forward.x; - move.y -= forward.y; - } - - if (key_down(KEY_A)) { - move.x += left.x; - move.y += left.y; - } - - if (key_down(KEY_D)) { - move.x -= left.x; - move.y -= left.y; - } - - if (key_down(KEY_EQUALS)) { - fov += FOV_CHANGE_SPEED * screen->delta; - } - - if (key_down(KEY_MINUS)) { - fov -= FOV_CHANGE_SPEED * screen->delta; - } - - v2 hit_pos; - bool movex, movey; - - cast_ray(camera->pos, sign(move.x) == 1 ? 0 : PI, &hit_pos); - movex = v2_dist(hit_pos, camera->pos) > PLAYER_SIZE; - - cast_ray(camera->pos, sign(move.y) == 1 ? PIH : -PIH, &hit_pos); - movey = v2_dist(hit_pos, camera->pos) > PLAYER_SIZE; - - if (movex) camera->pos.x += move.x * MOVE_SPEED * screen->delta; - if (movey) camera->pos.y += move.y * MOVE_SPEED * screen->delta; -} - static void verline(Swapchain* swapchain, int x, int y0, int y1, uint32_t color) { for (int y = y0; y <= y1; y++) { swapchain->images[swapchain->image_current][(y * swapchain->width) + x] = color; } - } void render(Screen* screen, const Camera* camera) { @@ -103,7 +26,7 @@ void render(Screen* screen, const Camera* camera) { for (int x = 0; x < screen->swapchain.width; x++) { const float xcam = (2 * (x / (float) (swapchain->width))) - 1; - const float change = fov * atan(xcam); + const float change = camera->fov * atan(xcam); const float theta = camera->angle + change; v2 hit_pos; |