Allow camera position and target position to vary

This commit is contained in:
Camden Dixie O'Brien
2025-09-23 15:35:26 +01:00
parent 483dab82ef
commit 4b093f43b6
3 changed files with 32 additions and 25 deletions

24
demo.c
View File

@@ -7,22 +7,23 @@
#define W 800
#define H 600
#define FOV 120
#define FOV 90
#define SAMPLES_PER_PIXEL 100
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))
static const vec3_t camera_pos = { 0.0, 0.0, 0.0 };
static const vec3_t camera_pos = { 0.0, 1.5, -2.0 };
static const vec3_t camera_target = { 0.0, 1.0, 1.0 };
static const obj_t scene[] = {
SPHERE(1.0, 0.0, -3.0, 1.0, LAMBERTIAN(0.6, 0.2, 0.8)),
SPHERE(-0.8, 0.0, -3.8, 1.0, LAMBERTIAN(1.0, 1.0, 1.0)),
SPHERE(-1.0, -0.8, -2.6, 0.2, LAMBERTIAN(0.2, 0.9, 0.3)),
SPHERE(0.3, -0.7, -1.8, 0.3, LAMBERTIAN(0.9, 0.6, 0.2)),
SPHERE(-1.6, -0.8, -2.0, 0.2, REFLECTIVE(1.0, 0.9, 0.4, 0.0)),
SPHERE(-6.0, 5.0, -5.0, 6.0, REFLECTIVE(0.9, 0.9, 0.9, 0.05)),
SPHERE(-0.7, -0.75, -1.5, 0.25, DIELECTRIC(1.5)),
SPHERE(0.0, -1001.0, 0.0, 1000.0, LAMBERTIAN(0.3, 0.3, 0.3)),
SPHERE(1.0, 1.0, 3.0, 1.0, LAMBERTIAN(0.6, 0.2, 0.8)),
SPHERE(-0.8, 1.0, 3.8, 1.0, LAMBERTIAN(1.0, 1.0, 1.0)),
SPHERE(-1.0, 0.2, 2.6, 0.2, LAMBERTIAN(0.2, 0.9, 0.3)),
SPHERE(0.3, 0.3, 1.8, 0.3, LAMBERTIAN(0.9, 0.6, 0.2)),
SPHERE(-1.6, 0.2, 2.0, 0.2, REFLECTIVE(1.0, 0.9, 0.4, 0.0)),
SPHERE(-6.0, 6.0, 5.0, 6.0, REFLECTIVE(0.9, 0.9, 0.9, 0.05)),
SPHERE(-0.7, 0.25, 1.5, 0.25, DIELECTRIC(1.5)),
SPHERE(0.0, -1000.0, 0.0, 1000.0, LAMBERTIAN(0.3, 0.3, 0.3)),
};
static pix_t pixbuf[W * H];
@@ -30,7 +31,8 @@ static pix_t pixbuf[W * H];
int main()
{
img_t img = { .pix = pixbuf };
camera_t camera = camera_init(camera_pos, FOV, W, H, SAMPLES_PER_PIXEL);
camera_t camera = camera_init(
camera_pos, camera_target, FOV, W, H, SAMPLES_PER_PIXEL);
camera_render(&camera, scene, NELEMS(scene), &img);
ff_write(STDOUT_FILENO, img);