From aada68c23e9f7274081b489b1775559c7edda856 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 14 Nov 2012 18:23:15 +1000 Subject: [PATCH] Add mat3_from_rotation function --- src/funs/transform.rs | 15 +++++++++------ src/matrix.rs | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/funs/transform.rs b/src/funs/transform.rs index c93a407..125c125 100644 --- a/src/funs/transform.rs +++ b/src/funs/transform.rs @@ -2,9 +2,9 @@ use num::Num; use ncast::*; use funs::exp::Exp; use funs::trig::*; -use matrix::Mat4; +use matrix::{Mat3, Mat4}; -pub pure fn mat4_from_rotation(theta: T, axis: Vec3) -> Mat4 { +pub pure fn mat3_from_rotation(theta: T, axis: Vec3) -> Mat3 { let rad = radians(&theta); let c: T = cos(&rad); let s: T = sin(&rad); @@ -12,8 +12,11 @@ pub pure fn mat4_from_rotation(theta: T, axis let _1: T = cast(1); let t: 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) + Mat3::new(t * axis.x * axis.x + c, t * axis.x * axis.y + s * axis.z, t * axis.x * axis.z - s * axis.y, + t * axis.x * axis.y - s * axis.z, t * axis.y * axis.y + c, t * axis.y * axis.z + s * axis.x, + t * axis.x * axis.z - s - axis.y, t * axis.y * axis.z - s * axis.x, t * axis.z * axis.z + c) +} + +pub pure fn mat4_from_rotation(theta: T, axis: Vec3) -> Mat4 { + mat3_from_rotation(theta, axis).to_Mat4() } \ No newline at end of file diff --git a/src/matrix.rs b/src/matrix.rs index 0d65593..cec33f2 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -260,7 +260,7 @@ pub impl Mat2: NumericMatrix_NxN> { } } -pub impl Mat2: Matrix2 { +pub impl Mat2: Matrix2 { #[inline(always)] pure fn to_Mat3() -> Mat3 { Mat3::from_Mat2(&self) @@ -511,7 +511,7 @@ pub impl Mat3: NumericMatrix_NxN> { } } -pub impl Mat3: Matrix3 { +pub impl Mat3: Matrix3 { #[inline(always)] pure fn to_Mat4() -> Mat4 { Mat4::from_Mat3(&self)