Skip to content

Commit 2915a3b

Browse files
rename GlobalTransform::compute_matrix to to_matrix (#19643)
# Objective - compute_matrix doesn't compute anything, it just puts an Affine3A into a Mat4. the name is inaccurate ## Solution - rename it to conform with to_isometry (which, ironically, does compute a decomposition which is rather expensive) ## Testing - Its a rename. If it compiles, its good to go --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent 2078137 commit 2915a3b

File tree

14 files changed

+33
-30
lines changed

14 files changed

+33
-30
lines changed

crates/bevy_pbr/src/atmosphere/resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ pub(super) fn prepare_atmosphere_transforms(
560560
};
561561

562562
for (entity, view) in &views {
563-
let world_from_view = view.world_from_view.compute_matrix();
563+
let world_from_view = view.world_from_view.to_matrix();
564564
let camera_z = world_from_view.z_axis.truncate();
565565
let camera_y = world_from_view.y_axis.truncate();
566566
let atmo_z = camera_z

crates/bevy_pbr/src/cluster/assign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub(crate) fn assign_objects_to_clusters(
353353

354354
let mut requested_cluster_dimensions = config.dimensions_for_screen_size(screen_size);
355355

356-
let world_from_view = camera_transform.compute_matrix();
356+
let world_from_view = camera_transform.to_matrix();
357357
let view_from_world_scale = camera_transform.compute_transform().scale.recip();
358358
let view_from_world_scale_max = view_from_world_scale.abs().max_element();
359359
let view_from_world = world_from_view.inverse();

crates/bevy_pbr/src/light/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn build_directional_light_cascades(
341341
.iter()
342342
.filter_map(|(entity, transform, projection, camera)| {
343343
if camera.is_active {
344-
Some((entity, projection, transform.compute_matrix()))
344+
Some((entity, projection, transform.to_matrix()))
345345
} else {
346346
None
347347
}
@@ -357,7 +357,7 @@ pub fn build_directional_light_cascades(
357357
// light_to_world has orthogonal upper-left 3x3 and zero translation.
358358
// Even though only the direction (i.e. rotation) of the light matters, we don't constrain
359359
// users to not change any other aspects of the transform - there's no guarantee
360-
// `transform.compute_matrix()` will give us a matrix with our desired properties.
360+
// `transform.to_matrix()` will give us a matrix with our desired properties.
361361
// Instead, we directly create a good matrix from just the rotation.
362362
let world_from_light = Mat4::from_quat(transform.compute_transform().rotation);
363363
let light_to_world_inverse = world_from_light.inverse();

crates/bevy_pbr/src/light_probe/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ where
595595
) -> Option<LightProbeInfo<C>> {
596596
environment_map.id(image_assets).map(|id| LightProbeInfo {
597597
world_from_light: light_probe_transform.affine(),
598-
light_from_world: light_probe_transform.compute_matrix().inverse(),
598+
light_from_world: light_probe_transform.to_matrix().inverse(),
599599
asset_id: id,
600600
intensity: environment_map.intensity(),
601601
affects_lightmapped_mesh_diffuse: environment_map.affects_lightmapped_mesh_diffuse(),

crates/bevy_pbr/src/prepass/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn update_previous_view_data(
216216
query: Query<(Entity, &Camera, &GlobalTransform), Or<(With<Camera3d>, With<ShadowView>)>>,
217217
) {
218218
for (entity, camera, camera_transform) in &query {
219-
let world_from_view = camera_transform.compute_matrix();
219+
let world_from_view = camera_transform.to_matrix();
220220
let view_from_world = world_from_view.inverse();
221221
let view_from_clip = camera.clip_from_view().inverse();
222222

@@ -703,7 +703,7 @@ pub fn prepare_previous_view_uniforms(
703703
let prev_view_data = match maybe_previous_view_uniforms {
704704
Some(previous_view) => previous_view.clone(),
705705
None => {
706-
let world_from_view = camera.world_from_view.compute_matrix();
706+
let world_from_view = camera.world_from_view.to_matrix();
707707
let view_from_world = world_from_view.inverse();
708708
let view_from_clip = camera.clip_from_view.inverse();
709709

crates/bevy_pbr/src/volumetric_fog/render.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub fn prepare_volumetric_fog_uniforms(
700700
// Do this up front to avoid O(n^2) matrix inversion.
701701
local_from_world_matrices.clear();
702702
for (_, _, fog_transform) in fog_volumes.iter() {
703-
local_from_world_matrices.push(fog_transform.compute_matrix().inverse());
703+
local_from_world_matrices.push(fog_transform.to_matrix().inverse());
704704
}
705705

706706
let uniform_count = view_targets.iter().len() * local_from_world_matrices.len();
@@ -712,7 +712,7 @@ pub fn prepare_volumetric_fog_uniforms(
712712
};
713713

714714
for (view_entity, extracted_view, volumetric_fog) in view_targets.iter() {
715-
let world_from_view = extracted_view.world_from_view.compute_matrix();
715+
let world_from_view = extracted_view.world_from_view.to_matrix();
716716

717717
let mut view_fog_volumes = vec![];
718718

crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ mod tests {
317317
#[test]
318318
fn ray_mesh_intersection_simple() {
319319
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
320-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
320+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
321321
let positions = &[V0, V1, V2];
322322
let vertex_normals = None;
323323
let indices: Option<&[u16]> = None;
@@ -338,7 +338,7 @@ mod tests {
338338
#[test]
339339
fn ray_mesh_intersection_indices() {
340340
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
341-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
341+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
342342
let positions = &[V0, V1, V2];
343343
let vertex_normals = None;
344344
let indices: Option<&[u16]> = Some(&[0, 1, 2]);
@@ -359,7 +359,7 @@ mod tests {
359359
#[test]
360360
fn ray_mesh_intersection_indices_vertex_normals() {
361361
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
362-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
362+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
363363
let positions = &[V0, V1, V2];
364364
let vertex_normals: Option<&[[f32; 3]]> =
365365
Some(&[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]);
@@ -381,7 +381,7 @@ mod tests {
381381
#[test]
382382
fn ray_mesh_intersection_vertex_normals() {
383383
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
384-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
384+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
385385
let positions = &[V0, V1, V2];
386386
let vertex_normals: Option<&[[f32; 3]]> =
387387
Some(&[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]);
@@ -403,7 +403,7 @@ mod tests {
403403
#[test]
404404
fn ray_mesh_intersection_missing_vertex_normals() {
405405
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
406-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
406+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
407407
let positions = &[V0, V1, V2];
408408
let vertex_normals: Option<&[[f32; 3]]> = Some(&[]);
409409
let indices: Option<&[u16]> = None;
@@ -424,7 +424,7 @@ mod tests {
424424
#[test]
425425
fn ray_mesh_intersection_indices_missing_vertex_normals() {
426426
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
427-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
427+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
428428
let positions = &[V0, V1, V2];
429429
let vertex_normals: Option<&[[f32; 3]]> = Some(&[]);
430430
let indices: Option<&[u16]> = Some(&[0, 1, 2]);
@@ -445,7 +445,7 @@ mod tests {
445445
#[test]
446446
fn ray_mesh_intersection_not_enough_indices() {
447447
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
448-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
448+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
449449
let positions = &[V0, V1, V2];
450450
let vertex_normals = None;
451451
let indices: Option<&[u16]> = Some(&[0]);
@@ -466,7 +466,7 @@ mod tests {
466466
#[test]
467467
fn ray_mesh_intersection_bad_indices() {
468468
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
469-
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
469+
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
470470
let positions = &[V0, V1, V2];
471471
let vertex_normals = None;
472472
let indices: Option<&[u16]> = Some(&[0, 1, 3]);

crates/bevy_picking/src/mesh_picking/ray_cast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {
233233
if let Some(distance) = ray_aabb_intersection_3d(
234234
ray,
235235
&Aabb3d::new(aabb.center, aabb.half_extents),
236-
&transform.compute_matrix(),
236+
&transform.to_matrix(),
237237
) {
238238
aabb_hits_tx.send((FloatOrd(distance), entity)).ok();
239239
}
@@ -287,7 +287,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {
287287

288288
// Perform the actual ray cast.
289289
let _ray_cast_guard = ray_cast_guard.enter();
290-
let transform = transform.compute_matrix();
290+
let transform = transform.to_matrix();
291291
let intersection = ray_intersection_over_mesh(mesh, &transform, ray, backfaces);
292292

293293
if let Some(intersection) = intersection {

crates/bevy_render/src/camera/camera.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,7 @@ impl Camera {
601601
rect_relative.y = 1.0 - rect_relative.y;
602602

603603
let ndc = rect_relative * 2. - Vec2::ONE;
604-
let ndc_to_world =
605-
camera_transform.compute_matrix() * self.computed.clip_from_view.inverse();
604+
let ndc_to_world = camera_transform.to_matrix() * self.computed.clip_from_view.inverse();
606605
let world_near_plane = ndc_to_world.project_point3(ndc.extend(1.));
607606
// Using EPSILON because an ndc with Z = 0 returns NaNs.
608607
let world_far_plane = ndc_to_world.project_point3(ndc.extend(f32::EPSILON));
@@ -668,7 +667,7 @@ impl Camera {
668667
) -> Option<Vec3> {
669668
// Build a transformation matrix to convert from world space to NDC using camera data
670669
let clip_from_world: Mat4 =
671-
self.computed.clip_from_view * camera_transform.compute_matrix().inverse();
670+
self.computed.clip_from_view * camera_transform.to_matrix().inverse();
672671
let ndc_space_coords: Vec3 = clip_from_world.project_point3(world_position);
673672

674673
(!ndc_space_coords.is_nan()).then_some(ndc_space_coords)
@@ -689,8 +688,7 @@ impl Camera {
689688
/// Will panic if the projection matrix is invalid (has a determinant of 0) and `glam_assert` is enabled.
690689
pub fn ndc_to_world(&self, camera_transform: &GlobalTransform, ndc: Vec3) -> Option<Vec3> {
691690
// Build a transformation matrix to convert from NDC to world space using camera data
692-
let ndc_to_world =
693-
camera_transform.compute_matrix() * self.computed.clip_from_view.inverse();
691+
let ndc_to_world = camera_transform.to_matrix() * self.computed.clip_from_view.inverse();
694692

695693
let world_space_coords = ndc_to_world.project_point3(ndc);
696694

crates/bevy_render/src/camera/projection.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ pub trait CameraProjection {
9393
/// This code is called by [`update_frusta`](crate::view::visibility::update_frusta) system
9494
/// for each camera to update its frustum.
9595
fn compute_frustum(&self, camera_transform: &GlobalTransform) -> Frustum {
96-
let clip_from_world =
97-
self.get_clip_from_view() * camera_transform.compute_matrix().inverse();
96+
let clip_from_world = self.get_clip_from_view() * camera_transform.to_matrix().inverse();
9897
Frustum::from_clip_from_world_custom_far(
9998
&clip_from_world,
10099
&camera_transform.translation(),

0 commit comments

Comments
 (0)