From 8389458b5bcfda7015081b7b715e40b3277402e1 Mon Sep 17 00:00:00 2001 From: KDecay Date: Sun, 3 Apr 2022 14:40:46 +0000 Subject: [PATCH] Remove `face_toward.rs` (#4277) # Objective - Part of the splitting process of #3503. ## Solution - Remove the `face_toward.rs` file containing the `FaceToward` trait. ## Reasons - It is unused inside of `bevy`. - The method `Mat4::face_toward` of the trait is identical to `Mat4::look_at_rh` (see https://docs.rs/glam/latest/glam/f32/struct.Mat4.html#method.look_at_rh). - Discussion in #3503. ## Changelog ### Removed - The `FaceToward` trait got removed. ## Migration Guide - The `FaceToward` trait got removed. To migrate you just have to change every occurrence of `Mat4::face_toward` to `Mat4::look_at_rh`. --- crates/bevy_math/src/face_toward.rs | 41 ----------------------------- crates/bevy_math/src/lib.rs | 6 ++--- 2 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 crates/bevy_math/src/face_toward.rs diff --git a/crates/bevy_math/src/face_toward.rs b/crates/bevy_math/src/face_toward.rs deleted file mode 100644 index f873964b18afc8..00000000000000 --- a/crates/bevy_math/src/face_toward.rs +++ /dev/null @@ -1,41 +0,0 @@ -use crate::{Mat4, Vec3}; - -/// Generates a translation / rotation matrix that faces a given target -pub trait FaceToward { - /// Generates a translation / rotation matrix that faces a given target - fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self; -} - -impl FaceToward for Mat4 { - fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self { - let forward = (eye - center).normalize(); - let right = up.cross(forward).normalize(); - let up = forward.cross(right); - Mat4::from_cols( - right.extend(0.0), - up.extend(0.0), - forward.extend(0.0), - eye.extend(1.0), - ) - } -} - -#[cfg(test)] -mod test { - #[test] - fn face_toward_mat4() { - use crate::{FaceToward, Mat4, Vec3, Vec4}; - - // Completely arbitrary arguments - let matrix = Mat4::face_toward( - Vec3::new(50.0, 60.0, 0.0), - Vec3::new(0.0, 0.0, 0.0), - Vec3::new(0.0, 1.0, 0.0), - ); - - assert_eq!(matrix.x_axis, Vec4::new(0.0, 0.0, -1.0, -0.0)); - assert_eq!(matrix.y_axis, Vec4::new(-0.7682213, 0.6401844, 0.0, 0.0)); - assert_eq!(matrix.z_axis, Vec4::new(0.6401844, 0.7682213, 0.0, 0.0)); - assert_eq!(matrix.w_axis, Vec4::new(50.0, 60.0, 0.0, 1.0)); - } -} diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index 9a8ae797ed04bb..b09230f7478045 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -1,14 +1,12 @@ -mod face_toward; mod geometry; -pub use face_toward::*; pub use geometry::*; pub use glam::*; pub mod prelude { #[doc(hidden)] pub use crate::{ - BVec2, BVec3, BVec4, EulerRot, FaceToward, IVec2, IVec3, IVec4, Mat3, Mat4, Quat, Rect, - Size, UVec2, UVec3, UVec4, Vec2, Vec3, Vec4, + BVec2, BVec3, BVec4, EulerRot, IVec2, IVec3, IVec4, Mat3, Mat4, Quat, Rect, Size, UVec2, + UVec3, UVec4, Vec2, Vec3, Vec4, }; }