diff --git a/src/plugins/spatial_query/mod.rs b/src/plugins/spatial_query/mod.rs index a0c8db79..c70f5ef3 100644 --- a/src/plugins/spatial_query/mod.rs +++ b/src/plugins/spatial_query/mod.rs @@ -42,7 +42,7 @@ //! # #[cfg(all(feature = "3d", feature = "f32"))] //! fn setup(mut commands: Commands) { //! // Spawn a ray caster at the center with the rays travelling right -//! commands.spawn(RayCaster::new(Vec3::ZERO, Vec3::X)); +//! commands.spawn(RayCaster::new(Vec3::ZERO, Direction3d::X)); //! // ...spawn colliders and other things //! } //! @@ -53,7 +53,7 @@ //! println!( //! "Hit entity {:?} at {} with normal {}", //! hit.entity, -//! ray.origin + ray.direction * hit.time_of_impact, +//! ray.origin + *ray.direction * hit.time_of_impact, //! hit.normal, //! ); //! } @@ -101,7 +101,7 @@ //! Collider::sphere(0.5), // Shape //! Vec3::ZERO, // Origin //! Quat::default(), // Shape rotation -//! Vec3::X // Direction +//! Direction3d::X // Direction //! )); //! // ...spawn colliders and other things //! } @@ -278,16 +278,14 @@ fn update_ray_caster_positions( let global_rotation = rotation.copied().or(transform.map(Rotation::from)); if let Some(global_position) = global_position { - ray.set_global_origin( - global_position.0 + rotation.map_or(origin, |rot| rot.rotate(origin)), - ); + ray.set_global_origin(global_position.0 + rotation.map_or(origin, |rot| rot * origin)); } else if parent.is_none() { ray.set_global_origin(origin); } if let Some(global_rotation) = global_rotation { - let global_direction = global_rotation.rotate(*ray.direction); - ray.set_global_direction(Dir::new_unchecked(global_direction)); + let global_direction = global_rotation * ray.direction; + ray.set_global_direction(global_direction); } else if parent.is_none() { ray.set_global_direction(direction); } @@ -306,13 +304,13 @@ fn update_ray_caster_positions( if global_position.is_none() { if let Some(position) = parent_position { let rotation = global_rotation.unwrap_or(parent_rotation.unwrap_or_default()); - ray.set_global_origin(position.0 + rotation.rotate(origin)); + ray.set_global_origin(position.0 + rotation * origin); } } if global_rotation.is_none() { if let Some(rotation) = parent_rotation { - let global_direction = rotation.rotate(*ray.direction); - ray.set_global_direction(Dir::new_unchecked(global_direction)); + let global_direction = rotation * ray.direction; + ray.set_global_direction(global_direction); } } } @@ -350,16 +348,15 @@ fn update_shape_caster_positions( let global_rotation = rotation.copied().or(transform.map(Rotation::from)); if let Some(global_position) = global_position { - shape_caster.set_global_origin( - global_position.0 + rotation.map_or(origin, |rot| rot.rotate(origin)), - ); + shape_caster + .set_global_origin(global_position.0 + rotation.map_or(origin, |rot| rot * origin)); } else if parent.is_none() { shape_caster.set_global_origin(origin); } if let Some(global_rotation) = global_rotation { - let global_direction = global_rotation.rotate(*shape_caster.direction); - shape_caster.set_global_direction(Dir::new_unchecked(global_direction)); + let global_direction = global_rotation * shape_caster.direction; + shape_caster.set_global_direction(global_direction); #[cfg(feature = "2d")] { shape_caster @@ -395,13 +392,13 @@ fn update_shape_caster_positions( if global_position.is_none() { if let Some(position) = parent_position { let rotation = global_rotation.unwrap_or(parent_rotation.unwrap_or_default()); - shape_caster.set_global_origin(position.0 + rotation.rotate(origin)); + shape_caster.set_global_origin(position.0 + rotation * origin); } } if global_rotation.is_none() { if let Some(rotation) = parent_rotation { - let global_direction = rotation.rotate(*shape_caster.direction); - shape_caster.set_global_direction(Dir::new_unchecked(global_direction)); + let global_direction = rotation * shape_caster.direction; + shape_caster.set_global_direction(global_direction); #[cfg(feature = "2d")] { shape_caster diff --git a/src/plugins/spatial_query/ray_caster.rs b/src/plugins/spatial_query/ray_caster.rs index b362d3ab..c2248261 100644 --- a/src/plugins/spatial_query/ray_caster.rs +++ b/src/plugins/spatial_query/ray_caster.rs @@ -45,7 +45,7 @@ use parry::query::{ /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn setup(mut commands: Commands) { /// // Spawn a ray at the center going right -/// commands.spawn(RayCaster::new(Vec3::ZERO, Vec3::X)); +/// commands.spawn(RayCaster::new(Vec3::ZERO, Direction3d::X)); /// // ...spawn colliders and other things /// } /// @@ -56,7 +56,7 @@ use parry::query::{ /// println!( /// "Hit entity {:?} at {} with normal {}", /// hit.entity, -/// ray.origin + ray.direction * hit.time_of_impact, +/// ray.origin + *ray.direction * hit.time_of_impact, /// hit.normal, /// ); /// } diff --git a/src/plugins/spatial_query/shape_caster.rs b/src/plugins/spatial_query/shape_caster.rs index cc70a591..6938adcb 100644 --- a/src/plugins/spatial_query/shape_caster.rs +++ b/src/plugins/spatial_query/shape_caster.rs @@ -38,7 +38,7 @@ use parry::query::details::TOICompositeShapeShapeBestFirstVisitor; #[cfg_attr(feature = "3d", doc = " Collider::sphere(0.5),")] /// Vec3::ZERO, /// Quat::default(), -/// Vec3::X +/// Direction3d::X, /// )); /// } /// diff --git a/src/plugins/spatial_query/system_param.rs b/src/plugins/spatial_query/system_param.rs index c708ceb0..179a467b 100644 --- a/src/plugins/spatial_query/system_param.rs +++ b/src/plugins/spatial_query/system_param.rs @@ -35,7 +35,7 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// // Cast ray and print first hit /// if let Some(first_hit) = spatial_query.cast_ray( /// Vec3::ZERO, // Origin -/// Vec3::X, // Direction +/// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// true, // Does the ray treat colliders as "solid" /// SpatialQueryFilter::default(), // Query filter @@ -46,7 +46,7 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// // Cast ray and get up to 20 hits /// let hits = spatial_query.ray_hits( /// Vec3::ZERO, // Origin -/// Vec3::X, // Direction +/// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// 20, // Maximum number of hits /// true, // Does the ray treat colliders as "solid" @@ -112,7 +112,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// // Cast ray and print first hit /// if let Some(first_hit) = spatial_query.cast_ray( /// Vec3::ZERO, // Origin - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// true, // Does the ray treat colliders as "solid" /// SpatialQueryFilter::default(), // Query filter @@ -161,7 +161,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// // Cast ray and print first hit /// if let Some(first_hit) = spatial_query.cast_ray( /// Vec3::ZERO, // Origin - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// true, // Does the ray treat colliders as "solid" /// SpatialQueryFilter::default(), // Query filter @@ -224,7 +224,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// // Cast ray and get hits /// let hits = spatial_query.ray_hits( /// Vec3::ZERO, // Origin - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// 20, // Maximum number of hits /// true, // Does the ray treat colliders as "solid" @@ -287,7 +287,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// // Cast ray and get all hits /// spatial_query.ray_hits_callback( /// Vec3::ZERO, // Origin - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// true, // Does the ray treat colliders as "solid" /// SpatialQueryFilter::default(), // Query filter @@ -355,7 +355,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// &Collider::sphere(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// true, // Should initial penetration at the origin be ignored /// SpatialQueryFilter::default(), // Query filter @@ -419,7 +419,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// &Collider::sphere(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// 20, // Max hits /// true, // Should initial penetration at the origin be ignored @@ -491,7 +491,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// &Collider::sphere(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation - /// Vec3::X, // Direction + /// Direction3d::X, // Direction /// 100.0, // Maximum time of impact (travel distance) /// true, // Should initial penetration at the origin be ignored /// SpatialQueryFilter::default(), // Query filter