From 6485ff070e174b373383a2a845b5824caa43bf3e Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 28 Dec 2012 13:37:18 +1000 Subject: [PATCH] Add Rotation trait This will eventually be implemented on Mat3 and Quat --- src/lmath.rc | 2 ++ src/rot.rs | 27 +++++++++++++++++++++++++++ src/test/test_rot.rs | 0 3 files changed, 29 insertions(+) create mode 100644 src/rot.rs create mode 100644 src/test/test_rot.rs diff --git a/src/lmath.rc b/src/lmath.rc index e2331ce..6be693b 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -14,6 +14,7 @@ extern mod numeric; pub mod gltypes; pub mod mat; pub mod quat; +pub mod rot; pub mod vec; #[test] @@ -21,6 +22,7 @@ mod test { mod test_gltypes; mod test_mat; mod test_quat; + mod test_rot; mod test_vec; } diff --git a/src/rot.rs b/src/rot.rs new file mode 100644 index 0000000..fde7409 --- /dev/null +++ b/src/rot.rs @@ -0,0 +1,27 @@ +use numeric::types::angle::Angle; + +use mat::Mat3; +use quat::Quat; +use vec::Vec3; + +/** + * A trait that includes some common rotation methods, constructors and conversions + */ +pub trait Rotation { + static pure fn from>(rot: R) -> self; + + static pure fn from_angle_x>(theta: A) -> self; + static pure fn from_angle_y>(theta: A) -> self; + static pure fn from_angle_z>(theta: A) -> self; + static pure fn from_angle_xyz>(x: A, y: A, z: A) -> self; + static pure fn from_angle_axis>(theta: A, axis: &Vec3) -> self; + static pure fn from_axes(x: Vec3, y: Vec3, z: Vec3) -> self; + static pure fn look_at(dir: &Vec3, up: &Vec3) -> self; + + pure fn concat(&self, other: &self) -> self; + pure fn rotate_vec(&self, vec: &Vec3) -> Vec3; + + pure fn to_mat3(&self) -> Mat3; + pure fn to_quat(&self) -> Quat; + // pure fn to_euler(&self) -> Euler; +} \ No newline at end of file diff --git a/src/test/test_rot.rs b/src/test/test_rot.rs new file mode 100644 index 0000000..e69de29