From 3316a77192183a4cf25904ab2381ab126bfe617a Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 7 Nov 2012 12:36:35 +1000 Subject: [PATCH] Add mat4_from_rotation function --- src/funs/transform.rs | 20 ++++++++++++++++++++ src/lmath.rc | 1 + 2 files changed, 21 insertions(+) create mode 100644 src/funs/transform.rs diff --git a/src/funs/transform.rs b/src/funs/transform.rs new file mode 100644 index 0000000..2ce818e --- /dev/null +++ b/src/funs/transform.rs @@ -0,0 +1,20 @@ +use num::Num; +use ncast::*; +use funs::exp::*; +use funs::trig::*; +use matrix::Mat4; + +fn mat4_from_rotation(axis: Vec3, angle: T) -> Mat4 { + let angle_rad = radians(&angle); + let c = cos(&angle_rad); + let s = sin(&angle_rad); + + let _0: T = cast(0); + let _1: T = cast(1); + let t = _1 - c; + + Mat4::new(t * axis.x * axis.x + c, t * axis.x * axis.y + s * axis.z, t * axis.x * axis.z - s * axis.y, _0, + t * axis.x * axis.y - s * axis.z, t * axis.y * axis.y + c, t * axis.y * axis.z + s * axis.x, _0, + t * axis.x * axis.z - s - axis.y, t * axis.y * axis.z - s * axis.x, t * axis.z * axis.z + c, _0, + _0, _0, _0, _1) +} \ No newline at end of file diff --git a/src/lmath.rc b/src/lmath.rc index 89f5f74..8e54154 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -35,6 +35,7 @@ pub mod funs { pub mod common; pub mod exp; pub mod relv; + pub mod transform; pub mod trig; #[test]