Added copy and clone
This commit is contained in:
12
src/vec4.rs
12
src/vec4.rs
@@ -5,6 +5,7 @@ use std::ops;
|
|||||||
// Vector: x,y,z,0
|
// Vector: x,y,z,0
|
||||||
// Position: x,y,z,1
|
// Position: x,y,z,1
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct Vec4 {
|
pub struct Vec4 {
|
||||||
x: [f32; 4],
|
x: [f32; 4],
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,17 @@ impl Vec4 {
|
|||||||
+ self.x[2] * other.x[2]
|
+ self.x[2] * other.x[2]
|
||||||
+ self.x[3] * other.x[3]
|
+ 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
|
//Normalise the vector
|
||||||
pub fn normalise(&mut self) {
|
pub fn normalise(&mut self) {
|
||||||
let magnitude = self.dot(self).sqrt();
|
let magnitude = self.dot(self).sqrt();
|
||||||
|
|||||||
Reference in New Issue
Block a user