diff --git a/src/projection.rs b/src/projection.rs index da16e23..e583930 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -24,9 +24,9 @@ use num::BaseFloat; /// /// This is the equivalent to the [gluPerspective] /// (http://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml) function. -pub fn perspective>(fovy: A, aspect: S, near: S, far: S) -> Matrix4 { +pub fn perspective>>(fovy: A, aspect: S, near: S, far: S) -> Matrix4 { PerspectiveFov { - fovy: fovy, + fovy: fovy.into(), aspect: aspect, near: near, far: far, @@ -65,17 +65,16 @@ pub fn ortho(left: S, right: S, bottom: S, top: S, near: S, far: S /// A perspective projection based on a vertical field-of-view angle. #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] -pub struct PerspectiveFov { - pub fovy: A, +pub struct PerspectiveFov { + pub fovy: Rad, pub aspect: S, pub near: S, pub far: S, } -impl> PerspectiveFov { +impl PerspectiveFov { pub fn to_perspective(&self) -> Perspective { let angle = self.fovy.div_s(cast(2i8).unwrap()); - let angle: Rad<_> = angle.into(); let ymax = self.near * tan(angle); let xmax = ymax * self.aspect; @@ -90,19 +89,16 @@ impl> PerspectiveFov { } } -impl> From> for Matrix4 { - fn from(persp: PerspectiveFov) -> Matrix4 { - let half_turn: A = Angle::turn_div_2(); - - assert!(persp.fovy > A::zero(), "The vertical field of view cannot be below zero, found: {:?}", persp.fovy); - assert!(persp.fovy < half_turn, "The vertical field of view cannot be greater than a half turn, found: {:?}", persp.fovy); +impl From> for Matrix4 { + fn from(persp: PerspectiveFov) -> Matrix4 { + assert!(persp.fovy > Rad::zero(), "The vertical field of view cannot be below zero, found: {:?}", persp.fovy); + assert!(persp.fovy < Rad::turn_div_2(), "The vertical field of view cannot be greater than a half turn, found: {:?}", persp.fovy); assert!(persp.aspect > S::zero(), "The aspect ratio cannot be below zero, found: {:?}", persp.aspect); assert!(persp.near > S::zero(), "The near plane distance cannot be below zero, found: {:?}", persp.near); assert!(persp.far > S::zero(), "The far plane distance cannot be below zero, found: {:?}", persp.far); assert!(persp.far > persp.near, "The far plane cannot be closer than the near plane, found: far: {:?}, near: {:?}", persp.far, persp.near); - let f: Rad<_> = persp.fovy.div_s(cast(2i8).unwrap()).into(); - let f = cot(f); + let f = cot(persp.fovy.div_s(cast(2i8).unwrap())); let two: S = cast(2i8).unwrap(); let c0r0 = f / persp.aspect;