use std::ops::{Add, Mul}; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct Vec3 { pub x: T, pub y: T, pub z: T, } impl Vec3 { pub fn new(x: T, y: T, z: T) -> Self { Vec3 { x, y, z } } } /// Vector addition impl Add> for Vec3 where T: Add, { type Output = Vec3; fn add(self, rhs: Vec3) -> Self::Output { Vec3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z) } } /// Scalar multiplication impl Mul for Vec3 where T: Mul, U: Copy, { type Output = Vec3; fn mul(self, rhs: U) -> Self::Output { Vec3::new(self.x * rhs, self.y * rhs, self.z * rhs) } } pub struct Sphere { pub center: Vec3, pub radius: f64, } pub enum Object { Sphere(Sphere), Cylinder { center: Vec3, direction: Vec3, radius: f64, length: f64, }, } pub struct Scene { pub eye_pos: Vec3, pub view_dir: Vec3, pub up_dir: Vec3, /// Horizontal field of view (in degrees) pub hfov: f64, pub image_width: usize, pub image_height: usize, /// Background color pub bkg_color: Vec3, /// Material color pub mtl_color: Vec3, pub objects: Vec, }