From 2244ed9a971c5e1fa1a42a949727ba85e2495737 Mon Sep 17 00:00:00 2001 From: Wafelack Date: Mon, 28 Dec 2020 12:38:44 +0100 Subject: [PATCH] feat: added Y rotation --- src/objects/hittable.rs | 23 +++++++++++++++++++++-- src/texture.rs | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/objects/hittable.rs b/src/objects/hittable.rs index 06ca1ce..66c1257 100644 --- a/src/objects/hittable.rs +++ b/src/objects/hittable.rs @@ -146,10 +146,29 @@ impl Hittable for RotateY { let mut direction = r.direction(); origin[0] = self.cos_theta * r.origin()[0] - self.sin_theta * r.origin()[2]; - origin[0] = self.sin_theta * r.origin()[0] + self.cos_theta * r.origin()[2]; + origin[2] = self.sin_theta * r.origin()[0] + self.cos_theta * r.origin()[2]; direction[0] = self.cos_theta * r.direction()[0] - self.sin_theta * r.direction()[2]; - direction[0] = self.sin_theta * r.direction()[0] + self.cos_theta * r.direction()[2]; + direction[2] = self.sin_theta * r.direction()[0] + self.cos_theta * r.direction()[2]; + + let rotated_r = Ray::new(origin, direction, r.time()); + + if !self.ptr.hit(&rotated_r, t_min, t_max, rec) { + return false; + } + + let mut p = rec.p; + let mut normal = rec.normal; + + p[0] = self.cos_theta * rec.p[0] + self.sin_theta * rec.p[2]; + p[2] = -self.sin_theta * rec.p[0] + self.cos_theta * rec.p[2]; + + normal[0] = self.cos_theta * rec.normal[0] + self.sin_theta * rec.normal[2]; + normal[2] = -self.sin_theta * rec.normal[0] + self.cos_theta * rec.normal[2]; + + rec.p = p; + + rec.set_face_normal(rotated_r, normal); true } diff --git a/src/texture.rs b/src/texture.rs index 7490fa8..b88f679 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -167,3 +167,4 @@ impl Texture for ImageTexture { ) } } +