wip: parallelization

This commit is contained in:
djaidjai committed 2026-05-03 14:58:56 +02:00
1 parent eb90c36ae8
commit 10f9c0984d
23 files changed
+294 -211

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
use std::sync::Arc;
use crate::{
objects::{materials::traits::Material, traits::Hittable},
ray::Ray,
vec3::Vec3,
};
use super::hit::Hit;
#[derive(Debug)]
pub struct Circle {
radius: f32,
center: Vec3,
normal: Vec3,
material: Arc<dyn Material>,
}
impl Circle {
pub fn new(radius: f32, center: Vec3, normal: Vec3, material: Arc<dyn Material>) -> Self {
Self {
radius,
center,
normal: normal.get_unit(),
material,
}
}
}
impl Hittable for Circle {
fn hit(&self, r: &Ray) -> Option<Hit> {
// check if ray parallel to plane
let dot = self.normal.dot(r.dir());
if dot == 0.0 {
return None;
}
// hitpoint on plane
let t = self.normal.dot(&(self.center - r.origin())) / dot;
// hits behind camera
if t < 0. {
return None;
};
let p = r.at(t);
if (p - self.center).length() < self.radius {
return Some(Hit::new(t, p, self.normal, self.material.clone(), self.normal.dot(&r.dir()) < 0.));
}
None
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.