Add translation and rotation
This commit is contained in:
@ -19,6 +19,30 @@ pub struct HitRecord<'material> {
|
||||
pub material: &'material Arc<Material>
|
||||
}
|
||||
|
||||
impl<'material> HitRecord<'material> {
|
||||
pub fn normalized(&mut self, ray: &Ray) {
|
||||
let dot = ray.direction().dot(&self.normal);
|
||||
let front_face = dot < 0.0;
|
||||
let normal = if front_face { self.normal } else { -self.normal };
|
||||
self.normal = normal;
|
||||
self.front_face = front_face;
|
||||
}
|
||||
/*pub fn normalized(& self) -> Self {
|
||||
let dot = ray.direction().dot(self.normal);
|
||||
let front_face = dot < 0.0;
|
||||
let normal = if front_face { self.normal } else { -self.normal };
|
||||
HitRecord {
|
||||
point: self.point,
|
||||
normal,
|
||||
t: self.t,
|
||||
u: self.u,
|
||||
v: self.v,
|
||||
front_face,
|
||||
material: self.material
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
pub trait Hittable {
|
||||
fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord>;
|
||||
fn bounding_box(&self, time0: f64, time1: f64) -> Option<Aabb>;
|
||||
@ -74,19 +98,18 @@ impl Hittable for Sphere {
|
||||
}
|
||||
let point = ray.at(root);
|
||||
let normal = (point - self.center) / self.radius;
|
||||
let dot = ray.direction().dot(&normal);
|
||||
let front_face = dot < 0.0;
|
||||
let (u, v) = Sphere::uv(&normal);
|
||||
let normal = if front_face { normal } else { -normal };
|
||||
Some(HitRecord {
|
||||
let mut rec = HitRecord {
|
||||
point,
|
||||
normal,
|
||||
t: root,
|
||||
u,
|
||||
v,
|
||||
front_face,
|
||||
front_face: false, // Will be set during normalied()
|
||||
material: &self.material
|
||||
})
|
||||
};
|
||||
rec.normalized(ray);
|
||||
Some(rec)
|
||||
}
|
||||
fn bounding_box(&self, _time0: f64, _time1: f64) -> Option<Aabb> {
|
||||
let s = Vec3::new(self.radius, self.radius, self.radius);
|
||||
|
Reference in New Issue
Block a user