]> git.nega.tv - josh/narcissus/commitdiff
narcissus-math: Use tan_pi for projection matrix
authorJoshua Simmons <josh@nega.tv>
Sun, 4 Jun 2023 08:54:51 +0000 (10:54 +0200)
committerJoshua Simmons <josh@nega.tv>
Sun, 4 Jun 2023 08:54:51 +0000 (10:54 +0200)
bins/narcissus/src/main.rs
libs/narcissus-maths/src/mat4.rs

index cfe4e4448aa6ae92f2dda431b50219725b824828..0e97806c4dc20018e5193cc36f1d6e27530393fd 100644 (file)
@@ -269,8 +269,11 @@ pub fn main() {
         let eye = Point3::new(s * camera_radius, camera_height, c * camera_radius);
         let center = Point3::ZERO;
         let camera_from_model = Mat4::look_at(eye, center, Vec3::Y);
-        let clip_from_camera =
-            Mat4::perspective_rev_inf_zo(Deg::new(45.0).into(), width as f32 / height as f32, 0.01);
+        let clip_from_camera = Mat4::perspective_rev_inf_zo(
+            HalfTurn::new(1.0 / 3.0),
+            width as f32 / height as f32,
+            0.01,
+        );
         let clip_from_model = clip_from_camera * camera_from_model;
 
         basic_uniform_buffer.write(BasicUniforms { clip_from_model });
index 36f0dc25cd63ea37676f27eaa7e64286d3bf0092..745aa4b21a17630152aea0dda2f90ef606299c8e 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{sin_cos_pi_f32, HalfTurn, Point2, Point3, Rad, Vec2, Vec3, Vec4};
+use crate::{sin_cos_pi_f32, tan_pi_f32, HalfTurn, Point2, Point3, Vec2, Vec3, Vec4};
 
 /// 4x4 matrix.
 ///
@@ -206,8 +206,8 @@ impl Mat4 {
     ///
     /// Src coordinate space: right-handed, +y up.
     /// Dst coordinate space: right-handed, -y up, depth range \[0,1\].
-    pub fn perspective_rev_inf_zo(vertical_fov: Rad, aspect_ratio: f32, z_near: f32) -> Mat4 {
-        let tan = (vertical_fov.as_f32() / 2.0).tan();
+    pub fn perspective_rev_inf_zo(vertical_fov: HalfTurn, aspect_ratio: f32, z_near: f32) -> Mat4 {
+        let tan = tan_pi_f32(vertical_fov.as_f32() / 2.0);
         let sy = 1.0 / tan;
         let sx = sy / aspect_ratio;
         Mat4::from_rows([