Skip to content

Commit 60a73fa

Browse files
author
Fpgu
authored
Use Dir3 for local axis methods in GlobalTransform (#13264)
Switched the return type from `Vec3` to `Dir3` for directional axis methods within the `GlobalTransform` component. ## Migration Guide The `GlobalTransform` component's directional axis methods (e.g., `right()`, `left()`, `up()`, `down()`, `back()`, `forward()`) have been updated from returning `Vec3` to `Dir3`.
1 parent bb76a2c commit 60a73fa

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

crates/bevy_pbr/src/render/light.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ pub fn prepare_lights(
910910
// we don't use the alpha at all, so no reason to multiply only [0..3]
911911
color: Vec4::from_slice(&light.color.to_f32_array()) * light.illuminance,
912912
// direction is negated to be ready for N.L
913-
dir_to_light: light.transform.back(),
913+
dir_to_light: light.transform.back().into(),
914914
flags: flags.bits(),
915915
shadow_depth_bias: light.shadow_depth_bias,
916916
shadow_normal_bias: light.shadow_normal_bias,

crates/bevy_transform/src/components/global_transform.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::Mul;
22

33
use super::Transform;
44
use bevy_ecs::{component::Component, reflect::ReflectComponent};
5-
use bevy_math::{Affine3A, Mat4, Quat, Vec3, Vec3A};
5+
use bevy_math::{Affine3A, Dir3, Mat4, Quat, Vec3, Vec3A};
66
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
77

88
/// Describe the position of an entity relative to the reference frame.
@@ -42,13 +42,13 @@ macro_rules! impl_local_axis {
4242
($pos_name: ident, $neg_name: ident, $axis: ident) => {
4343
#[doc=std::concat!("Return the local ", std::stringify!($pos_name), " vector (", std::stringify!($axis) ,").")]
4444
#[inline]
45-
pub fn $pos_name(&self) -> Vec3 {
46-
(self.0.matrix3 * Vec3::$axis).normalize()
45+
pub fn $pos_name(&self) -> Dir3 {
46+
Dir3::new_unchecked((self.0.matrix3 * Vec3::$axis).normalize())
4747
}
4848

4949
#[doc=std::concat!("Return the local ", std::stringify!($neg_name), " vector (-", std::stringify!($axis) ,").")]
5050
#[inline]
51-
pub fn $neg_name(&self) -> Vec3 {
51+
pub fn $neg_name(&self) -> Dir3 {
5252
-self.$pos_name()
5353
}
5454
};

examples/3d/3d_viewport_to_world.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ fn draw_cursor(
3737
let point = ray.get_point(distance);
3838

3939
// Draw a circle just above the ground plane at that position.
40-
gizmos.circle(
41-
point + ground.up() * 0.01,
42-
Dir3::new_unchecked(ground.up()), // Up vector is already normalized.
43-
0.2,
44-
Color::WHITE,
45-
);
40+
gizmos.circle(point + ground.up() * 0.01, ground.up(), 0.2, Color::WHITE);
4641
}
4742

4843
#[derive(Component)]

0 commit comments

Comments
 (0)