diff --git a/crates/fj-math/src/transform.rs b/crates/fj-math/src/transform.rs index ee99c7729..c0daf1f70 100644 --- a/crates/fj-math/src/transform.rs +++ b/crates/fj-math/src/transform.rs @@ -1,7 +1,5 @@ use std::ops; -use nalgebra::Perspective3; - use super::{Aabb, LineSegment, Point, Triangle, Vector}; /// An affine transform @@ -118,27 +116,6 @@ impl Transform { } } - /// Project transform according to camera specification, return data as an array. - /// Used primarily for graphics code. - pub fn project_to_array( - &self, - aspect_ratio: f64, - fovy: f64, - znear: f64, - zfar: f64, - ) -> [f64; 16] { - let projection = Perspective3::new(aspect_ratio, fovy, znear, zfar); - - let mut array = [0.; 16]; - array.copy_from_slice( - (projection.to_projective() * self.inner) - .matrix() - .as_slice(), - ); - - array - } - /// Transform the given axis-aligned bounding box pub fn transform_aabb(&self, aabb: &Aabb<3>) -> Aabb<3> { Aabb { diff --git a/crates/fj-viewer/src/graphics/transform.rs b/crates/fj-viewer/src/graphics/transform.rs index 48e591c27..53aa0084b 100644 --- a/crates/fj-viewer/src/graphics/transform.rs +++ b/crates/fj-viewer/src/graphics/transform.rs @@ -1,4 +1,5 @@ use bytemuck::{Pod, Zeroable}; +use nalgebra::Perspective3; use crate::camera::Camera; @@ -18,12 +19,23 @@ impl Transform { let field_of_view_in_y = 2. * ((camera.field_of_view_in_x() / 2.).tan() / aspect_ratio).atan(); - let transform = camera.camera_to_model().project_to_array( - aspect_ratio, - field_of_view_in_y, - camera.near_plane(), - camera.far_plane(), - ); + let transform = { + let projection = Perspective3::new( + aspect_ratio, + field_of_view_in_y, + camera.near_plane(), + camera.far_plane(), + ); + + let mut array = [0.; 16]; + array.copy_from_slice( + (projection.to_projective() * camera.camera_to_model().inner) + .matrix() + .as_slice(), + ); + + array + }; Self(transform.map(|scalar| scalar as f32)) }