Fix projection::perspective.

This commit is contained in:
Mikko Perttunen 2013-04-07 12:55:03 +03:00
parent 9116917607
commit 5cf091656d

View file

@ -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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
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)