-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
418b912
commit 1a1c755
Showing
4 changed files
with
85 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use nalgebra::{Point3, Vector3}; | ||
use std::ops::{Add, Mul}; | ||
|
||
pub struct Ray { | ||
pub orig: Point3<f64>, | ||
pub dir: Vector3<f64>, | ||
} | ||
|
||
impl Ray { | ||
pub fn new(orig: Point3<f64>, dir: Vector3<f64>) -> Self { | ||
Self { orig, dir } | ||
} | ||
|
||
pub fn at(&self, t: f64) -> Point3<f64> { | ||
self.orig + t * self.dir | ||
} | ||
} | ||
|
||
pub struct Color { | ||
pub r: f64, | ||
pub g: f64, | ||
pub b: f64, | ||
} | ||
|
||
impl Color { | ||
pub fn new(r: f64, g: f64, b: f64) -> Self { | ||
Self { r, g, b } | ||
} | ||
|
||
pub fn from(vec: Vector3<f64>) -> Self { | ||
Self { | ||
r: vec.x, | ||
g: vec.y, | ||
b: vec.z, | ||
} | ||
} | ||
} | ||
|
||
impl Add for Color { | ||
type Output = Self; | ||
|
||
fn add(self, rhs: Self) -> Self { | ||
Self { | ||
r: self.r + rhs.r, | ||
g: self.g + rhs.g, | ||
b: self.b + rhs.b, | ||
} | ||
} | ||
} | ||
|
||
impl Mul<f64> for Color { | ||
type Output = Self; | ||
|
||
fn mul(self, rhs: f64) -> Self { | ||
Self { | ||
r: self.r * rhs, | ||
g: self.g * rhs, | ||
b: self.b * rhs, | ||
} | ||
} | ||
} | ||
|
||
impl Mul<Color> for f64 { | ||
type Output = Color; | ||
|
||
fn mul(self, rhs: Color) -> Color { | ||
Color { | ||
r: self * rhs.r, | ||
g: self * rhs.g, | ||
b: self * rhs.b, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.