Skip to content

Commit

Permalink
physics: Add escape_along_ray().
Browse files Browse the repository at this point in the history
This function will serve the purpose that `collide_along_ray()` with
`StopAt::EmptySpace` was intended to serve. So much of the control flow
needs to have opposite logic that it is more confusing than helpful to
combine them.

It is currently unused.
  • Loading branch information
kpreid committed Oct 12, 2023
1 parent f2ebc91 commit 2b9068b
Show file tree
Hide file tree
Showing 2 changed files with 380 additions and 53 deletions.
11 changes: 5 additions & 6 deletions all-is-cubes/src/physics/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ordered_float::NotNan;
use num_traits::float::Float as _;

use super::collision::{
aab_raycast, collide_along_ray, find_colliding_cubes, nudge_on_ray, Contact,
aab_raycast, collide_along_ray, escape_along_ray, find_colliding_cubes, nudge_on_ray, Contact,
};
use crate::block::{BlockCollision, Resolution};
#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -500,15 +500,14 @@ impl Body {
direction: FreeVector,
) -> Option<(FreePoint, NotNan<FreeCoordinate>)> {
if false {
// TODO: This attempted implementation does not work, causing lots of falling into
// blocks. But if we can fix the bugs, it will make push-out actually work with
// recursive blocks. (It's why I added StopAt::EmptySpace.)
// TODO: This attempted reimplementation does not work yet.
// Once `escape_along_ray()` is working properly, we can enable this and make
// push-out actually work with recursive blocks.

let direction = direction.normalize(); // TODO: set this to a max distance
let ray = Ray::new(self.position, direction);

let end =
collide_along_ray(space, ray, self.collision_box, |_| {}, StopAt::EmptySpace)?;
let end = escape_along_ray(space, ray, self.collision_box)?;

let nudged_distance = end.t_distance + POSITION_EPSILON;
Some((
Expand Down
Loading

0 comments on commit 2b9068b

Please sign in to comment.