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`.
This commit is contained in:
Fpgu 2024-05-07 04:52:05 +08:00 committed by GitHub
parent bb76a2c69c
commit 60a73fa60b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 11 deletions

View file

@ -910,7 +910,7 @@ pub fn prepare_lights(
// we don't use the alpha at all, so no reason to multiply only [0..3]
color: Vec4::from_slice(&light.color.to_f32_array()) * light.illuminance,
// direction is negated to be ready for N.L
dir_to_light: light.transform.back(),
dir_to_light: light.transform.back().into(),
flags: flags.bits(),
shadow_depth_bias: light.shadow_depth_bias,
shadow_normal_bias: light.shadow_normal_bias,

View file

@ -2,7 +2,7 @@ use std::ops::Mul;
use super::Transform;
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_math::{Affine3A, Mat4, Quat, Vec3, Vec3A};
use bevy_math::{Affine3A, Dir3, Mat4, Quat, Vec3, Vec3A};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
/// Describe the position of an entity relative to the reference frame.
@ -42,13 +42,13 @@ macro_rules! impl_local_axis {
($pos_name: ident, $neg_name: ident, $axis: ident) => {
#[doc=std::concat!("Return the local ", std::stringify!($pos_name), " vector (", std::stringify!($axis) ,").")]
#[inline]
pub fn $pos_name(&self) -> Vec3 {
(self.0.matrix3 * Vec3::$axis).normalize()
pub fn $pos_name(&self) -> Dir3 {
Dir3::new_unchecked((self.0.matrix3 * Vec3::$axis).normalize())
}
#[doc=std::concat!("Return the local ", std::stringify!($neg_name), " vector (-", std::stringify!($axis) ,").")]
#[inline]
pub fn $neg_name(&self) -> Vec3 {
pub fn $neg_name(&self) -> Dir3 {
-self.$pos_name()
}
};

View file

@ -37,12 +37,7 @@ fn draw_cursor(
let point = ray.get_point(distance);
// Draw a circle just above the ground plane at that position.
gizmos.circle(
point + ground.up() * 0.01,
Dir3::new_unchecked(ground.up()), // Up vector is already normalized.
0.2,
Color::WHITE,
);
gizmos.circle(point + ground.up() * 0.01, ground.up(), 0.2, Color::WHITE);
}
#[derive(Component)]