Module radial

Source
Expand description

Allocation-free radial impulses selected by the existing direct-overlap query.

Selection uses current collider surfaces, including compound child offsets, rather than body-origin distance. Each dynamic body receives at most one linear COM impulse (no torque). Direction is from the request center to the body’s current COM; falloff uses the nearest accepted child surface. Fixed/kinematic bodies are excluded. Sleeping behavior is explicit.

All ordinary failures are checked before changing velocities, wake flags, forces or the accepted-output buffer. Candidate scratch may change on error. A truncated query is rejected, never applied as a first-N blast. An additional numeric preflight rejects geometry the existing f32 query would silently omit. No clocks, detector, damage, feedback, replay state or persistent cache is added.

A physics-lab pulse can replace a manual body loop at an actual fixed tick:

use ferravex_math::{Vec2, Vec3};
use ferravex_physics::{d2::*, radial::*};
let mut world = PhysicsWorld::default();
let ball = world.add_ball([2., 0.], 0.5, true);
let wall = world.add_ball([0., -2.], 0.5, false);
let mut candidates = [None; 8]; // Reuse these caller buffers on later ticks.
let mut accepted = [None; 4];
let request = RadialImpulseRequest {
    center: Vec3::ZERO, radius: 8.,
    model: ImpulseModel::PerBody(11.), falloff: Falloff::LinearSurface,
    zero_distance: ZeroDistance::Axis(Vec3::Y),
    sleeping: SleepingPolicy::Wake, sensors: RadialSensors::Exclude,
    layers: u32::MAX, ignored_body: None, max_bodies: 4, max_colliders: 8,
};
let report = apply_radial_impulse(&mut world, request, &mut candidates,
    &mut accepted).unwrap();
assert_eq!(report.applied, 1);
let effect = accepted[0].unwrap();
assert_eq!(effect.body, ball);
assert!((world.bodies[ball].linvel() - Vec2::X * effect.impulse.x
    / world.bodies[ball].mass()).length() < 1e-4);
assert_eq!(world.bodies[wall].linvel(), Vec2::ZERO);
world.step(1. / 120.); // Real physics progresses; the operation itself runs no tick.
assert!(world.bodies[ball].translation().x > 2.);
// Restart owns world/body restoration; this helper retains no pending blast.
assert!(world.remove_body(ball));
let replacement = world.add_ball([2., 0.], 0.5, true);
let report = apply_radial_impulse(&mut world, request, &mut candidates,
    &mut accepted).unwrap();
assert_eq!(report.applied, 1);
assert_eq!(accepted[0].unwrap().body, replacement);
assert_ne!(replacement, ball);

The same generic adapter accepts the spatial world without a new renderer:

use ferravex_math::Vec3;
use ferravex_physics::{d3::*, radial::*};
let mut world = PhysicsWorld::default();
let body = world.add_ball([0., 0., 2.], 0.5, true);
let request = RadialImpulseRequest {
    center: Vec3::ZERO, radius: 4., model: ImpulseModel::Total(6.),
    falloff: Falloff::Constant, zero_distance: ZeroDistance::Skip,
    sleeping: SleepingPolicy::Skip, sensors: RadialSensors::Exclude,
    layers: u32::MAX, ignored_body: None, max_bodies: 1, max_colliders: 1,
};
let mut candidates = [None; 1];
let mut accepted = [None; 1];
assert_eq!(apply_radial_impulse(&mut world, request, &mut candidates,
    &mut accepted).unwrap().applied, 1);
assert_eq!(accepted[0].unwrap().impulse, Vec3::Z * 6.);
assert!((world.bodies[body].linvel() - Vec3::Z * 6.
    / world.bodies[body].mass()).length() < 1e-4);
world.step(1. / 120.);
assert!(world.bodies[body].translation().z > 2.);

Structs§

RadialImpulse
Exact accepted impulse; zero/underflow impulses and skipped bodies are absent. Output order is ascending generational body handle, independent of child order.
RadialImpulseReport
Counts for one successful invocation; no counters persist between invocations.
RadialImpulseRequest
Explicit blast policy. See the module’s runnable fixed-tick lab recipes. No default model, falloff or zero-distance axis is chosen for the caller.

Enums§

Falloff
Falloff uses signed distance to the nearest child accepted by the query.
ImpulseModel
Scalar impulse policy; magnitudes must be finite and nonnegative.
RadialImpulseError
Atomic rejection: world state and accepted output remain unchanged. Candidate scratch is unspecified after any error.
RadialSensors
Identical sensor membership rules to the dimensional overlap queries.
SleepingPolicy
Only dynamic bodies can be affected; sleeping dynamics follow this policy.
ZeroDistance
Direction when the body’s COM coincides exactly with the request center.

Traits§

RadialWorld
Sealed adapter for the existing d2/d3 PhysicsWorlds. See the module recipes. Generic consumers can accept W: RadialWorld; no caller-provided detector or callback runs between preflight and commit. The shared kernel uses World<B>.

Functions§

apply_radial_impulse
Check the complete blast, then apply existing body COM-impulse methods once per accepted body. See the module for runnable recipes in both dimensions.