Skip to content

Commit

Permalink
feat: added Y rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wafelack committed Dec 28, 2020
1 parent 9a93a2f commit 2244ed9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/objects/hittable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ impl Texture for ImageTexture {
)
}
}

0 comments on commit 2244ed9

Please sign in to comment.