summaryrefslogtreecommitdiff
path: root/src/calculus.rs
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-02 16:56:59 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-02 16:56:59 +0700
commit93b24b9d01f806cf69ecee86fada9e5b9bf06182 (patch)
treec4c941acdeced6cb5b9cc51eedabc994ceda0b38 /src/calculus.rs
parentd618968b9577cbaf6306f42157be19bd2a6a6aa0 (diff)
material
Diffstat (limited to 'src/calculus.rs')
-rw-r--r--src/calculus.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/calculus.rs b/src/calculus.rs
index e1e9caf..568eb60 100644
--- a/src/calculus.rs
+++ b/src/calculus.rs
@@ -105,6 +105,20 @@ pub mod calculus {
z: self.z / mag,
}
}
+
+ pub fn is_near_zero(&self) -> bool {
+ self.x.abs() < f32::EPSILON &&
+ self.y.abs() < f32::EPSILON &&
+ self.z.abs() < f32::EPSILON
+ }
+
+ pub fn reflect(&self, normal: &Self) -> Self {
+ self.sub(
+ &normal.scalar_mul(
+ 2.0 * self.dot_prod(&normal)
+ )
+ )
+ }
}
pub struct Ray {
@@ -117,6 +131,10 @@ pub mod calculus {
// Get parametric location
self.origin.add(&self.direction.scalar_mul(t))
}
+
+ pub fn reflect(&self, normal: &Vec3) -> Vec3 {
+ self.direction.reflect(&normal)
+ }
}
pub fn deg2rad(deg: f32) -> f32 {