From 02fedfc9653cb37219849de7dae14ae13d2f6c36 Mon Sep 17 00:00:00 2001 From: Julian T Date: Wed, 4 Aug 2021 17:21:03 +0200 Subject: Add translation and move center position from sphere --- src/core/bound3.rs | 8 +++++++- src/core/vector3.rs | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/bound3.rs b/src/core/bound3.rs index ce6bb09..8c467c0 100644 --- a/src/core/bound3.rs +++ b/src/core/bound3.rs @@ -64,6 +64,13 @@ impl Bound3 { let diag = self.max - self.min; diag.x * diag.y * diag.z } + + pub fn offset(&self, offset: Vector3) -> Self { + Self { + min: self.min + offset, + max: self.max + offset, + } + } } impl Bound3f { @@ -86,7 +93,6 @@ impl Bound3f { /// assert!(!b.intersect(&r3, 0.0, INFTY)); /// ``` pub fn intersect(&self, ray: &Ray, t_min: Float, t_max: Float) -> bool { - println!("BIN: {} -> {}", self.min, self.max); // Method stolen from Ray tracing the next week. // They mention its from pixar for i in 0..3 { diff --git a/src/core/vector3.rs b/src/core/vector3.rs index 1cc6f60..9ba0191 100644 --- a/src/core/vector3.rs +++ b/src/core/vector3.rs @@ -2,7 +2,7 @@ //! //! Also add more 3d math things needed for shading and 3d calculations. use crate::{Float, Number, NEAR_ZERO}; -use std::ops::{Mul, Sub, Add, DivAssign, Neg, AddAssign, Index}; +use std::ops::{Mul, Sub, Add, Div, DivAssign, Neg, AddAssign, Index}; use std::fmt; #[derive(Clone, Copy)] @@ -73,6 +73,17 @@ impl Mul for Vector3 { } } +impl Div for Vector3 { + type Output = Self; + fn div(self, op: T) -> Self::Output { + Self::Output::new_xyz( + self.x / op, + self.y / op, + self.z / op, + ) + } +} + impl Neg for Vector3 { type Output = Self; -- cgit v1.2.3