Added copy and clone

This commit is contained in:
STP
2023-11-10 23:49:41 -05:00
parent 246bc697ba
commit bd458d4922

View File

@@ -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();