Specify camera FOV instead of viewport height

This commit is contained in:
Camden Dixie O'Brien
2025-09-22 16:23:51 +01:00
parent 157bf8d93e
commit 22a8b3a009
3 changed files with 13 additions and 5 deletions

View File

@@ -9,6 +9,10 @@
#include <stdio.h>
#include <threads.h>
#ifndef M_PI
#define M_PI 3.14159265258979323846264
#endif
#define MAX_ITER 10
#define MIN_T 1e-6
#define SAMPLE_STDDEV 0.333
@@ -113,12 +117,16 @@ static int render_thread(void *arg)
}
camera_t camera_init(
vec3_t pos, double focal_len, double viewport_height, uint32_t img_width,
vec3_t pos, double focal_len, double fov, uint32_t img_width,
uint32_t img_height, unsigned samples_per_pixel)
{
const double aspect = (double)img_width / (double)img_height;
const double fov_rad = M_PI * fov / 180.0;
const double viewport_height = focal_len * tan(fov_rad / 2);
const double viewport_width = viewport_height * aspect;
const vec3_t viewport_disp = { 0, 0, focal_len };
const vec3_t u = { viewport_width, 0, 0 };
const vec3_t v = { 0, -viewport_height, 0 };
const vec3_t topleft = vec3_sub(