Add normalize method
This commit is contained in:
parent
693a0adda0
commit
59a9cdb8d7
1 changed files with 8 additions and 0 deletions
|
@ -39,6 +39,7 @@ pub trait Quaternion<T> {
|
|||
pure fn inverse() -> self;
|
||||
pure fn length2() -> T;
|
||||
pure fn length() -> T;
|
||||
pure fn normalize() -> self;
|
||||
|
||||
pure fn to_Mat3() -> Mat3<T>;
|
||||
pure fn to_Mat4() -> Mat4<T>;
|
||||
|
@ -157,6 +158,13 @@ pub impl<T:Copy Num NumCast Exp FuzzyEq> Quat<T>: Quaternion<T> {
|
|||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize() -> Quat<T> {
|
||||
let mut n: T = cast(1);
|
||||
n /= self.length();
|
||||
return self.mul_t(n);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_Mat3() -> Mat3<T> {
|
||||
let x2 = self.x + self.x;
|
||||
|
|
Loading…
Reference in a new issue