Implemented missing rotation functions (rotate_point, rotate_ray)

This commit is contained in:
kvark 2013-11-02 11:16:18 -04:00
parent c13ebf57ab
commit 42e3801715

View file

@ -20,7 +20,7 @@ use matrix::{Mat2, ToMat2};
use matrix::{Mat3, ToMat3}; use matrix::{Mat3, ToMat3};
use point::{Point, Point2, Point3}; use point::{Point, Point2, Point3};
use quaternion::{Quat, ToQuat}; use quaternion::{Quat, ToQuat};
use ray::{Ray, Ray2, Ray3}; use ray::Ray;
use vector::{Vector, Vec2, Vec3}; use vector::{Vector, Vec2, Vec3};
/// A trait for generic rotation /// A trait for generic rotation
@ -35,9 +35,13 @@ pub trait Rotation
+ ApproxEq<S> + ApproxEq<S>
{ {
fn identity() -> Self; fn identity() -> Self;
fn rotate_point(&self, point: &P) -> P;
fn rotate_vec(&self, vec: &V) -> V; fn rotate_vec(&self, vec: &V) -> V;
#[inline]
fn rotate_point(&self, point: &P) -> P {
Point::from_vec( &self.rotate_vec( &point.to_vec() ) )
}
#[inline] #[inline]
fn rotate_ray(&self, ray: &Ray<P,V>) -> Ray<P,V> { fn rotate_ray(&self, ray: &Ray<P,V>) -> Ray<P,V> {
Ray::new( //FIXME: use clone derived from Array Ray::new( //FIXME: use clone derived from Array
@ -115,15 +119,9 @@ impl<S: Float> Rotation<S, [S, ..2], Vec2<S>, Point2<S>> for Basis2<S> {
#[inline] #[inline]
fn identity() -> Basis2<S> { Basis2{ mat: Mat2::identity() } } fn identity() -> Basis2<S> { Basis2{ mat: Mat2::identity() } }
#[inline]
fn rotate_point(&self, _point: &Point2<S>) -> Point2<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn rotate_vec(&self, vec: &Vec2<S>) -> Vec2<S> { self.mat.mul_v(vec) } fn rotate_vec(&self, vec: &Vec2<S>) -> Vec2<S> { self.mat.mul_v(vec) }
#[inline]
fn rotate_ray(&self, _ray: &Ray2<S>) -> Ray2<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn concat(&self, other: &Basis2<S>) -> Basis2<S> { Basis2 { mat: self.mat.mul_m(&other.mat) } } fn concat(&self, other: &Basis2<S>) -> Basis2<S> { Basis2 { mat: self.mat.mul_m(&other.mat) } }
@ -236,15 +234,9 @@ impl<S: Float> Rotation<S, [S, ..3], Vec3<S>, Point3<S>> for Basis3<S> {
#[inline] #[inline]
fn identity() -> Basis3<S> { Basis3{ mat: Mat3::identity() } } fn identity() -> Basis3<S> { Basis3{ mat: Mat3::identity() } }
#[inline]
fn rotate_point(&self, _point: &Point3<S>) -> Point3<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn rotate_vec(&self, vec: &Vec3<S>) -> Vec3<S> { self.mat.mul_v(vec) } fn rotate_vec(&self, vec: &Vec3<S>) -> Vec3<S> { self.mat.mul_v(vec) }
#[inline]
fn rotate_ray(&self, _ray: &Ray3<S>) -> Ray3<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn concat(&self, other: &Basis3<S>) -> Basis3<S> { Basis3 { mat: self.mat.mul_m(&other.mat) } } fn concat(&self, other: &Basis3<S>) -> Basis3<S> { Basis3 { mat: self.mat.mul_m(&other.mat) } }
@ -298,15 +290,9 @@ impl<S: Float> Rotation<S, [S, ..3], Vec3<S>, Point3<S>> for Quat<S> {
#[inline] #[inline]
fn identity() -> Quat<S> { Quat::identity() } fn identity() -> Quat<S> { Quat::identity() }
#[inline]
fn rotate_point(&self, _point: &Point3<S>) -> Point3<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn rotate_vec(&self, vec: &Vec3<S>) -> Vec3<S> { self.mul_v(vec) } fn rotate_vec(&self, vec: &Vec3<S>) -> Vec3<S> { self.mul_v(vec) }
#[inline]
fn rotate_ray(&self, _ray: &Ray3<S>) -> Ray3<S> { fail!("Not yet implemented") }
#[inline] #[inline]
fn concat(&self, other: &Quat<S>) -> Quat<S> { self.mul_q(other) } fn concat(&self, other: &Quat<S>) -> Quat<S> { self.mul_q(other) }