Remove the wavefront object loader for now...
[mandelwow.git] / support / vec3.rs
1 extern crate glutin;
2
3 use std::f32;
4 use std::ops::Add;
5 use std::ops::AddAssign;
6 use std::ops::Sub;
7 use std::ops::SubAssign;
8 use std::ops::Mul;
9
10 #[derive(Default, PartialEq, Debug, Clone, Copy)]
11 pub struct Vec3(pub f32, pub f32, pub f32);
12
13 impl Add for Vec3 {
14     type Output = Vec3;
15     fn add(self, other: Vec3) -> Vec3 {
16         Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
17     }
18 }
19
20 impl AddAssign for Vec3 {
21     fn add_assign(&mut self, other: Vec3) {
22         *self = Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
23     }
24 }
25
26 impl Sub for Vec3 {
27     type Output = Vec3;
28     fn sub(self, other: Vec3) -> Vec3 {
29         Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
30     }
31 }
32
33 impl SubAssign for Vec3 {
34     fn sub_assign(&mut self, other: Vec3) {
35         *self = Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
36     }
37 }
38
39 impl Mul<f32> for Vec3 {
40     type Output = Vec3;
41     fn mul(self, f: f32) -> Vec3 {
42         Vec3(self.0 * f, self.1 * f, self.2 * f)
43     }
44 }
45
46 pub fn norm(v: &Vec3) -> Vec3 {
47     let len = (v.0 * v.0 + v.1 * v.1 + v.2 * v.2).sqrt();
48     Vec3(v.0 / len, v.1 / len, v.2 / len)
49 }