const vec = @import("./vec.zig");

const Ray = @import("./ray.zig").Ray;

const Point3 = vec.Point3;
const Vec3 = vec.Vec3;

pub const Camera = struct {
    origin: Point3,
    lower_left_corner: Point3,
    horizontal: Vec3,
    vertical: Vec3,

    pub fn init() Camera {
        const aspect_ratio = 16.0 / 9.0;
        const viewport_height = 2.0;
        const viewport_width = aspect_ratio * viewport_height;
        const focal_length = 1.0;
        const origin = Point3.init(0, 0, 0);
        const horizontal = Vec3.init(viewport_width, 0.0, 0.0);
        const vertical = Vec3.init(0.0, viewport_height, 0.0);

        return Camera{
            .origin = origin,
            .horizontal = horizontal,
            .vertical = vertical,
            .lower_left_corner = origin.sub(horizontal.scale(0.5)).sub(vertical.scale(0.5)).sub(Vec3.init(0, 0, focal_length)),
        };
    }
    pub fn get_ray(camera: Camera, u: f32, v: f32) Ray {
        return Ray.init(camera.origin, camera.lower_left_corner.add(camera.horizontal.scale(u).add(camera.vertical.scale(v).sub(camera.origin))));
    }
};
