From bd458d49226015401d0c08eab52827e78d2848e3 Mon Sep 17 00:00:00 2001 From: STP Date: Fri, 10 Nov 2023 23:49:41 -0500 Subject: [PATCH] Added copy and clone --- src/vec4.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vec4.rs b/src/vec4.rs index 78b3247..0ae45e7 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -5,6 +5,7 @@ use std::ops; // Vector: x,y,z,0 // Position: x,y,z,1 +#[derive(Copy, Clone)] pub struct Vec4 { x: [f32; 4], } @@ -31,6 +32,17 @@ impl Vec4 { + self.x[2] * other.x[2] + self.x[3] * other.x[3] } + //Cross product + pub fn cross(&self, other: &Vec4) -> Vec4 { + Vec4 { + x: [ + self.x[1] * other.x[2] - self.x[2] * other.x[1], + self.x[2] * other.x[0] - self.x[0] * other.x[2], + self.x[0] * other.x[1] - self.x[1] * other.x[0], + 0.0, + ], + } + } //Normalise the vector pub fn normalise(&mut self) { let magnitude = self.dot(self).sqrt();