summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-01 18:41:07 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2025-03-01 18:41:07 +0700
commit5e61a588a59008705846326956ff0b1f8ee43b16 (patch)
tree7436a2140247465c9559853c99ce43e030a05b81
parent084875ac8e9aa12cf6cc1892def9e4bc5fd4cdda (diff)
fix normal
-rw-r--r--src/calculus.rs2
-rw-r--r--src/object.rs4
-rw-r--r--src/renderer.rs6
3 files changed, 6 insertions, 6 deletions
diff --git a/src/calculus.rs b/src/calculus.rs
index 67138d1..c9b0574 100644
--- a/src/calculus.rs
+++ b/src/calculus.rs
@@ -1,5 +1,5 @@
pub mod calculus {
- #[derive(Copy, Clone)]
+ #[derive(Copy, Clone, Debug)]
pub struct Vec3 {
pub x: f32,
pub y: f32,
diff --git a/src/object.rs b/src/object.rs
index ff965f0..0da9148 100644
--- a/src/object.rs
+++ b/src/object.rs
@@ -37,7 +37,7 @@ pub struct Sphere {
impl Sphere {
pub fn new(center: Vec3, radius: f32) -> Self {
- let r = f32::max(0.0, radius);
+ let radius = f32::max(0.0, radius);
Self { center, radius }
}
}
@@ -65,7 +65,7 @@ impl Hittable for Sphere {
rec.t = root;
rec.position = r.at(rec.t);
- let outward_normal = rec.normal
+ let outward_normal = rec.position
.sub(&self.center)
.scalar_mul(1.0 / self.radius);
rec.set_face_normal(r, outward_normal);
diff --git a/src/renderer.rs b/src/renderer.rs
index 2fb76d2..4936d9e 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -43,9 +43,9 @@ pub fn render(display_buffer: &mut DisplayBuffer) {
Sphere::new(Point3::new(0.0, 0.0, -1.0), 0.5)
);
- // world.push(
- // Sphere::new(Point3::new(0.0, -100.5, -1.0), 100.0)
- // );
+ world.push(
+ Sphere::new(Point3::new(0.0, -100.5, -1.0), 100.0)
+ );
(0..IMG_HEIGHT).for_each(|j| {