From 5cf091656d8f9c1b50d32b1db336dda19c6ba020 Mon Sep 17 00:00:00 2001 From: Mikko Perttunen Date: Sun, 7 Apr 2013 12:55:03 +0300 Subject: [PATCH 1/2] Fix projection::perspective. --- src/projection.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/projection.rs b/src/projection.rs index f05ef67..d79b1f7 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) From 4293d9aa1bce44f6d9d81d326387b17ec4701702 Mon Sep 17 00:00:00 2001 From: Mikko Perttunen Date: Sun, 7 Apr 2013 13:06:26 +0300 Subject: [PATCH 2/2] Add function projection::orthographic. --- src/projection.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/projection.rs b/src/projection.rs index d79b1f7..85c2d72 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -59,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) +}