@@ -78,13 +78,20 @@ pub fn ortho<S: BaseFloat>(left: S, right: S, bottom: S, top: S, near: S, far: S
7878
7979/// Create a planar projection matrix, which can be either perspective or orthographic.
8080///
81- /// The projection frustum is always two units high at the origin along the view direction,
82- /// making the focal point located at `(0.0, 0.0, cot(fovy / 2.0))`. Unlike a standard perspective
83- /// projection, this allows `fovy` to be zero or negative.
84- pub fn planar < S : BaseFloat , A : Into < Rad < S > > > ( fovy : A , aspect : S , near : S , far : S ) -> Matrix4 < S > {
81+ /// The projection frustum is always `height` units high at the origin along the view direction,
82+ /// making the focal point located at `(0.0, 0.0, cot(fovy / 2.0)) * height / 2.0`. Unlike
83+ /// a standard perspective projection, this allows `fovy` to be zero or negative.
84+ pub fn planar < S : BaseFloat , A : Into < Rad < S > > > (
85+ fovy : A ,
86+ aspect : S ,
87+ height : S ,
88+ near : S ,
89+ far : S ,
90+ ) -> Matrix4 < S > {
8591 PlanarFov {
8692 fovy : fovy. into ( ) ,
8793 aspect,
94+ height,
8895 near,
8996 far,
9097 }
@@ -305,6 +312,7 @@ impl<S: BaseFloat> From<Ortho<S>> for Matrix4<S> {
305312pub struct PlanarFov < S > {
306313 pub fovy : Rad < S > ,
307314 pub aspect : S ,
315+ pub height : S ,
308316 pub near : S ,
309317 pub far : S ,
310318}
@@ -321,6 +329,11 @@ impl<S: BaseFloat> From<PlanarFov<S>> for Matrix4<S> {
321329 "The vertical field of view cannot be greater than a half turn, found: {:?}" ,
322330 persp. fovy
323331 ) ;
332+ assert ! {
333+ persp. height >= S :: zero( ) ,
334+ "The projection plane height cannot be negative, found: {:?}" ,
335+ persp. height
336+ }
324337
325338 let two: S = cast ( 2 ) . unwrap ( ) ;
326339 let inv_f = Rad :: tan ( persp. fovy / two) ;
@@ -346,13 +359,13 @@ impl<S: BaseFloat> From<PlanarFov<S>> for Matrix4<S> {
346359 persp. near,
347360 ) ;
348361
349- let c0r0 = S :: one ( ) / persp. aspect ;
362+ let c0r0 = two / ( persp. aspect * persp . height ) ;
350363 let c0r1 = S :: zero ( ) ;
351364 let c0r2 = S :: zero ( ) ;
352365 let c0r3 = S :: zero ( ) ;
353366
354367 let c1r0 = S :: zero ( ) ;
355- let c1r1 = S :: one ( ) ;
368+ let c1r1 = two / persp . height ;
356369 let c1r2 = S :: zero ( ) ;
357370 let c1r3 = S :: zero ( ) ;
358371
0 commit comments