propper multithreading

This commit is contained in:
2023-12-03 22:12:46 -05:00
parent d8488f24f7
commit 0eff7fc694
10 changed files with 391 additions and 201 deletions
+19 -1
View File
@@ -1,4 +1,9 @@
use crate::{bvh::AABB, material::Material, primitive::*};
use crate::{
bvh::AABB,
material::Material,
primitive::{self, *},
ray::{Intersection, Ray},
};
use nalgebra::{Matrix4, Vector3};
use std::sync::Arc;
@@ -98,4 +103,17 @@ impl Node {
self.inv_model = self.model.try_inverse().unwrap();
self.aabb.transform_mut(&self.model);
}
// Intersection of a ray, will convert to model coords and check
pub fn intersect_ray(&self, ray: &Ray) -> Option<Intersection> {
let ray = ray.transform(&self.inv_model); //Transform from world coordinates
if let Some(mut intersect) = self.primitive.intersect_ray(&ray) {
intersect.transform_mut(&self.model, &self.inv_model); //Transform to world coords
return Some(intersect);
}
return None;
}
//Gets the bounding box in world coords
pub fn get_world_aabb(&self) -> AABB {
return self.aabb.clone();
}
}