From 900f466e43dbc6baee5296f96e5265902abe448c Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Sun, 11 Oct 2020 15:41:29 +0200 Subject: [PATCH] no need to specialize set_fovy --- src/geometry/perspective.rs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index d9cd5fee..b877142f 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -254,6 +254,15 @@ impl Perspective3 { ); self.matrix[(0, 0)] = self.matrix[(1, 1)] / aspect; } + + /// Updates this perspective with a new y field of view of the view frustum. + #[inline] + pub fn set_fovy(&mut self, fovy: N) { + let old_m22 = self.matrix[(1, 1)]; + let f = N::one() / (fovy / crate::convert(2.0)).tan(); + self.matrix[(1, 1)] = f; + self.matrix[(0, 0)] *= f / old_m22; + } } // OpenGL specialization @@ -284,13 +293,6 @@ impl Perspective3 { res } - /// Updates this perspective with a new y field of view of the view frustum. - #[inline] - pub fn set_fovy(&mut self, fovy: N) { - let old_m22 = self.matrix[(1, 1)]; - self.matrix[(1, 1)] = N::one() / (fovy / crate::convert(2.0)).tan(); - self.matrix[(0, 0)] = self.matrix[(0, 0)] * (self.matrix[(1, 1)] / old_m22); - } /// Updates this perspective matrix with a new near plane offset of the view frustum. /// Implementation note: set_znear() must be specialized because it calls other specialized functions. @@ -343,15 +345,6 @@ impl Perspective3 { res } - /// Updates this perspective with a new y field of view of the view frustum. - #[inline] - pub fn set_fovy(&mut self, fovy: N) { - let old_m22 = self.matrix[(1, 1)]; - let f = N::one() / (fovy / crate::convert(2.0)).tan(); - self.matrix[(1, 1)] = -f; - self.matrix[(0, 0)] *= f / old_m22; - } - /// Updates this perspective matrix with a new near plane offset of the view frustum. /// Implementation note: set_znear() must be specialized because it calls other specialized functions. #[inline] @@ -371,8 +364,8 @@ impl Perspective3 { /// Updates this perspective matrix with new near and far plane offsets of the view frustum. #[inline] pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) { - self.matrix[(2, 2)] = -zfar / (zfar - znear); - self.matrix[(2, 3)] = -(zfar * znear) / (zfar - znear); + self.matrix[(2, 2)] = zfar / (znear - zfar); + self.matrix[(2, 3)] = (zfar * znear) / (znear - zfar); } }