Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf committed Feb 18, 2024
1 parent c287f09 commit d9512c0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
35 changes: 16 additions & 19 deletions src/plugins/spatial_query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//! }
//!
Expand All @@ -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,
//! );
//! }
Expand Down Expand Up @@ -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
//! }
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/spatial_query/ray_caster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// }
///
Expand All @@ -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,
/// );
/// }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/spatial_query/shape_caster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/// ));
/// }
///
Expand Down
18 changes: 9 additions & 9 deletions src/plugins/spatial_query/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d9512c0

Please sign in to comment.