use nalgebra::{Point3, Vector3};
use ray::Ray;
use std::f64::consts;
#[derive(Copy, Clone)]
pub struct Camera {
origin: Point3<f64>,
lower_left_corner: Vector3<f64>,
horizontal: Vector3<f64>,
vertical: Vector3<f64>,
}
impl Camera {
pub fn new(vert_fov: f64, aspect_ratio: f64) -> Camera {
let theta = vert_fov * consts::PI / 180.0;
let half_height = (theta / 2.0).tan();
let half_width = aspect_ratio * half_height;
Camera {
origin: Point3::new(0.0, 0.0, 0.0),
lower_left_corner: Vector3::new(-half_width, -half_height, -1.0),
horizontal: Vector3::new(2.0 * half_width, 0.0, 0.0),
vertical: Vector3::new(0.0, 2.0 * half_height, 0.0),
}
}
pub fn get_ray(&self, u: f64, v: f64) -> Ray {
let direction = self.lower_left_corner + u * self.horizontal + v * self.vertical;
Ray::new(self.origin.clone(), direction)
}
}