diff --git a/src/projection.rs b/src/projection.rs index f05ef67..85c2d72 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -8,12 +8,16 @@ use mat::{Mat4, BaseMat4}; /** * Create a perspective projection matrix * + * Note: the fovy parameter should be specified in degrees. + * * This is the equivalent of the gluPerspective function, the algorithm of which * can be found [here](http://www.opengl.org/wiki/GluPerspective_code). */ #[inline(always)] pub fn perspective + Add + Sub + Mul + Div + Neg>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4 { - let ymax = near * tan(radians(fovy)); + let _2: T = num::cast(2); + + let ymax = near * tan(radians(fovy / _2)); let xmax = ymax * aspectRatio; frustum(-xmax, xmax, -ymax, ymax, near, far) @@ -55,4 +59,23 @@ pub fn frustum + Add + Sub + c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) -} \ No newline at end of file +} + +/** + * Create an orthographic projection matrix + * + * This is the equivalent of the now deprecated [glOrtho] + * (http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml) function. + */ +#[inline(always)] +pub fn orthographic + Add + Sub + Mul + Div + Neg>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4 { + let _0: T = num::cast(0); + let _1: T = num::cast(1); + let _2: T = num::cast(2); + + BaseMat4::new(_2 / (right - left), _0, _0, _0, + _0, _2 / (top - bottom), _0, _0, + _0, _0, -_2 / (far - near), _0, + -(right + left) / (right - left), -(top + bottom) / (top - bottom), + -(far + near) / (far - near), _1) +}