Add Rotation constructor, reorganise feilds
This commit is contained in:
parent
44fa552950
commit
2cb00d8c0e
2 changed files with 10 additions and 4 deletions
|
@ -76,11 +76,15 @@ pub impl<T:Copy Ord> Degrees<T>: Ord {
|
|||
* An angular rotation around an arbitary axis
|
||||
*/
|
||||
pub struct Rotation<T> {
|
||||
axis: Vec3<T>,
|
||||
theta: Radians<T>,
|
||||
axis: Vec3<T>,
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Rotation<T> {
|
||||
static pure fn new(theta: Radians<T>, axis: Vec3<T>) -> Rotation<T> {
|
||||
Rotation { theta: move theta, axis: move axis }
|
||||
}
|
||||
|
||||
pure fn to_mat3() -> Mat3<T> {
|
||||
let c: T = cos(&self.theta);
|
||||
let s: T = sin(&self.theta);
|
||||
|
|
|
@ -55,8 +55,8 @@ fn test_rotation() {
|
|||
{
|
||||
let pos = Vec4::new(1.0, 0.0, 0.0, 1.0); // the position to transform
|
||||
let rot = Rotation {
|
||||
axis: Vec3::new(0.0, 0.0, 1.0), // unit_z
|
||||
theta: Degrees(180.0).to_radians(),
|
||||
axis: Vec3::new(0.0, 0.0, 1.0), // unit_z
|
||||
};
|
||||
|
||||
let newpos = rot.to_mat4().mul_v(&pos);
|
||||
|
@ -68,13 +68,13 @@ fn test_rotation() {
|
|||
let pos = Vec4::new(4f32, 0f32, 0f32, 1f32);
|
||||
|
||||
let rot_a = Rotation {
|
||||
axis: Vec3::new(0f32, 1f32, 0f32), // unit_y
|
||||
theta: Degrees(90f32).to_radians(),
|
||||
axis: Vec3::new(0f32, 1f32, 0f32), // unit_y
|
||||
};
|
||||
|
||||
let rot_b = Rotation {
|
||||
axis: -Vec3::new(0f32, 1f32, 0f32), // -unit_y
|
||||
theta: Degrees(90f32).to_radians(),
|
||||
axis: -Vec3::new(0f32, 1f32, 0f32), // -unit_y
|
||||
};
|
||||
|
||||
let newpos_a = rot_a.to_mat4().mul_v(&pos);
|
||||
|
@ -86,4 +86,6 @@ fn test_rotation() {
|
|||
assert newpos_a == expected_pos_a;
|
||||
assert newpos_b == expected_pos_b;
|
||||
}
|
||||
|
||||
// TODO: test to_quat
|
||||
}
|
Loading…
Reference in a new issue