Skip to content

Commit

Permalink
return Direction3d from Transform::up and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
rosefromthedead committed Jan 29, 2024
1 parent 9256749 commit 7291423
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_audio/src/sinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ impl SpatialAudioSink {
/// Set the listener position, with an ear on each side separated by `gap`.
pub fn set_listener_position(&self, position: Transform, gap: f32) {
self.set_ears_position(
position.translation + position.left() * gap / 2.0,
position.translation + position.right() * gap / 2.0,
position.translation + *position.left() * gap / 2.0,
position.translation + *position.right() * gap / 2.0,
);
}

Expand Down
28 changes: 16 additions & 12 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::GlobalTransform;
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_math::primitives::Direction3d;
use bevy_math::{Affine3A, Mat3, Mat4, Quat, Vec3};
use bevy_reflect::prelude::*;
use bevy_reflect::Reflect;
Expand Down Expand Up @@ -185,55 +186,58 @@ impl Transform {

/// Get the unit vector in the local `X` direction.
#[inline]
pub fn local_x(&self) -> Vec3 {
self.rotation * Vec3::X
pub fn local_x(&self) -> Direction3d {
// Direction3d::new(x) panics if x is of invalid length, but quat * unit vector is length 1
Direction3d::new(self.rotation * Vec3::X).unwrap()
}

/// Equivalent to [`-local_x()`][Transform::local_x()]
#[inline]
pub fn left(&self) -> Vec3 {
pub fn left(&self) -> Direction3d {
-self.local_x()
}

/// Equivalent to [`local_x()`][Transform::local_x()]
#[inline]
pub fn right(&self) -> Vec3 {
pub fn right(&self) -> Direction3d {
self.local_x()
}

/// Get the unit vector in the local `Y` direction.
#[inline]
pub fn local_y(&self) -> Vec3 {
self.rotation * Vec3::Y
pub fn local_y(&self) -> Direction3d {
// Direction3d::new(x) panics if x is of invalid length, but quat * unit vector is length 1
Direction3d::new(self.rotation * Vec3::Y).unwrap()
}

/// Equivalent to [`local_y()`][Transform::local_y]
#[inline]
pub fn up(&self) -> Vec3 {
pub fn up(&self) -> Direction3d {
self.local_y()
}

/// Equivalent to [`-local_y()`][Transform::local_y]
#[inline]
pub fn down(&self) -> Vec3 {
pub fn down(&self) -> Direction3d {
-self.local_y()
}

/// Get the unit vector in the local `Z` direction.
#[inline]
pub fn local_z(&self) -> Vec3 {
self.rotation * Vec3::Z
pub fn local_z(&self) -> Direction3d {
// Direction3d::new(x) panics if x is of invalid length, but quat * unit vector is length 1
Direction3d::new(self.rotation * Vec3::Z).unwrap()
}

/// Equivalent to [`-local_z()`][Transform::local_z]
#[inline]
pub fn forward(&self) -> Vec3 {
pub fn forward(&self) -> Direction3d {
-self.local_z()
}

/// Equivalent to [`local_z()`][Transform::local_z]
#[inline]
pub fn back(&self) -> Vec3 {
pub fn back(&self) -> Direction3d {
self.local_z()
}

Expand Down

0 comments on commit 7291423

Please sign in to comment.