ray-trace-w1/src/types_defined.rs

66 lines
1.2 KiB
Rust

use std::{fs::File, io::{BufWriter}};
use crate::material::{MaterialKind};
use crate::ppm_writer::PPMWriter;
/*
* [3]
*/
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
pub type Point = Vec3;
pub type Color = Vec3;
/*
fn: P(t) = t*b
*/
#[derive(Debug)]
pub struct Ray {
pub point: Point,
pub direction: Vec3,
}
pub struct HitRecord {
pub t: f32,
pub p: Vec3,
pub normal: Vec3,
pub front_face: bool,
pub material: Option<MaterialKind>,
}
pub struct Camera<'a> {
pub image_width: i32,
pub image_height: i32,
// pub aspect_ratio: f32,
// pub viewport_width: f32,
// pub viewport_height: f32,
pub camera_center: Point,
// pub focal_length: Vec3,
// pub viewport_u: Vec3,
// pub viewport_v: Vec3,
pub viewport_u_delta: Vec3,
pub viewport_v_delta: Vec3,
pub viewport_top_left_pixel_center: Vec3,
// sample times
pub sample_times: i8,
pub reflect_depth: i8,
// writer
pub ppm_file_writer: &'a mut PPMWriter<BufWriter<File>>
}
/*
/////////////
// for test
/////////////
*/
pub struct Sphere {
pub center: Point,
pub radius: f32,
pub material: Option<MaterialKind>,
}