aboutsummaryrefslogtreecommitdiff
path: root/src/core/vector3.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-01-30 15:37:07 +0100
committerJulian T <julian@jtle.dk>2021-01-30 15:37:07 +0100
commit86303936ab3180828b984ebb256bab8e69dab5cf (patch)
treee4bfb08d9c73edd12aef944e0d698c03753032da /src/core/vector3.rs
parentfdb3e8cb8d53449c107388e143345beae162f95e (diff)
Finished initial film, reorganization and started work on shapes
Diffstat (limited to 'src/core/vector3.rs')
-rw-r--r--src/core/vector3.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/core/vector3.rs b/src/core/vector3.rs
new file mode 100644
index 0000000..da09ceb
--- /dev/null
+++ b/src/core/vector3.rs
@@ -0,0 +1,47 @@
+use crate::{Float, Number};
+use std::ops::{Sub, Add};
+
+#[derive(Clone, Copy)]
+pub struct Vector3<T: Number> {
+ pub x: T,
+ pub y: T,
+ pub z: T,
+}
+
+pub type Vector3f = Vector3<Float>;
+
+impl<T: Number> Vector3<T> {
+ pub fn new(initial: T) -> Vector3<T> {
+ Vector3 {
+ x: initial,
+ y: initial,
+ z: initial,
+ }
+ }
+
+ pub fn new_xy(x: T, y: T, z: T) -> Vector3<T> {
+ Vector3 { x, y, z}
+ }
+}
+
+impl<T: Number> Sub for Vector3<T> {
+ type Output = Self;
+ fn sub(self, op: Self) -> Self::Output {
+ Self::new_xy(
+ self.x - op.x,
+ self.y - op.y,
+ self.z - op.z,
+ )
+ }
+}
+
+impl<T: Number> Add for Vector3<T> {
+ type Output = Self;
+ fn add(self, op: Self) -> Self::Output {
+ Self::new_xy(
+ self.x + op.x,
+ self.y + op.y,
+ self.z + op.z,
+ )
+ }
+}