Inline redundant method

This commit is contained in:
Hanno Braun 2025-05-13 14:05:10 +02:00
parent 7b16d4a04e
commit 8fc2a139c9
2 changed files with 18 additions and 29 deletions

View File

@ -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 {

View File

@ -1,4 +1,5 @@
use bytemuck::{Pod, Zeroable};
use nalgebra::Perspective3;
use crate::camera::Camera;
@ -18,13 +19,24 @@ 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(
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))
}