Add mat3_from_rotation function
This commit is contained in:
parent
a9273389ea
commit
aada68c23e
2 changed files with 11 additions and 8 deletions
|
@ -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<T:Copy Num NumCast AngleConv Trig>(theta: T, axis: Vec3<T>) -> Mat4<T> {
|
||||
pub pure fn mat3_from_rotation<T:Copy Num NumCast AngleConv Trig>(theta: T, axis: Vec3<T>) -> Mat3<T> {
|
||||
let rad = radians(&theta);
|
||||
let c: T = cos(&rad);
|
||||
let s: T = sin(&rad);
|
||||
|
@ -12,8 +12,11 @@ pub pure fn mat4_from_rotation<T:Copy Num NumCast AngleConv Trig>(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<T:Copy Num NumCast AngleConv Trig>(theta: T, axis: Vec3<T>) -> Mat4<T> {
|
||||
mat3_from_rotation(theta, axis).to_Mat4()
|
||||
}
|
|
@ -260,7 +260,7 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast FuzzyEq> Mat2<T>: Matrix2<T> {
|
||||
pub impl<T:Copy NumCast> Mat2<T>: Matrix2<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_Mat3() -> Mat3<T> {
|
||||
Mat3::from_Mat2(&self)
|
||||
|
@ -511,7 +511,7 @@ pub impl<T:Copy Num NumCast FuzzyEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast FuzzyEq> Mat3<T>: Matrix3<T> {
|
||||
pub impl<T:Copy NumCast> Mat3<T>: Matrix3<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_Mat4() -> Mat4<T> {
|
||||
Mat4::from_Mat3(&self)
|
||||
|
|
Loading…
Reference in a new issue