2012-11-25 18:28:41 +00:00
|
|
|
use core::f64::consts::pi;
|
2012-11-25 16:26:01 +00:00
|
|
|
use num::cast::*;
|
|
|
|
use vec::Vec3;
|
|
|
|
|
2012-11-25 18:28:41 +00:00
|
|
|
pub trait Angle<T>: Add<self,self>
|
|
|
|
, Sub<self,self>
|
|
|
|
, Mul<T,self>
|
|
|
|
, Div<T,self>
|
|
|
|
, Modulo<T,self>
|
|
|
|
, Neg<self> {
|
|
|
|
pure fn to_radians() -> Radians<T>;
|
|
|
|
pure fn to_degrees() -> Degrees<T>;
|
2012-11-25 16:26:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-25 18:28:41 +00:00
|
|
|
pub enum Radians<T> = T;
|
2012-11-25 17:43:48 +00:00
|
|
|
|
2012-11-25 18:28:41 +00:00
|
|
|
pub impl<T:Copy Num NumCast> Radians<T>: Angle<T> {
|
|
|
|
#[inline(always)] pure fn to_radians() -> Radians<T> { self }
|
|
|
|
#[inline(always)] pure fn to_degrees() -> Degrees<T> { Degrees(*self * cast(180.0 / pi)) }
|
|
|
|
|
|
|
|
#[inline(always)] pure fn add(rhs: &Radians<T>) -> Radians<T> { self + *rhs }
|
|
|
|
#[inline(always)] pure fn sub(rhs: &Radians<T>) -> Radians<T> { self - *rhs }
|
|
|
|
#[inline(always)] pure fn mul(rhs: &T) -> Radians<T> { self * *rhs }
|
|
|
|
#[inline(always)] pure fn div(rhs: &T) -> Radians<T> { self / *rhs }
|
|
|
|
#[inline(always)] pure fn modulo(rhs: &T) -> Radians<T> { self % *rhs }
|
|
|
|
#[inline(always)] pure fn neg() -> Radians<T> {-self }
|
2012-11-25 17:43:48 +00:00
|
|
|
}
|
|
|
|
|
2012-11-25 18:28:41 +00:00
|
|
|
pub enum Degrees<T> = T;
|
2012-11-25 17:43:48 +00:00
|
|
|
|
2012-11-25 18:28:41 +00:00
|
|
|
pub impl<T:Copy Num NumCast> Degrees<T>: Angle<T> {
|
|
|
|
#[inline(always)] pure fn to_radians() -> Radians<T> { Radians(*self * cast(pi / 180.0)) }
|
|
|
|
#[inline(always)] pure fn to_degrees() -> Degrees<T> { self }
|
|
|
|
|
|
|
|
#[inline(always)] pure fn add(rhs: &Degrees<T>) -> Degrees<T> { self + *rhs }
|
|
|
|
#[inline(always)] pure fn sub(rhs: &Degrees<T>) -> Degrees<T> { self - *rhs }
|
|
|
|
#[inline(always)] pure fn mul(rhs: &T) -> Degrees<T> { self * *rhs }
|
|
|
|
#[inline(always)] pure fn div(rhs: &T) -> Degrees<T> { self / *rhs }
|
|
|
|
#[inline(always)] pure fn modulo(rhs: &T) -> Degrees<T> { self % *rhs }
|
|
|
|
#[inline(always)] pure fn neg() -> Degrees<T> {-self }
|
2012-11-25 17:43:48 +00:00
|
|
|
}
|
|
|
|
|
2012-11-25 16:26:01 +00:00
|
|
|
pub struct AxisRotation<T> {
|
|
|
|
axis: Vec3<T>,
|
2012-11-25 18:28:41 +00:00
|
|
|
theta: Radians<T>,
|
2012-11-25 16:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Euler<T> {
|
2012-11-25 18:28:41 +00:00
|
|
|
x: Radians<T>, // pitch
|
|
|
|
y: Radians<T>, // yaw
|
|
|
|
z: Radians<T>, // roll
|
2012-11-25 16:26:01 +00:00
|
|
|
}
|