From: Bernie Innocenti Date: Sun, 19 Mar 2017 08:05:12 +0000 (-0400) Subject: Split Vec3. X-Git-Tag: v0.2.0~5 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=b1f47d18bd76c1d1475f992f021e714289f4b79a;p=mandelwow.git Split Vec3. --- diff --git a/support/camera.rs b/support/camera.rs index 1b56d7d..10ad1f0 100644 --- a/support/camera.rs +++ b/support/camera.rs @@ -1,44 +1,13 @@ extern crate glutin; +use support::vec3::Vec3; +use support::vec3::norm; + use std::f32; -use std::ops::Add; -use std::ops::AddAssign; -use std::ops::Sub; -use std::ops::Mul; //use glutin::Event; //use glutin::VirtualKeyCode; -#[derive(Default, PartialEq, Debug, Clone, Copy)] -pub struct Vec3 (f32, f32, f32); - -impl Add for Vec3 { - type Output = Vec3; - fn add(self, other: Vec3) -> Vec3 { - Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2) - } -} - -impl AddAssign for Vec3 { - fn add_assign(&mut self, other: Vec3) { - *self = Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2) - } -} - -impl Sub for Vec3 { - type Output = Vec3; - fn sub(self, other: Vec3) -> Vec3 { - Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2) - } -} - -impl Mul for Vec3 { - type Output = Vec3; - fn mul(self, f: f32) -> Vec3 { - Vec3(self.0 * f, self.1 * f, self.2 * f) - } -} - #[derive(Default)] pub struct CameraState { aspect_ratio: f32, @@ -57,11 +26,6 @@ pub struct CameraState { turning_right: bool, } -fn norm(v: &Vec3) -> Vec3 { - let len = (v.0 * v.0 + v.1 * v.1 + v.2 * v.2).sqrt(); - Vec3(v.0 / len, v.1 / len, v.2 / len) -} - impl CameraState { pub fn new() -> CameraState { CameraState { diff --git a/support/mod.rs b/support/mod.rs index 068a524..8996e55 100644 --- a/support/mod.rs +++ b/support/mod.rs @@ -9,6 +9,7 @@ use glium::{self, Display}; use glium::vertex::VertexBufferAny; pub mod camera; +pub mod vec3; pub enum Action { Stop, diff --git a/support/vec3.rs b/support/vec3.rs new file mode 100644 index 0000000..85d3cc3 --- /dev/null +++ b/support/vec3.rs @@ -0,0 +1,42 @@ +extern crate glutin; + +use std::f32; +use std::ops::Add; +use std::ops::AddAssign; +use std::ops::Sub; +use std::ops::Mul; + +#[derive(Default, PartialEq, Debug, Clone, Copy)] +pub struct Vec3 (pub f32, pub f32, pub f32); + +impl Add for Vec3 { + type Output = Vec3; + fn add(self, other: Vec3) -> Vec3 { + Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2) + } +} + +impl AddAssign for Vec3 { + fn add_assign(&mut self, other: Vec3) { + *self = Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2) + } +} + +impl Sub for Vec3 { + type Output = Vec3; + fn sub(self, other: Vec3) -> Vec3 { + Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2) + } +} + +impl Mul for Vec3 { + type Output = Vec3; + fn mul(self, f: f32) -> Vec3 { + Vec3(self.0 * f, self.1 * f, self.2 * f) + } +} + +pub fn norm(v: &Vec3) -> Vec3 { + let len = (v.0 * v.0 + v.1 * v.1 + v.2 * v.2).sqrt(); + Vec3(v.0 / len, v.1 / len, v.2 / len) +}