Skip to main content

Module force_field

Module force_field 

Source
Expand description

Spatial force fields (gravity wells, vortex, wind, explosion). Spatial force-field system for applying continuous forces to rigid bodies.

Force fields generate a force vector as a function of world-space position and simulation time. Multiple fields can be stacked; the ForceFieldSystem accumulates them and applies the result to any body that lies within each field’s optional bounding region.

§Available field kinds

KindDescription
UniformConstant force independent of position
RadialAttractInverse-power attraction toward a point
RadialRepelInverse-power repulsion away from a point
VortexTangential rotation around an axis
WindDirectional wind with optional drag scaling
ExplosionExpanding pressure wave from an origin point
TurbulentDeterministic pseudo-random perturbation

§Example

use oxiphysics::force_field::{ForceFieldKind, ForceFieldSystem};

let mut sys = ForceFieldSystem::new();

// Gravity-like field pulling toward origin
sys.add(ForceFieldKind::RadialAttract {
    center: [0.0, 0.0, 0.0],
    strength: 9.81,
    falloff_exp: 2.0,
});

// Wind pushing in +X
sys.add(ForceFieldKind::Wind {
    direction: [1.0, 0.0, 0.0],
    base_speed: 5.0,
});

let f = sys.force_at([1.0, 1.0, 1.0], 0.0);
assert!(f[0].is_finite()); // wind contribution

Structs§

AabbRegion
Axis-aligned bounding box that restricts a field to a region.
ForceFieldEntry
A single registered force field with its metadata.
ForceFieldSystem
Manages a collection of ForceFieldEntry instances and computes the combined force at any world-space position.

Enums§

ForceFieldKind
Describes the mathematical model of a force field.