Skip to content

Commit 94c284d

Browse files
ShaturJondolf
andauthored
Add RayCaster::get(_global)_point (#971)
# Objective Fixes #968. ## Solution Add the mentioned methods. ## Testing I didn't test it, but the change is trivial. I did similar to what Bevy does: https://docs.rs/bevy_math/0.18.1/src/bevy_math/ray.rs.html#97 --------- Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
1 parent 896c952 commit 94c284d

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/spatial_query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
//! println!(
5959
//! "Hit entity {} at {} with normal {}",
6060
//! hit.entity,
61-
//! ray.origin + *ray.direction * hit.distance,
61+
//! ray.get_global_point(hit.distance),
6262
//! hit.normal,
6363
//! );
6464
//! }

src/spatial_query/ray_caster.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use bevy::{
5757
/// println!(
5858
/// "Hit entity {} at {} with normal {}",
5959
/// hit.entity,
60-
/// ray.origin + *ray.direction * hit.distance,
60+
/// ray.get_global_point(hit.distance),
6161
/// hit.normal,
6262
/// );
6363
/// }
@@ -279,6 +279,18 @@ impl RayCaster {
279279
));
280280
}
281281
}
282+
283+
/// Returns the point at a given distance along the ray.
284+
#[must_use]
285+
pub fn get_point(&self, distance: Scalar) -> Vector {
286+
self.origin + self.direction.adjust_precision() * distance
287+
}
288+
289+
/// Like [`Self::get_point`], but returns the point in global coordinates.
290+
#[must_use]
291+
pub fn get_global_point(&self, distance: Scalar) -> Vector {
292+
self.global_origin + self.global_direction.adjust_precision() * distance
293+
}
282294
}
283295

284296
fn on_add_ray_caster(mut world: DeferredWorld, ctx: HookContext) {

0 commit comments

Comments
 (0)