csci5607/assignment-1/src/scene_data.rs

75 lines
1.2 KiB
Rust
Raw Normal View History

2023-01-31 07:15:22 +00:00
use std::ops::{Add, Mul};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Vec3<T = f64> {
pub x: T,
pub y: T,
pub z: T,
}
impl<T> Vec3<T> {
pub fn new(x: T, y: T, z: T) -> Self {
Vec3 { x, y, z }
}
}
/// Vector addition
impl<T> Add<Vec3<T>> for Vec3<T>
where
T: Add<T>,
{
type Output = Vec3<T::Output>;
fn add(self, rhs: Vec3<T>) -> Self::Output {
Vec3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
}
}
/// Scalar multiplication
impl<T, U> Mul<U> for Vec3<T>
where
T: Mul<U, Output = U>,
U: Copy,
{
type Output = Vec3<U>;
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<Object>,
}