Files
batomorph/demo.c

50 lines
1.2 KiB
C

#include "camera.h"
#include "ff.h"
#include "obj.h"
#include "rng.h"
#include <unistd.h>
#define W 800
#define H 600
#define FOV 90
#define SAMPLES_PER_PIXEL 100
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[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 vec3_t sky = { 0.6, 0.7, 1.0 };
static const obj_t objs[] = {
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];
int main()
{
const scene_t scene = {
.sky_colour = sky,
.objs = objs,
.obj_count = NELEMS(objs),
};
img_t img = { .pix = pixbuf };
camera_t camera = camera_init(
camera_pos, camera_target, FOV, W, H, SAMPLES_PER_PIXEL);
camera_render(&camera, &scene, &img);
ff_write(STDOUT_FILENO, img);
return 0;
}