diff options
author | Julian T <julian@jtle.dk> | 2021-02-03 15:34:17 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-03 15:34:17 +0100 |
commit | 8296be848319eecd43f94900d4d12414ec189166 (patch) | |
tree | d0adad5c05692a55e2957d02eb62666bd45e011f /src/core | |
parent | 32e719a517a6fea113f3e66e350c9aa60ddd98b9 (diff) |
Add simple perspective camera
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/vector3.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/core/vector3.rs b/src/core/vector3.rs index 915765d..6f4d6ab 100644 --- a/src/core/vector3.rs +++ b/src/core/vector3.rs @@ -2,7 +2,8 @@ //! //! Also add more 3d math things needed for shading and 3d calculations. use crate::{Float, Number}; -use std::ops::{Sub, Add, DivAssign}; +use std::ops::{Mul, Sub, Add, DivAssign}; +use std::fmt; #[derive(Clone, Copy)] pub struct Vector3<T: Number> { @@ -49,6 +50,17 @@ impl<T: Number> Add for Vector3<T> { } } +impl<T: Number> Mul<T> for Vector3<T> { + type Output = Self; + fn mul(self, op: T) -> Self::Output { + Self::Output::new_xyz( + self.x * op, + self.y * op, + self.z * op, + ) + } +} + impl<T: Number> DivAssign<T> for Vector3<T> { fn div_assign(&mut self, op: T) { self.x /= op; @@ -57,6 +69,12 @@ impl<T: Number> DivAssign<T> for Vector3<T> { } } +impl<T: Number> fmt::Display for Vector3<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_fmt(format_args!("[{}, {}, {}]", self.x, self.y, self.z)) + } +} + impl Vector3f { /// Calculates the length times itself /// @@ -97,4 +115,13 @@ impl Vector3f { new.norm_in(); new } + + pub fn cross(&self, op: &Self) -> Self { + Self::new_xyz( + self.y * op.z - self.z * op.y, + self.z * op.x - self.x * op.z, + self.x * op.y - self.y * op.x, + ) + + } } |