From da1c3949a449f3fafe579c62ff6b14ffd993a197 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 21 Feb 2021 18:01:56 +0100 Subject: Add 3d bounding box and merged SceneIntersection and Intersection --- src/core/vector3.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/core/vector3.rs') diff --git a/src/core/vector3.rs b/src/core/vector3.rs index e26c07c..1cc6f60 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}; +use std::ops::{Mul, Sub, Add, DivAssign, Neg, AddAssign, Index}; use std::fmt; #[derive(Clone, Copy)] @@ -107,6 +107,20 @@ impl fmt::Display for Vector3 { } } +// Ohh god +impl Index for Vector3 { + type Output = T; + + fn index(&self, i: u32) -> &Self::Output { + match i { + 0 => &self.x, + 1 => &self.y, + 2 => &self.z, + _ => panic!("index out of bounds: index {} is not possible with 3d vector", i) + } + } +} + impl Vector3f { pub const ZERO: Self = Vector3f {x: 0.0, y: 0.0, z: 0.0}; -- cgit v1.2.3