aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ray.rs7
-rw-r--r--src/core/spectrum.rs2
-rw-r--r--src/core/vector3.rs10
3 files changed, 18 insertions, 1 deletions
diff --git a/src/core/ray.rs b/src/core/ray.rs
index c944184..0517e50 100644
--- a/src/core/ray.rs
+++ b/src/core/ray.rs
@@ -8,6 +8,13 @@ pub struct Ray {
}
impl Ray {
+ pub fn new(origin: Vector3f, direction: Vector3f) -> Ray {
+ Ray {
+ origin,
+ direction,
+ }
+ }
+
pub fn new_to(origin: Vector3f, target: Vector3f) -> Ray {
let dir = (target - origin).norm();
Ray {
diff --git a/src/core/spectrum.rs b/src/core/spectrum.rs
index 9cca7dc..c33d3af 100644
--- a/src/core/spectrum.rs
+++ b/src/core/spectrum.rs
@@ -12,6 +12,8 @@ pub struct Spectrum {
}
impl Spectrum {
+ pub const ZERO: Self = Spectrum { c: [0.0; 3] };
+
pub fn new_rgb(r: Float, g: Float, b: Float) -> Spectrum {
Spectrum { c: [r, g, b] }
}
diff --git a/src/core/vector3.rs b/src/core/vector3.rs
index ff5a678..9d6c1cf 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};
+use std::ops::{Mul, Sub, Add, DivAssign, Neg, AddAssign};
use std::fmt;
#[derive(Clone, Copy)]
@@ -85,6 +85,14 @@ impl<T: Number> Neg for Vector3<T> {
}
}
+impl<T: Number> AddAssign<&Self> for Vector3<T> {
+ fn add_assign(&mut self, op: &Self) {
+ self.x += op.x;
+ self.y += op.y;
+ self.z += op.z;
+ }
+}
+
impl<T: Number> DivAssign<T> for Vector3<T> {
fn div_assign(&mut self, op: T) {
self.x /= op;