diff options
author | Julian T <julian@jtle.dk> | 2021-02-03 17:29:27 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-03 17:29:27 +0100 |
commit | 977b0e4152433b2a68e2b97fe5fe2c0ff6fb20d8 (patch) | |
tree | 9c1eccef2ede2507e7d29a0daf44d56c76036415 /src/core | |
parent | 8296be848319eecd43f94900d4d12414ec189166 (diff) |
Can render a simple sphere, without shading
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/spectrum.rs | 6 | ||||
-rw-r--r-- | src/core/vector2.rs | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/core/spectrum.rs b/src/core/spectrum.rs index c72a251..fb82a9e 100644 --- a/src/core/spectrum.rs +++ b/src/core/spectrum.rs @@ -12,9 +12,13 @@ pub struct Spectrum { } impl Spectrum { - fn new_rgb(r: Float, g: Float, b: Float) -> Spectrum { + pub fn new_rgb(r: Float, g: Float, b: Float) -> Spectrum { Spectrum { c: [r, g, b] } } + + pub fn to_rgb(&self, scale: Float) -> (Float, Float, Float) { + (self.c[0] * scale, self.c[1] * scale, self.c[2] * scale) + } } impl std::ops::Mul<Float> for &Spectrum { diff --git a/src/core/vector2.rs b/src/core/vector2.rs index 5afa0f2..3aadb46 100644 --- a/src/core/vector2.rs +++ b/src/core/vector2.rs @@ -3,6 +3,7 @@ //! This is implemented generictly with types that fit in the Number trait use crate::{Float, Number}; use std::ops::{Sub, Add}; +use std::fmt; #[derive(Clone, Copy)] pub struct Vector2<T: Number> { @@ -43,6 +44,12 @@ impl<T: Number> Add for Vector2<T> { } } +impl<T: Number> fmt::Display for Vector2<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_fmt(format_args!("[{}, {}]", self.x, self.y)) + } +} + impl Vector2f { pub fn ceil(&self) -> Self { Self::new_xy( |